From: Vasile Rotaru <vrotaru@seznam.cz>
To: William Lovas <wlovas@stwing.upenn.edu>, caml-list@inria.fr
Subject: Re: fancy types (was Re: [Caml-list] ocaml killer)
Date: Sun, 1 Feb 2004 03:11:08 +0100 [thread overview]
Message-ID: <20040201031108.4c47b181.vrotaru@seznam.cz> (raw)
In-Reply-To: <20040131033915.GA2151@force.stwing.upenn.edu>
William Lovas <wlovas@stwing.upenn.edu> wrote:
> On Fri, Jan 30, 2004 at 11:36:13AM +0100, Thomas Fischbacher wrote:
> >
> > On Thu, 29 Jan 2004, William Lovas wrote:
> >
> > > # type ('a, 'b) specialist = S of (('a, 'b) specialist -> 'a -> 'b);;
[...]
> >
> > Hm, correct me if I am wrong, but to me this looks as if you had to
> > unnecessarily cons at every recursive call...
>
> Well, it depends on what you mean by "unnecessarily" and what you mean by
> "cons". First, if by "cons" you mean "call a constructor", then yes, i did
> have to cons at every recursive call. However, if by "cons" you mean
> "allocate memory", i can't say for sure by looking at this code -- it says
> nothing about the optimizations applied to variant types during compilation
> or potential opportunities for structure sharing. I strongly suspect that
> memory need not be allocated, though, in which case the answer is no, i did
> not have to allocate memory at every recursive cell.
>
Just look at this:
rv@helios:~$ cat specialist_typed.ml
type ('a, 'b) specialist = S of (('a, 'b) specialist -> 'a -> 'b)
let fac n =
let do_rec (S specialist) n =
if n = 0 then
1
else
n * specialist (S specialist) (n - 1)
in
do_rec (S do_rec) n
rv@helios:~$ ocamlc -dlambda specialist_typed.ml
(setglobal Specialist_typed!
(let
(fac/61
(function n/62
(let
(do_rec/63
(function param/68 n/65
(if (== n/65 0) 1
(let (specialist/64 (field 0 param/68))
(* n/65
(apply specialist/64 (makeblock 0 specialist/64)
(- n/65 1)))))))
(apply do_rec/63 (makeblock 0 do_rec/63) n/62))))
(makeblock 0 fac/61)))
rv@helios:~$ ocamlc -dlambda specialist_untyped.ml
(setglobal Specialist_untyped!
(let
(fac/56
(function n/57
(let
(do_rec/58
(function specialist/59 n/60
(if (== n/60 0) 1
(* n/60
(apply specialist/59 (id specialist/59) (- n/60 1))))))
(apply do_rec/58 do_rec/58 n/57))))
(makeblock 0 fac/56)))
The difference between the two versions are in those two calls
(id specialist/..) ; obviously a nop
and
(makeblock 0 specialist/..) ; ???
Comments about whether (makeblock 0 ..) is a special case which can be
optimized away are welcome.
>
> cheers,
> William
>
Regards,
Vasha
-------------------
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
next prev parent reply other threads:[~2004-02-02 10:47 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-27 6:32 [Caml-list] ocaml killer Alexander Epifanov
2004-01-27 8:56 ` Alex Baretta
2004-01-27 9:43 ` Alexander Epifanov
2004-01-27 18:32 ` Shawn Wagner
2004-01-28 4:38 ` skaller
2004-01-28 5:30 ` james woodyatt
[not found] ` <40168498.6070708@tfb.com>
2004-01-27 19:10 ` Alex Baretta
2004-01-28 13:29 ` David Fox
2004-01-28 15:12 ` Eray Ozkural
2004-01-27 9:41 ` Alexander Danilov
2004-01-27 9:57 ` Alexander Epifanov
2004-01-27 16:43 ` Eric Stokes
2004-01-27 18:19 ` David Fox
2004-01-27 18:47 ` Richard Jones
2004-01-27 19:29 ` Eric Stokes
2004-01-28 13:30 ` Eray Ozkural
2004-01-28 23:26 ` Chet Murthy
2004-01-28 23:47 ` Martin Berger
2004-01-29 0:00 ` Chet Murthy
2004-01-29 0:04 ` Chet Murthy
2004-01-29 0:11 ` Martin Berger
2004-01-29 0:34 ` Chet Murthy
2004-01-29 0:47 ` [Caml-list] ocaml killer' Matt Gushee
2004-01-29 8:52 ` [Caml-list] ocaml killer Thomas Fischbacher
2004-01-29 16:20 ` fancy types (was Re: [Caml-list] ocaml killer) William Lovas
2004-01-29 17:13 ` james woodyatt
2004-01-29 17:26 ` Benedikt Grundmann
2004-01-29 17:17 ` Thomas Fischbacher
2004-01-29 17:41 ` Andreas Rossberg
2004-01-29 19:18 ` William Lovas
2004-01-30 10:36 ` Thomas Fischbacher
2004-01-31 3:39 ` William Lovas
2004-02-01 2:11 ` Vasile Rotaru [this message]
2004-02-02 11:08 ` Florian Hars
2004-01-29 18:33 ` Alex Baretta
2004-01-29 17:53 ` [Caml-list] ocaml killer skaller
2004-01-29 5:20 ` Brian Hurt
2004-01-29 6:36 ` Alexander Epifanov
2004-01-29 8:53 ` [Caml-list] ocaml and concurrency james woodyatt
2004-01-29 9:46 ` Vitaly Lugovsky
2004-01-29 10:37 ` Martin Berger
2004-01-29 11:51 ` Michael Hicks
2004-01-29 12:20 ` Alex Baretta
2004-01-29 12:43 ` Martin Berger
2004-01-29 15:42 ` Vitaly Lugovsky
2004-01-29 16:11 ` Martin Berger
2004-01-29 16:56 ` Andreas Rossberg
2004-01-29 17:19 ` james woodyatt
2004-01-29 17:43 ` Martin Berger
2004-01-29 17:54 ` Andreas Rossberg
2004-01-29 18:08 ` Martin Berger
2004-01-30 0:19 ` Lauri Alanko
2004-01-29 19:37 ` skaller
2004-01-30 0:05 ` Martin Berger
2004-01-30 6:52 ` Brian Hurt
2004-01-30 8:53 ` Issac Trotts
2004-01-30 20:45 ` skaller
2004-01-31 6:29 ` Brian Hurt
2004-01-30 20:12 ` skaller
2004-01-29 18:35 ` skaller
2004-01-29 9:56 ` Alex Baretta
2004-01-29 18:26 ` skaller
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=20040201031108.4c47b181.vrotaru@seznam.cz \
--to=vrotaru@seznam.cz \
--cc=caml-list@inria.fr \
--cc=wlovas@stwing.upenn.edu \
/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;
as well as URLs for NNTP newsgroup(s).