Version française
Home     About     Download     Resources     Contact us    
Browse thread
RE: Language Design
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: qrczak@k...
Subject: Re: Language Design
Fri, 1 Sep 2000 12:57:13 +0100, Dave Berry <dave@kal.com> pisze:

> Given a value in a monad, e.g. IO v, how can I remove v from the Monad?

For Haskell's IO monad, you don't have a function of type IO v -> v.
IO is carried up to main, the "action of the whole program".

Other monads may or may not provide a similar function.

> Surely this would be required to seamlessly integrate stateful and
> functional code?

In a pure language it is not possible to create a function which does
I/O when applied. If an operation may do I/O, it is reflected in its
type and usage. It may be considered a good thing, and is practically
a must in a lazy language.

In some Haskell implementations there is monad called ST (state
transformer) which provides mutable references and arrays, and can
be wrapped in a pure function. Not all stateful code requires IO.

Actually in some implementations there is unsafePerformIO :: IO a -> a
but it's, well, unsafe. It's sometimes very useful for real life
problems.

-- 
 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK