Version française
Home     About     Download     Resources     Contact us    
Browse thread
Option functions (or lack thereof) + operator for composition
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michael Ekstrand <michael@e...>
Subject: Re: [Caml-list] Option functions (or lack thereof) + operator for composition
On 11/16/2010 05:27 AM, Serge Le Huitouze wrote:
> 2. Operator for composition (and its precedence)
> ********************************************************
> To get rid of many warnings, I wrapped some calls (the "connect" calls of
> my widgets) into "ignore (f x y)" statements.
> I've no particular grief in using "ignore", but I find the parentheses
> *really* annoying.
> 
> In Haskell, I would write "ignore $ f x y", which I find much lighter weight.
> 
> I'm not familiar with operators and their precedence, but I wonder: is it
> possible to do something similar with OCaml?

Batteries provides operators for things like this.  It defines the '**>'
operator for function application; it's an odd name, but it has the
right associativity.  As Dmitry mentioned, some override (&).  Batteries
also provides composition operators |- and -|, and a pipeline operator
|> (opposite of **>).  With that operator, you can write:

    f x y |> ignore

thereby putting the emphasis on "f x y" and relegating "ignore" to a
cleanup at the end.

- Michael