From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA28388; Wed, 18 Aug 2004 09:10:41 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA28347 for ; Wed, 18 Aug 2004 09:10:40 +0200 (MET DST) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i7I7AbmL008478 for ; Wed, 18 Aug 2004 09:10:39 +0200 Received: from [192.168.1.200] (ppp211-206.lns2.syd3.internode.on.net [203.122.211.206]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i7I7AZ4Y051171; Wed, 18 Aug 2004 16:40:35 +0930 (CST) Subject: Re: [Caml-list] Are map and iter guaranteed to be called in forwards order? From: skaller Reply-To: skaller@users.sourceforge.net To: Jon Harrop Cc: caml-list In-Reply-To: <1092805868.29139.1237.camel@pelican.wigram> References: <20040817120053.GA9749@annexia.org> <200408180157.58200.jon@jdh30.plus.com> <1092805868.29139.1237.camel@pelican.wigram> Content-Type: text/plain Message-Id: <1092813033.29139.1273.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 18 Aug 2004 17:10:34 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 412300ED.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 sourceforge:01 2004:99 2004:99 prevost:01 bug:01 bug:01 ocaml's:01 inference:01 ocaml's:01 locating:99 endmatch:01 44,:01 val:01 endl:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, 2004-08-18 at 15:11, skaller wrote: > 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 ;-). > > The actual code above doesn't compile due to a bug, Oops. Its a bug in my translation of the routine, not in Felix! The code below actually works. Clear advantages of Ocaml here are: (a) Ocaml's type inference simplifies presentation (b) :: as both constructor and pattern in Ocaml are nice, as is [x;y;z] list constructor (Felix uses :: like C++ for qualification :( (c) Felix anonymous functions only accept one argument (needs fixing) (d) Felix function parameters aren't general patterns: at best a single top level tuple match is allowed (ugly constraint) However the worst problem isn't shown by the correct code: whilst Ocaml's error messages are sometimes confusing as to reason and location, and Felix is generally better at locating the source of a problem -- Felix sometimes gives very confusing explanations -- it took me an hour to finally convince myself I actually had a type error in my previous code, rather than a compiler bug. The fact that an ordinary programmer can write a compiler for a powerful language in Ocaml really shows just how good Ocaml is :) --------------------------------- include "std"; open List; fun snd(x,y)=>y; fun fst(x,y)=>x; fun index[t] (l:list[t]) = { typedef il_t = int * list [int * t]; fun f(il:il_t) (e: t) => match il with | ?i,?l => i+1, Cons ((i, e),l) endmatch ; return rev (snd ( fold_left f of (il_t) (0, Empty[int * t]) l )) ; } var x = Empty[int]; x = Cons(11,x); x = Cons(22,x); x = Cons(33,x); x = Cons(44,x); x = Cons(55,x); x = Cons(66,x); val z = index x; iter (proc (x:int,y:int) { print x; print " -> "; print y; endl; } ) z ; ------------ [skaller@pelican] ~/links/flx>bin/flx -Ilib --force il 0 -> 66 1 -> 55 2 -> 44 3 -> 33 4 -> 22 5 -> 11 -- 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