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: David Allsopp <dra-news@m...>
Subject: RE: [Caml-list] Value shadowing
> > a useful style and would be greatly irritated by a warning on all  
> > shadowing
> > - but I think that in most cases for me the type of each [x] is  
> > different.
>
> I also find that style useful.  Sometimes the type changes, but I can  
> recall useful cases where the type doesn't change, e.g., a sequence  
> of various operations on a list.  Mock-up:
>
>      let lst = generate_list_somehow () in
>      let lst = List.filter (fun x -> x > 0) in
>      let lst = List.sort compare lst in
>      ...

Although in this case you can use a function composition operator instead -
so

let lst = [5; 4; 3; 2; 1; 0; -1; -2; -3; -4; -5]
in
  let lst = List.filter (fun x -> x > 0) lst
  in
    let lst = List.map (fun x -> -2 * x) lst
    in
      let lst = List.sort compare lst
      in
        lst

becomes [assuming let ($$) f g x = f (g x)]

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




David