[Haskell-cafe] Re: Monad explanation
DekuDekuplex at Yahoo.com
Thu Feb 5 00:38:10 EST 2009
On Thu, 5 Feb 2009 15:18:09 +1300, "Richard O'Keefe"
<ok at cs.otago.ac.nz> wrote:
>On 5 Feb 2009, at 10:20 am, Gregg Reynolds wrote:
>> That's a fairly common representation, seems to work for lots of
>> people, but it caused me no end of trouble. Values are mathematical
>> objects; how, I asked myself, can they possibly /be/ programs that
>> do IO (or actions, or computations, or <your metaphor here>)? It
>> doesn't make sense, says I,
>without reference to the rest of your message, of course values can /be/
>programs. One of the fundamental insights in programming is that
>(all) programs are values, which, in combination with the observation
>that some programs exist, means that some values are programs.
>Indeed, in the pure lambda calculus, _everything_ is a function (=
Indeed. Perhaps at least part of this confusion is caused by a
difference in style of thinking between the functional and imperative
programming paradigms; in functional programming, functions are
first-class values, so they are treated just like any other values.
Therefore, functional programs are values.
This style of thinking contrasts with that of imperative programming,
where programs are typically considered to be composed of statements
which change global state when executed (see "Functional programming -
HaskellWiki: 1 What is functional programming?" at
>If you don't like it put that way, say that values can be _names for_
>programs, or that values can _be treated as_ programs by interpreters.
>I'd rather not get too far into White Knight territory, though.
Actually, I have a question myself on this issue. I had intended to
give an example of a self-referential program that modifies itself to
illustrate programs as first-class values, but then I just discovered
that it seems that Haskell doesn't support reflection (see
In particular, I just came across the following archived post in
Haskell-Cafe, "Re: [Haskell-cafe] To yi or not to yi, is this really
the question? A plea for a cooperative, ubiquitous, distributed
integrated development system.," dated "Mon, 18 Jun 2007 14:05:53
in which Pasqualino 'Titto' Assini wrote as follows:
>Most languages, even Java, have a reflection capability to dynamically inspect
>an object. It is surprising that Haskell doesn't offer it.
In the same thread, Claus Reinke, in his response, dated "Mon, 18 Jun
2007 15:45:50 -0700" (see
wrote as follows:
>>Most languages, even Java, have a reflection capability to dynamically inspect
>>an object. It is surprising that Haskell doesn't offer it.
>it has to be done with care, or it will invalidate *all* your nice reasoning
>about haskell programs. random example
>reify (f . g) == [| f . g |] =/= [| \x-> f (g x) |] == reify (\x-> f (g x))
I tried looking up "self-reference" on HaskellWiki, but my search did
not result in any hits.
Is it possible to write a self-referential function in Haskell that
modifies itself? My intuition is that this would violate referential
transparency, so it is probably not possible, but as long as the
program is only allowed to reference itself without actually modifying
itself, then there should be a way.
Alternatively, it should be possible for a Haskell program to create a
copy of itself, and then to modify that copy, as long as referential
transparency is not violated.
To what extent are self-reference and reflection supported n Haskell?
-- Benjamin L. Russell
Benjamin L. Russell / DekuDekuplex at Yahoo dot com
Translator/Interpreter / Mobile: +011 81 80-3603-6725
"Furuike ya, kawazu tobikomu mizu no oto."
-- Matsuo Basho^
More information about the Haskell-Cafe