Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Markus Mottl <markus@oefai.at>
Cc: Andrej Bauer <Andrej.Bauer@andrej.com>, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] environment idiom
Date: 12 Dec 2004 10:56:38 +1100	[thread overview]
Message-ID: <1102809398.2611.637.camel@pelican.wigram> (raw)
In-Reply-To: <20041211181313.GA9656@fichte.ai.univie.ac.at>

On Sun, 2004-12-12 at 05:13, Markus Mottl wrote:

> Another solution would be to use a state monad encapsulating
> the environment.  It has operators for getting and setting states.
> Instead of passing all arguments from function to function "manually",
> you then just need to use the monadic bind operator, which does all that
> implicitly - and even purely functionally + in a statically type safe way!

There's some illusion here. I had an argument with someone that
functional arrays were impossible: array implies O(1) which implies
mutable. Yet Haskell has them, via monads .. and it's all
'purely functional and referentially transparent'.

Took me a while to figure out why this is NOT the case.
Yet obviously, it cannot be. Consider a more extreme
example: using state transformer monads, you can emulate
the action of any C program in Haskell. So it is quite
clear there's no possibility of this being 'purely functional
and referentially transparent' because C programs are not.

The answer is evident in this example because it is so extreme.
Whether code is 'purely functional' etc or not, is a matter of
your viewpoint. Sure, the *Haskell* encoding is purely functional,
but the code *viewed at the monadic level* is not.

I.e. if you implement an interpreter for a non-transparent
non-functional language in a transparent and functional one,
then the interpreter is purely functional, but what it
interprets is not.

So monadic programming with state transformers is NOT
referentially transparent or purely functional at all.
Because you are NOT encoding in Haskell but using
the extension the monad provides.. and THAT code patently
isn't functional.

So actually all these claims about purely functional I/O
and state transformers are wrong: they miss the fundamental
point that when you use them you're no longer coding
in the base language -- the notion of 'code' is relative.

In the 'C interpreter' monad your code has all the
same properties C has -- in particular it isn't transparent
or purely functional. The fact that the interpreter implementation
retains these properties is only relevant to the correctness 
of the interpeter -- not the use of it.

I think there is a theorem here: when you abstract purely
functional code, there is no guarrantee the result is functional.
The bottom line is that given an environment E

	f: A -> B

is not functional if f fiddles with environment E.
It is absurd then to think that

	f: E * A -> E * B

is suddenly purely functional, just because the environment
is now made explicit. This is the inverse theorem:
you can lift any non-functional code to a purely functional
interpretation. Monads just 'drop' the explicit E,
leaving the orginal f which is not functional by specification.
Contradiction: monadic extensions of Haskell do not
magically allow purely functional arrays.

But it is all just fiddling with the 'level' of the code
you're talking about. Fundamentally the notions of purely
functional and referentially transparent are relative things.
Your Haskell is running on a CPU that clearly isn't functional.

A final example. Ocaml *is* purely functional. As long
as you consider references as values -- rather than what
they refer to. In reality, it's just a state transformer
monad like Haskell, only the encoding is built in to
the language.

-- 
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




  reply	other threads:[~2004-12-11 23:57 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-09  2:07 HENRIKSON, JEFFREY
2004-12-09  4:47 ` [Caml-list] " Jacques Garrigue
2004-12-09  6:02   ` Michael Walter
2004-12-09 11:28     ` Jacques Garrigue
2004-12-09 20:02     ` pad
2004-12-09 23:11       ` Jacques Garrigue
2004-12-10  2:30         ` skaller
2004-12-09  9:09 ` Richard Jones
2004-12-09 13:12   ` [Caml-list] " Ville-Pertti Keinonen
2004-12-10 11:59     ` Richard Jones
2004-12-10 10:52 ` [Caml-list] " Andrej Bauer
2004-12-10 12:13   ` Richard Jones
2004-12-10 23:35     ` Jacques Garrigue
2004-12-11  2:30   ` skaller
2004-12-11 14:31     ` Andrej Bauer
2004-12-11 18:13       ` Markus Mottl
2004-12-11 23:56         ` skaller [this message]
2004-12-12  2:36           ` William Lovas
2004-12-12  5:33             ` skaller
2004-12-12 19:09               ` Michael Walter
2004-12-13  0:48                 ` skaller
2004-12-13  2:03                   ` Michael Walter
2004-12-13  2:05                     ` Michael Walter
     [not found]                       ` <877e9a170412121844b633bb8@mail.gmail.com>
2004-12-13  2:45                         ` Michael Walter
2004-12-13  6:18                           ` skaller
2004-12-13  7:08                             ` skaller
2004-12-13  9:56                             ` Michael Walter
2004-12-13 12:59                               ` skaller
2004-12-13  8:56                           ` Thomas Fischbacher
2004-12-13  9:21                             ` Jacques Garrigue
2004-12-13 10:05                               ` Michael Walter
2004-12-13 10:29                                 ` Thomas Fischbacher
2004-12-13 21:16                                   ` Michael Walter
2004-12-13 10:20                               ` Thomas Fischbacher
2004-12-13 12:09                                 ` Jacques Garrigue
2004-12-13 12:48                                   ` Thomas Fischbacher
2004-12-13 14:09                                   ` skaller
2004-12-13 21:39                                     ` Michael Walter
2004-12-13 13:22                                 ` skaller
2004-12-13 16:54                                   ` Marcin 'Qrczak' Kowalczyk
2004-12-13 18:44                                   ` Thomas Fischbacher
2004-12-13 10:11                             ` Michael Walter
2004-12-13 11:46                             ` skaller
2004-12-13  5:41                     ` skaller
2004-12-13  9:29                       ` Michael Walter
2004-12-13 12:30                         ` skaller
2004-12-13 13:49                           ` Martin Berger
2004-12-12 23:03           ` Thomas Fischbacher
2004-12-13  1:26             ` skaller
2004-12-13  8:37               ` Thomas Fischbacher
2004-12-13 10:53                 ` skaller
2004-12-13 11:38                   ` Martin Berger
2004-12-13 13:33                     ` skaller
2004-12-13 12:01                   ` Thomas Fischbacher
2004-12-13 13:41                     ` skaller
2004-12-11 23:29       ` skaller
2004-12-12  0:21         ` Jacques Carette

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=1102809398.2611.637.camel@pelican.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=Andrej.Bauer@andrej.com \
    --cc=caml-list@inria.fr \
    --cc=markus@oefai.at \
    /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