Version française
Home     About     Download     Resources     Contact us    
Browse thread
Value shadowing
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Vincent Hanquez <tab@s...>
Subject: Re: [Caml-list] Value shadowing (tangent)
On Wed, Aug 13, 2008 at 03:49:23AM -0700, Brighten Godfrey wrote:
> Going off on a tangent here...
>
> On Aug 13, 2008, at 2:56 AM, David Allsopp wrote:
>>
>> let lst = [5; 4; 3; 2; 1; 0; -1; -2; -3; -4; -5]
>> in
>>   let filter = List.filter (fun x -> x > 0)
>>   in
>>     let double = List.map (fun x -> -2 * x)
>>     in
>>       let sort = List.sort compare
>>       in
>>         (sort $$ double $$ filter) lst
>
> I've seen little of other people's OCaml code, so out of curiosity, do 
> you or others actually write code formatted like the above, as opposed to 
> the more compact and (I think) readable
>
>     let lst = [5; 4; 3; 2; 1; 0; -1; -2; -3; -4; -5] in
>     let filter = List.filter (fun x -> x > 0) in
>     let double = List.map (fun x -> -2 * x) in
>     let sort = List.sort compare in
>     (sort $$ double $$ filter) lst

I write the compact way too, which i found much more readable.
I really dislike the wavy effect, of the former example, it has on code.

however i understand why some people do it the first way. after the "in"
you're in some sort of new scope (previous scope augmented by your
let binds)

-- 
Vincent