[Haskell-beginners] data constructor with IO type

Daneel Yaitskov rtfm.rtfm.rtfm at gmail.com
Tue Feb 24 12:04:33 EST 2009

Hi All,

I'd like to know does it exist a method which allow to construct the TestB
type without a temporary variable such as the TestA constructor.

module Main where

import Monad
import Control.Concurrent
data TestA = TestA (MVar Bool)
xGetA (TestA x) = x
data TestB = TestB { xGetB ::  MVar Bool } 

main =
 do tmp <- newMVar False
   let t = TestB { xGetB  = tmp } in
       do vt <- takeMVar t
          putStrLn ("HELLO" ++ show vt)

main = do
 t <- liftM TestA  (newMVar False)
 vt <- takeMVar (xGetA t)
 putStrLn ("HELLO" ++ show vt)


Daneel Yaitskov

More information about the Beginners mailing list