Browse thread
Option functions (or lack thereof) + operator for composition
[
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: | 2010-11-16 (15:18) |
From: | bluestorm <bluestorm.dylc@g...> |
Subject: | Re: [Caml-list] Option functions (or lack thereof) + operator for composition |
On Tue, Nov 16, 2010 at 3:26 PM, Michael Ekstrand <michael@elehack.net>wrote: > > 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 (<|) as inverse of (|>) is also available. It doesn't have the "right" associativity, but you can easily use (f -| g -| h <| x) instead of (f **> g **> h **> x). Though I find the application-as-pipeline style quite readable in some cases, I think that in general it is more often superfluous than not. Besides, as mentioned recently on this list, overuse of the function composition operators (|-) and (-|) are also call for troubles with the value restriction. All in all, I think it's reasonable to stay conservative and not advertise funky binary operators too loudly. That said, domain-specific binary operators are certainly useful for readability in some contexts --- that's what an infix operator is anyway : an unreadable-by-design symbol that only get meaning by domain-specific conventions. Local open in, available by standard since OCaml 3.12, allow us to neatly encapsulate such domain-specific notations into OCaml modules.