[Haskell-cafe] Functional Dependencies conflicts

Limestraël limestrael at gmail.com
Mon Apr 19 05:37:45 EDT 2010


It seems like a reasonable and not-too-painful solution, thanks!

Concerning Haskell typesystem, I know it to be beautiful, but also kind of
complex. One of the great Haskell assets is genericity, but this complexity
sometimes encumbers this genericity.
But still, Haskell is -- in terms of flexibility -- way before other
languages which pretend to be generic.


2010/4/18 Sebastian Fischer <sebf at informatik.uni-kiel.de>

>
> 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.)
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100419/8e8b343a/attachment.html


More information about the Haskell-Cafe mailing list