简体   繁体   中英

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'
  ...

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
    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM