Version franaise
Home About Download Resources Contact us
Browse thread
right-associating infix application operator camlp4 extension
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christian Lindig <lindig@c...>
Subject: Re: [Caml-list] right-associating infix application operator camlp4 extension

On Aug 11, 2005, at 5:04 AM, Quc Peyrot wrote:

> Thanks a lot for the answers.
> Strangely I couldn't find $ in this documentation, but
> let ($) f x = f x
> seems to work.

This does not work; you need a right associative operator:

# let ($) f x = f x;;
val ( $ ) : ('a -> 'b) -> 'a -> 'b = <fun>
# (-) 3 $ (/) 4 $ 2 ;;
This expression has type int -> int but is here used with type int

# let (@@) f x = f x;;
val ( @@ ) : ('a -> 'b) -> 'a -> 'b = <fun>
# (-) 3 @@ (/) 4 @@ 2 ;;
- : int = 1

This is the right result for 3-(4/2)=1.

-- Christian