what do I need to know to understand camlp4
[
Home
]
[ Index:
by date

by threads
]
[ Message by date: previous  next ] [ Message in thread: previous  next ] [ Thread: previous  next ]
[ Message by date: previous  next ] [ Message in thread: previous  next ] [ Thread: previous  next ]
Date:   (:) 
From:  David House <dmhouse@g...> 
Subject:  Re: [Camllist] what do I need to know to understand camlp4 
On 24 September 2010 01:15, Elias Gabriel Amaral da Silva <tolkiendili@gmail.com> wrote: > [1] Pervasives should define it. In fact, even though ** is > rightassociative, it looks like any userdefined operator is > leftassociative by default. So it works like Haskell: > > # let ($) a b = a b;; > val ( $ ) : ('a > 'b) > 'a > 'b = <fun> > # fun x y z > x $ y $ z;; >  : ('a > 'b > 'c) > 'a > 'b > 'c = <fun> > # let q = fun x y z > x $ y $ z;; > val q : ('a > 'b > 'c) > 'a > 'b > 'c = <fun> > # let q' = fun x y z > (x $ y) $ z;; > val q' : ('a > 'b > 'c) > 'a > 'b > 'c = <fun> > # let q'' = fun x y z > x $ (y $ z);; > val q'' : ('a > 'b) > ('c > 'a) > 'c > 'b = <fun> > # let q''' = fun x y z > x $ y z;; > val q''' : ('a > 'b) > ('c > 'a) > 'c > 'b = <fun> Incidentally, ($) in Haskell is rightassociative; however the consensus in the Haskell community (in my experience) is that this is a mistake. If it were leftassociative, you would lose the ability to say f $ g $ x, but this can be written f . g $ x anyway (dot is function composition (a > b) > (b > c) > a > c, and does rightassociate), but many things would require fewer parentheses, e.g. f (g x) (h y) can be written f $ g x $ h y. In fact, the strict function application operator ($!) *is* leftassociative. See http://hackage.haskell.org/trac/haskellprime/wiki/ChangeDollarAssociativity for more information. Also, you say "Pervasives should define it"  the important thing about dollar in Haskell is that it has very low precedence, hence its ability to save parentheses. I didn't think OCaml allowed us to specify the operator precedence of the infix operators we define.