This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2010-09-24 (07:35) From: David House Subject: Re: [Caml-list] 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
> right-associative, it looks like any user-defined operator is
> left-associative 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 right-associative; however the
consensus in the Haskell community (in my experience) is that this is
a mistake. If it were left-associative, 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
right-associate), 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* left-associative.