[Haskell-cafe] How to derive instance for type without exported constructor?

Grigory Sarnitskiy sargrigory at ya.ru
Fri Sep 4 07:58:00 EDT 2009

In System.Random StdGen is defined as

data StdGen = StdGen Int32 Int32

but its constructor StdGen is not exported. How to make StdGen to be an instance of Binary? The following won't work:

instance Data.Binary.Binary StdGen where
    put (StdGen aa ab) = do
	    Data.Binary.put aa
	    Data.Binary.put ab
    get = do
    aa <- get
    ab <- get
    return (StdGen aa ab)

More information about the Haskell-Cafe mailing list