* [Caml-list] operators: compose and Haskell's $ operator
@ 2001-04-26 0:07 Charles Martin
2001-04-26 0:57 ` Brian Rogoff
[not found] ` <Pine.BSF.4.21.0104251746120.15356-100000@shell5.ba.best.co m>
0 siblings, 2 replies; 4+ messages in thread
From: Charles Martin @ 2001-04-26 0:07 UTC (permalink / raw)
To: caml-list
Does someone out there have an out-of-the box solution for adding composition and an equivalent for Haskell's $ operator to OCaml?
I've been using let (<<) f g x = f (g x) for composition, but an equivalent for the $ operator eludes me, as it needs to be right associative and of low precedence. Maybe someone with some Haskell envy has figured something out using camlp4?
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] operators: compose and Haskell's $ operator
2001-04-26 0:07 [Caml-list] operators: compose and Haskell's $ operator Charles Martin
@ 2001-04-26 0:57 ` Brian Rogoff
[not found] ` <Pine.BSF.4.21.0104251746120.15356-100000@shell5.ba.best.co m>
1 sibling, 0 replies; 4+ messages in thread
From: Brian Rogoff @ 2001-04-26 0:57 UTC (permalink / raw)
To: Charles Martin; +Cc: caml-list
On Wed, 25 Apr 2001, Charles Martin wrote:
> Does someone out there have an out-of-the box solution for adding
> composition and an equivalent for Haskell's $ operator to OCaml?
>
> I've been using let (<<) f g x = f (g x) for composition, but an
You should be warned that that doesn't mix nicely with CamlP4's quotation
syntax.
>equivalent for the $ operator eludes me, as it needs to be right
>associative and of low precedence.
Maybe <->? Let's test it
# let ( <-> ) f x = f x;;
val ( <-> ) : ('a -> 'b) -> 'a -> 'b = <fun>
# (fun x -> x + 1) <-> (5 / 2) + 3;;
- : int = 6
# (fun x -> x + 1) <-> (5 / 2) * 3;;
- : int = 7
> Maybe someone with some Haskell envy has figured something out using
> camlp4?
I admit I have a little Haskell envy (type classes and the `infix` syntax :),
but I can probably live with some parentheses ...
-- Brian
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] operators: compose and Haskell's $ operator
[not found] ` <Pine.BSF.4.21.0104251746120.15356-100000@shell5.ba.best.co m>
@ 2001-04-26 1:22 ` Charles Martin
2001-04-26 2:11 ` Brian Rogoff
0 siblings, 1 reply; 4+ messages in thread
From: Charles Martin @ 2001-04-26 1:22 UTC (permalink / raw)
To: caml-list
At 05:57 PM 4/25/01 -0700, you wrote:
>On Wed, 25 Apr 2001, Charles Martin wrote:
>>equivalent for the $ operator eludes me, as it needs to be right
>>associative and of low precedence.
>
># let ( <-> ) f x = f x;;
>val ( <-> ) : ('a -> 'b) -> 'a -> 'b = <fun>
Unfortunately, this is left-associative:
# (+) 3 <-> ( * ) 2 <-> 4;;
Characters 0-5:
This expression has type int -> int but is here used with type
(int -> int) -> 'a
...and higher in precedence than logical operators:
# not <-> true && false;;
- : bool = false
The expression table (http://caml.inria.fr/ocaml/htmlman/manual014.html) does not have an ellipsis after the "<-" entry, so I assume that "<->" gets lumped into the "other infix symbols" category, which is left associative (and higher precedence than the logical operators).
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] operators: compose and Haskell's $ operator
2001-04-26 1:22 ` Charles Martin
@ 2001-04-26 2:11 ` Brian Rogoff
0 siblings, 0 replies; 4+ messages in thread
From: Brian Rogoff @ 2001-04-26 2:11 UTC (permalink / raw)
To: Charles Martin; +Cc: caml-list
On Wed, 25 Apr 2001, Charles Martin wrote:
> At 05:57 PM 4/25/01 -0700, you wrote:
> >On Wed, 25 Apr 2001, Charles Martin wrote:
> >>equivalent for the $ operator eludes me, as it needs to be right
> >>associative and of low precedence.
> >
> ># let ( <-> ) f x = f x;;
> >val ( <-> ) : ('a -> 'b) -> 'a -> 'b = <fun>
>
> Unfortunately, this is left-associative:
Oops, you're right of course. Given that there seems to be no solution, I
guess a little extra parenthesization is your only "pure OCaml option" option.
I've only seen the $ used heavily in code that uses the do notation, where
OCaml might use (gasp!) imperative code with ;, so I've never been tempted
to write a syntax extension for this.
-- Brian
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2001-04-26 2:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-26 0:07 [Caml-list] operators: compose and Haskell's $ operator Charles Martin
2001-04-26 0:57 ` Brian Rogoff
[not found] ` <Pine.BSF.4.21.0104251746120.15356-100000@shell5.ba.best.co m>
2001-04-26 1:22 ` Charles Martin
2001-04-26 2:11 ` Brian Rogoff
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox