[Haskell-cafe] Beginners problem with the type system

Bulat Ziganshin bulat.ziganshin at gmail.com
Mon Oct 22 17:14:44 EDT 2007

Hello Henrik,

Monday, October 22, 2007, 10:02:20 PM, you wrote:

> In particular, I want to define two classes 'Channel' and 'Port' (see
> below) that define a common interface for several concrete  
> implementations with different synchronization characteristics.

may be this my code will be useful for you:

class PipeElement e where
  getP :: e a -> IO a
  putP :: e a -> a -> IO ()

instance PipeElement MVar where
  getP = takeMVar
  putP = putMVar

instance PipeElement Chan where
  getP = readChan
  putP = writeChan

data PairFunc a = PairFunc (IO a) (a -> IO ())

instance PipeElement PairFunc where
  getP (PairFunc get_f put_f) = get_f
  putP (PairFunc get_f put_f) = put_f

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list