From: John Prevost <jmp@arsdigita.com>
To: Walid Taha <taha@cs.chalmers.se>
Cc: John Prevost <jmp@arsdigita.com>,
Markus Mottl <mottl@miss.wu-wien.ac.at>,
caml-list@inria.fr
Subject: Re: Imperative programming in Caml
Date: 08 Aug 2000 14:23:39 -0400 [thread overview]
Message-ID: <87ya27vcgk.fsf@localhost.localdomain.> (raw)
In-Reply-To: Walid Taha's message of "Tue, 8 Aug 2000 20:01:53 +0200 (MET DST)"
>>>>> "wt" == Walid Taha <taha@cs.chalmers.se> writes:
wt> This is a great revision, and I particularly like the way that
wt> you broke the task into smaller pieces. The code is certainly
wt> more structured. However, you get the biggest payoff in your
wt> rewrite from using the "option" type, and that is something
wt> that I was trying to avoid (see "option types" below).
{...}
>> imperative call;
>> let x = blah in
>> imperative call
>>
>> is much less disconcerting.
wt> Not quite sure what you mean here.
If you write:
imperative call;
let x = blah in
imperative call
then you get a little distracted by the indentation. It's true that
the expression after a let ... in is part of that let, but since let
contains a single expression, keeping everything at the same
indentation level makes things a little more clear. (That is, makes
it clear that you're doing one thing after another, whether it's the
imperative call or the binding call.)
wt> Some of the choice was intentional. In particular, "option"
wt> types are very appropriate here, and were the first thing that
wt> came to my mind when I was thinking about writing these little
wt> examples. But "option" types do, however, require introducing
wt> the concept of parameteric polymorphism. For my initial
wt> postulate to be answer possitively, avoiding introducing
wt> concepts from function programming would be necessary.
>> The thing that distressed me most was trying to figure out what
>> your ref ref was doing. I understand it now.
wt> I found the need for ref ref that strange too, but as you see,
wt> for that "naive" imperative style, it is necessary.
Mmm. I don't think you're going to have much success at showing that
O'Caml is a reasonable language without using at least some
polymorphism. Perhaps this restatement of my previous code would
help, though:
type optional_int =
| No_Int
| Some_Int of int
module MutableIntList = struct
type mcons = { mutable fore : optional_mcons;
mutable v : int;
mutable back : optional_mcons }
and optional_mcons =
| No_Mcons
| Some_MCons of mcons
type mlist = { mutable head : optional_mcons;
mutable tail : optional_mcons }
...
end
type optional_bool =
| No_Bool
| Some_Bool of bool
type mutable_bool = { mutable v : bool }
...
This does everything that the previous code did, but with no
parametric polymorphism. If polymorphism is difficult to explain, you
might show the example in this form, then point out how the same sort
of datastructure is used over and over again with no change but a
different name and different types inside. Then you could introduce
option and ref types as a generalized solution.
John.
next prev parent reply other threads:[~2000-08-08 20:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-07-25 21:47 overhead of GC in caml runtime? Norman Ramsey
2000-07-28 9:52 ` Xavier Leroy
2000-08-03 19:20 ` Imperative programming in Caml Walid Taha
2000-08-04 19:43 ` Markus Mottl
2000-08-04 19:57 ` Walid Taha
2000-08-06 1:59 ` John Prevost
2000-08-08 18:01 ` Walid Taha
2000-08-08 18:23 ` John Prevost [this message]
2000-08-08 18:30 ` Walid Taha
2000-08-08 21:10 ` Pierre Weis
2000-08-09 13:50 ` Walid Taha
2000-08-04 18:33 Don Syme
2000-08-04 19:48 ` Walid Taha
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=87ya27vcgk.fsf@localhost.localdomain. \
--to=jmp@arsdigita.com \
--cc=caml-list@inria.fr \
--cc=mottl@miss.wu-wien.ac.at \
--cc=taha@cs.chalmers.se \
/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