[Haskell-cafe] Re: Functional version of this OO snippet

Jonathan Cast jonathanccast at fastmail.fm
Fri Dec 5 13:01:53 EST 2008


On Fri, 2008-12-05 at 18:50 +0100, Thomas Davie wrote:
> On 5 Dec 2008, at 17:46, Duncan Coutts wrote:
> 
> > On Fri, 2008-12-05 at 17:06 +0100, Thomas Davie wrote:
> >> On 5 Dec 2008, at 17:00, Duncan Coutts wrote:
> >>
> >>> On Fri, 2008-12-05 at 16:50 +0100, Thomas Davie wrote:
> >>>
> >>>> Sure, and he could then use a fold instead of a map.  Reading files
> >>>> is
> >>>> problematic, but as long as you're only doing it once (the most
> >>>> common
> >>>> situation) is entirely fine wrapped up in an unsafePerformIO.
> >>>
> >>> Nooooo!
> >>>
> >>> Please don't go telling people it's entirely fine to use
> >>> unsafePerformIO
> >>> like that (or at all really).
> >>
> >> Exactly what isn't fine about it?
> >
> > It's the antithesis of pure functional programming. It's so unsafe  
> > that
> > we don't even have a semantics for it.
> Yes, but we also don't have semantics for IO, so it's no real surprise  
> that we have none for something that runs an IO action.

We don't have a (denotational) semantics for Haskell, either.  But, in
principle, one could be produced if desired.  The pure subset is easy;
IO only requires a semantics for the underlying OS and --- in the
presence of the FFI --- the C language.

Unless you add unsafePerformIO or evaluate to the language.  I think
that, if someone was sufficiently motivated to work out the details,
that you could prove that there is *no* denotational semantics for IO
which admits either function without changing the definition of one or
more pure Haskell types.

jcc




More information about the Haskell-Cafe mailing list