luis-fdz
luis-fdz

Reputation: 181

Changing the precedence of operators defined in a monadic expressions

Since we cannot use infixl nor infixr within a monadic expression, how could we change the precedence and associativity of an operator defined within a monadic expression?

For example, how could we change the precedence of (.=) in:

... = do
  let (.=) = ...
  infixl 5 .=  -- this produces a 'parse error'
  ...

Upvotes: 2

Views: 93

Answers (1)

chi
chi

Reputation: 116139

You can add fixity annotations inside let and where. Whether you are inside a do block or not is irrelevant.

For instance, this compiles and runs fine:

main :: IO ()
main = do
    let (###) :: Int -> Int -> Int
        x ### y = x
        infixl 5 ###
    print (3 ### 7 ### 9)  -- outputs 3
    

Upvotes: 8

Related Questions