Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Are map and iter guaranteed to be called in forwards order?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Are map and iter guaranteed to be called in forwards order?
On Wed, 2004-08-18 at 10:57, Jon Harrop wrote:
> On Tuesday 17 August 2004 15:26, John Prevost wrote:

> let index l =
>   List.rev (snd (List.fold_left (fun (i, l) e -> i+1, (i, e)::l) (0, []) l));;

> Ha! Try writing that in Felix (in another mailing-list, of course ;-).

Unfair to make that challange and deny the right to a response :)
So you get it: its much the same as the Caml version except
the type annotations on the arguments are mandatory in Felix:

fun index[t] (l:list[t]) =>
  rev (snd (
    fold_left
      (fun (i:int, l: list [t], e: int * t) =>
        i+1, Cons ((i, e),l)
      )
      (0, Empty[t]) 
      l
  ))
;

The actual code above doesn't compile due to a bug,
so I'm glad of the example -- thanks! [Looks like
I forgot to alpha convert before unifying during
overload resolution]

However its *should* work: What Caml can do and Felix cannot, 
is pass a *polymorphic* function as an argument. Caml allows
that -- but then you can only use it monomorphically 
[unless you wrap it in a record].

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners