From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@lri.fr>
To: Chris Hecker <checker@d6.com>
Cc: caml-list@inria.fr
Subject: Re: practical functional programming
Date: Mon, 6 Nov 2000 14:16:06 +0100 (MET) [thread overview]
Message-ID: <14854.44822.43851.623717@pc803> (raw)
In-Reply-To: <4.3.2.7.2.20001103055229.00ab6880@shell16.ba.best.com>
In his message of Fri November 3, 2000, Chris Hecker writes:
> However, after reading Okasaki's papers about functional
> datastructures, I'm not sure I get why someone would go to all that
> trouble. In other words, I can trivially write an O(1) queue using
> imperative languages (or imperative features of a funcional
> lanugage, like caml's queue.ml). Okasaki goes to a _lot_ of trouble
> to implement an O(1) queue in a pure functional way, using all sorts
> of lazy optimizations and scheduling and whatnot. He acheives O(1),
> but the constant is going to be rather large compared to shuffling a
> pointer/ref around in C/caml.
>
> So, what does all this trouble buy you?
The answer to your question is "persistence".
Indeed, there is no need using a purely functional datastructure when
there is an easy imperative solution. And I think that most
programmers on this mailing list are not extremists of purely
functional programming and will agree with me on that point.
But there is sometimes a need for persistence when programming. As
explained in Okasaki's book, persistence is the property of a
structure to remain valid after an operation (e.g. an insertion) have
been performed on it. Purely functional datastructures are persistent.
(The converse is not true: you may have persistent datastructures
which are implemented in a purely functional way.)
Consider for instance the problem of traversing the syntax tree of a
program to do type checking. If the language require the use of a
symbol table, you may choose between a persistent or a non-persistent
implementation. With a non-persistent implementation, you are likely
to add things in your table before going into a deeper subterm and to
remove them when done with the subterm, like this:
| Let (x,e1,e2) ->
let ty1 = typecheck e1 in
add x ty1;
let ty2 = typecheck e2 in
remove x;
ty2
With a persistent datastructure, you only have to carry the current
symbol table along and you never have to undo anything:
| Let (x,e1,e2) ->
let ty1 = typecheck st e1 in
typecheck (add st x ty1) e2
This is a very silly example but there are many real situations where
persistence is needed (I encountered many of them in practice). Then
you look for efficient persistent datastructures and Okasaki's book
provides good practical solutions for some of them and, above all,
generic methods to build others.
Hope this helps,
--
Jean-Christophe FILLIATRE
mailto:Jean-Christophe.Filliatre@lri.fr
http://www.lri.fr/~filliatr
next prev parent reply other threads:[~2000-11-06 22:15 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-11-03 22:44 Chris Hecker
2000-11-04 18:48 ` Chet Murthy
2000-11-05 14:25 ` John Max Skaller
2000-11-06 22:26 ` Michael Hicks
2000-11-06 6:55 ` Francisco Reyes
2000-11-06 13:16 ` Jean-Christophe Filliatre [this message]
2000-11-06 18:15 ` Chris Hecker
2000-11-07 7:54 ` Stephan Houben
2000-11-11 14:32 ` John Max Skaller
2000-11-12 13:17 ` Ken Wakita
2000-11-12 20:09 ` John Max Skaller
2000-11-13 0:19 ` Ken Wakita
2000-11-13 7:45 ` STARYNKEVITCH Basile
2000-11-07 9:06 ` Xavier Leroy
2000-11-07 10:13 ` Chris Hecker
2000-11-09 10:56 ` Stephan Houben
2000-11-09 21:56 ` Chris Hecker
2000-11-07 18:05 ` Thorsten Ohl
2000-11-07 19:19 ` Marcin 'Qrczak' Kowalczyk
2000-11-06 23:10 Hao-yang Wang
2000-11-06 23:24 Hao-yang Wang
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=14854.44822.43851.623717@pc803 \
--to=jean-christophe.filliatre@lri.fr \
--cc=caml-list@inria.fr \
--cc=checker@d6.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