Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: Teaching bottomline, part 3: what should improve.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: David Teller <David.Teller@e...>
Subject: Re: [Caml-list] Re: Teaching bottomline, part 3: what should improve.
On Thu, 2007-05-24 at 18:30 +0200, Loup Vaillant wrote:
> It sounds like you need some kind of macro which can encapsulate a
> chunk of code into an anonymous function like :
> 
> for_each i : my_list
> begin
>   i*2
> end
> (* map (fun i -> i*2) my_list *)
> 
> and :
> 
> accumulate acc = 0 in i : my_list
> begin
>   acc+i
> end
> (* fold (+) 0 my_list *)
> 
> Problem : works only on lists (or arrays, depending of your choice).
> And a Haskell like syntax for creating lists would help. (something
> like [0..10]). I think camlp4 can handle all that.

Or perhaps

map i traversing my_list
begin
  i*2
end

accumulate acc = 0 with i traversing my_list
begin
 acc+i
end

...

where "traversing my_list" is a value with 'a lazy list, or something
similar. Nothing then prevents from using different styles of
"traversing" to provide left-to-right or right-to-left list traversal,
or array traversal...

Cheers,
 David