[Haskell-cafe] Functional Dependencies conflicts

Sebastian Fischer sebf at informatik.uni-kiel.de
Sun Apr 18 09:59:21 EDT 2010


On Apr 18, 2010, at 11:01 AM, Limestraël wrote:

> It's strange I can't declare a generic instance for Binary types...  
> I thought I was trying to do something quite common in Haskell.

A common workaround is to define a newtype like this

     newtype GenericBinary a = GB { fromGB :: a }

and an instance like this

     instance Binary a => Binarizable (GenericBinary a) a where
       toBinary = fromGB

which only needs FlexibleInstances enabled.

You can then 'tag' Binary types for which you want to use the generic  
default instance above with the GB newtype constructor. Whether this  
is less of a pain than implementing a Binarizable instance for each  
Binary type is a different question..

Sebastian

-- 
Underestimating the novelty of the future is a time-honored tradition.
(D.G.)





More information about the Haskell-Cafe mailing list