[Yhc] coreFunc has extra argument

Tom Hawkins tomahawkins at gmail.com
Tue Mar 4 10:06:39 EST 2008


Thanks Tom and Jeremy, this helps a lot.  Actually, Tom I see you
spelled this out for me a couple weeks ago in an earlier post.  Sorry,
I'm a bit slow.

So am I correct in saying that World is never reference in the
program, it's only used to emulate imperative actions?

-Tom

On 3/4/08, Thomas Shackell <shackell at cs.york.ac.uk> wrote:
> > I believe
> > 'tackling the awkward squad' explains the World parameter.
> >
> > http://research.microsoft.com/~simonpj/papers/marktoberdorf/
>
> Indeed this is the 'World' parameter. It's quite easy to see why it's
> needed. Image the getChar function ...
>
> getChar :: IO Char
>
> if we imagine that the World parameter wasn't present, this would make
> the type of getChar.
>
> getChar :: _E Char
>
> Since _E is just a box this is basically the same as.
>
> getChar :: Char
>
> Since this doesn't take any arguments it's a CAF, i.e. a constant value.
> Since it's constant, every call to getChar would always return the same
> character!
>
> When we add the World parameter we turn getChar into.
>
> getChar :: World -> Char
>
> Now getChar takes an argument, so its value is no longer constant (its
> value can vary depending on the argument). Haskell neither knows, nor
> cares, that getChar doesn't even look at the World argument. As far as
> Haskell is concerned getChar has an argument so Haskell can't treat it
> like a constant.
>
> In other words, it's all some nasty trickery to make impure functions
> work correctly in Haskell ;)
>
> Hope that explains it :)
>
>
> Tom
>
>
>
>


More information about the Yhc mailing list