From: skaller <skaller@users.sourceforge.net>
To: Jon Harrop <jon@jdh30.plus.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Are map and iter guaranteed to be called in forwards order?
Date: 18 Aug 2004 17:10:34 +1000 [thread overview]
Message-ID: <1092813033.29139.1273.camel@pelican.wigram> (raw)
In-Reply-To: <1092805868.29139.1237.camel@pelican.wigram>
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
prev parent reply other threads:[~2004-08-18 7:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-17 12:00 Richard Jones
2004-08-17 12:45 ` Damien Doligez
2004-08-17 14:26 ` John Prevost
2004-08-17 14:56 ` Richard Jones
2004-08-17 15:13 ` Anil Madhavapeddy
2004-08-17 15:17 ` Jean-Marie Gaillourdert
2004-08-17 15:19 ` John Prevost
2004-08-18 0:57 ` Jon Harrop
2004-08-18 5:11 ` skaller
2004-08-18 7:10 ` skaller [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1092813033.29139.1273.camel@pelican.wigram \
--to=skaller@users.sourceforge.net \
--cc=caml-list@inria.fr \
--cc=jon@jdh30.plus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox