<div dir="ltr">Hello haskellers,<br><br>Anyone know the trick for making a Binary instance of a GADT.<br>See sample code below followed by the type error reported by ghc version 6.8.3<br><br>Thanks,<br>
Tony<br><br>----<br>{-# LANGUAGE GADTs #-}<br><br>module GADTTest where<br><br>import Data.Binary<br>import Control.Monad (liftM)<br><br>data Query a where<br> Lookup :: String -> Query (Maybe Int)<br> Fetch :: [String] -> Query [Int]<br>
<br>instance (Binary a) => Binary (Query a) where<br> put (Lookup x) = putWord8 0 >> put x<br> put (Fetch x) = putWord8 1 >> put x<br> get = getWord8 >>= \tag -> case tag of<br> 0 -> liftM Lookup get<br>
1 -> liftM Fetch get<br>-----<br><br>GADTTest.hs:12:0:<br> Couldn't match expected type `Maybe Int'<br> against inferred type `[Int]'<br> When trying to generalise the type inferred for `get'<br>
Signature type: forall a. (Binary a) => Get (Query a)<br> Type to generalise: Get (Query a)<br> In the instance declaration for `Binary (Query a)'<br></div>