From: Brian Hurt <bhurt@spnz.org>
To: skaller <skaller@tpg.com.au>
Cc: Martin Berger <martinb@dcs.qmul.ac.uk>, The Trade <caml-list@inria.fr>
Subject: Re: [Caml-list] ocaml and concurrency
Date: Sat, 31 Jan 2004 00:29:25 -0600 (CST) [thread overview]
Message-ID: <Pine.LNX.4.44.0401302354080.5210-100000@localhost.localdomain> (raw)
In-Reply-To: <1075495504.23595.64.camel@localhost.localdomain>
On 31 Jan 2004, skaller wrote:
> On Fri, 2004-01-30 at 17:52, Brian Hurt wrote:
> > On Fri, 30 Jan 2004, Martin Berger wrote:
> >
> > > > Perhaps because you're a type theorist? <g>
> > >
> > > being a type theorist has many disadvantages ...
> > >
> > > > C not only *does* have function types, it has
> > > > first class function values just like ML does.
> > >
> > > well, i'm not so sure about this for two reasons.
> >
> > Technically, he's correct. What C doesn't have is partial function
> > application,
>
> If by that you mean currying .. well, of course C has that.
> If a function returns a function which returns a function
> you can curry exactly like in ML :-)
Yuck. Yes, I suppose you could do that- but I say again, yuck. A simple
function, which in Ocaml would have the type int -> int -> int ->int,
would have the C prototype:
((int (*)(int)) (*)(int)) foo(int);
Something reasonably, but not unheard of, complicated, like say:
('a -> 'b -> 'c) -> 'a array -> 'b array -> 'c array
would be (ignoring the type safety issue):
(((void **) (*)(void **))(*)(void **))foo(void * (*)(void *) (*)(void *));
That's like something out of a submission to the IOCCC. Not that the
uncurried version is that much better:
void ** foo(void * (*)(void *, void *), void **, void **);
>
> > which makes having functional types much less worthwhile-
> > it's impossible for a function type to also contain state.
>
> Almost, but not quite true:
>
> int f(int x) {
> static int y = x;
> y = y + x;
> return x;
> }
>
> clearly does contain state.. the function isn't
> re-entrant though (which means merely not
> thread safe here since it manifestly isn't recursive).
It's not only not re-entrant, it doesn't do what my example does. Here, I
can have only one sum ever. My example allows to me have multiple
different sums simultaneously- and adding to one doesn't add to the
others. The C++ example kicking around that uses objects is more correct.
Which is one way to do it in C- fake objects, and then used the faked
objects to fake partial application.
>
> However it is true in Haskell and any purely
> functional Ocaml code .. they really cannot contain
> any state :-)
No, even then they can contain state, they just can't change it. But it
can be different from one partial application to another.
A purely functional example:
let logb base x = (log x)/.(log base);;
let log10 = logb 10.;;
let log2 = logb 2.;;
let logn = logb (exp 1.);;
Here I have three different functions- but all of them contain functional
state- the base of logarithms I'm working in.
>
> Indeed, one can go further and say that ML functions
> are a lie: if you consider:
>
> let f x =
> let g y = y + x in g
> in
> let g1 = f 1
> and g2 = f 2
>
> then the two g's are distinction functions, they're
> NOT the 'g' defined in f, which in fact is NOT
> a function at all, merely an abstraction (of course
> g1 and g2 are functions .. :)
f has a type int -> int -> int here, so f 1 has the type int -> int.
Looks like a function to me. The question is: what is a function?
--
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
- Gene Spafford
Brian
-------------------
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-01-31 5:26 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
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 [this message]
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=Pine.LNX.4.44.0401302354080.5210-100000@localhost.localdomain \
--to=bhurt@spnz.org \
--cc=caml-list@inria.fr \
--cc=martinb@dcs.qmul.ac.uk \
--cc=skaller@tpg.com.au \
/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