Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: Syntax for label
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi VANICAT <remi.vanicat@l...>
Subject: Re: Syntax for label, NEW PROPOSAL
Pierre Weis <Pierre.Weis@inria.fr> writes:

> $ ocamlpedantic
>         Objective Caml version 2.99+10
> 
> # let sum l = List.fold_right ( + ) l 0;;
>                               ^^^^^
> This expression has type int -> int -> int but is here used with type 'a list
> 
> Clearly, there is something wrong now! We may remark that the error
> message is not that clear, but this is a minor point, since error
> messages are never clear enough anyway!
> 
> The real problem is that fixing the code makes no good at all to its
> readability (at least that's what I would say):
> 
> # let sum l = List.fold_right fun:begin fun x acc:y -> x + y end acc:0;;
> val sum : 'a -> int list -> int = <fun>

here, i prefer to use parenthesis as :

let sum l = List.fold_right fun:(fun x acc:y -> x + y) acc:0;;

it's more readable

also i do want the fun: label (you may change the name, but a label
here is useful) to be able to write 

let sum l = List.fold_right acc:0
              fun:(fun long multi line function  definition here)

but i agreed that the acc label (in fun x acc:y -> x + y) is a pain,
because he forbid the use of usual function here 

-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat