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:  Elias Gabriel Amaral da Silva <tolkiendili@g...> 
Subject:  Re: [Camllist] what do I need to know to understand camlp4 
2010/9/23 ben kuin <benkuin@gmail.com>: >> [1] Compared to other programming languages. I know the syntax is > the way it is for precise reasons (currying, closer to mathematical >> notation, ...). > Would you mind to list a few mathematical subjects that help me to > understand OCamls syntax? I suppose one is lambda calculus. Function application is leftassociative in ML. That is, if $ is an operator such as a $ b means "a applied to b", then it is more natural to interpret a $ b $ c as (a $ b) $ c[1]. The apply "operator" is simply not written in OCaml, so we write just a b c, and it means (a b) c. This is due to the fact that a N parameter function is just a singleparameter function that return a new "curried" function that gets N1 parameters  just like lambda calculus. So one could write let f = a b in f c to make this explicit as well. (This gets a bit more complicated with optional parameters) In fact, you want some mathematical background on functional programming aesthetics (and whatnot), http://en.wikipedia.org/wiki/Lambda_calculus may be a good introduction. [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>  Elias Gabriel Amaral da Silva <tolkiendili@gmail.com>