Haskell Precedence: Lambda and operator

前端 未结 2 1490
后悔当初
后悔当初 2021-02-05 08:53

I found precedence and associativity is a big obstacle for me to understand what the grammar is trying to express at first glance to haskell code.

For example,



        
2条回答
  •  离开以前
    2021-02-05 09:23

    A good rule of thumb seems to be that you can never make a custom operator that has precedence over built in syntactic constructs. For instance consider this example:

    if b then f *** x else f *** y
    

    Regardless of the associativity of ***, no one would expect it to binds as:

    (if b then f *** x else f) *** y
    

    There aren't a lot of syntactic constructs in Haskell (do and case are a little special because of layout syntax) but let can be used as another example:

    (let x = y in y *** x) /= ((let x = y in y) *** x) 
    

提交回复
热议问题