Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] failwith, raise and type inference
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] failwith, raise and type inference
From: Ker Lutyn <ker527mail@yahoo.com>
> I wonder if we could have Haskell's $ operator added to OCaml. It would make
> this idiom and a lot of my code nicer.
> 
>     failwith $ "foo" ^ "bar"
> 
> Defining it myself as
> 
>     let ($) f x = f x
> 
> doesn't work because of precedence and associativity. The caml sources
> frequently define
> 
>     let (++) x f = f x
> 
> which is a similar idea - but lots of times Haskell's $ is what you want.

This doesn't look very much related to the original thread.
But you just have to find an operator with the right associativity.

    let (@<) f x = f x ;;
    print_string @< String.capitalize  @< "foo" ^ "bar" ;;

Since the first character decides the associativity, you might also
choose @@, @>, or anything you like. ^^, ^@, ... would have the same
associativity and precedence also.
Look at section 6.7 of the manual for infix operators and their
precedences.

Jacques Garrigue

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners