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: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] Re: Teaching bottomline, part 3: what should improve.
On Thursday 24 May 2007 17:30:56 Loup Vaillant wrote:
> It sounds like you need some kind of macro which can encapsulate a
> chunk of code into an anonymous function like :

Might be worth going F# compatible here:

> for_each i : my_list
> begin
>   i*2
> end
> (* map (fun i -> i*2) my_list *)

  [for i in my_list -> i*2]

To be honest, this kind of syntactic sugar doesn't wash with me. I just end up 
using functions everywhere.

> Problem : works only on lists (or arrays, depending of your choice).

You can generate arrays and lazy sequences using a slightly different syntax:

  [|for i in my_list -> i*2|]
  {for i in my_list -> i*2}

> And a Haskell like syntax for creating lists would help. (something
> like [0..10]).

Range comprehensions:

  [0 .. 10]

Also, with increments:

  [10 .. -2 .. 0]

And over lazy sequences, hence the factorial example:

  let factorial n = Seq.fold ( * ) 1 {2 .. n}

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The F#.NET Journal
http://www.ffconsultancy.com/products/fsharp_journal/?e