[Haskell-beginners] special polymorphic default of typeclass depending on other typeclasses?

Sylvain Henry sylvain at haskus.fr
Thu Jun 29 17:34:55 UTC 2017


Constraints aren't considered when instance selection is performed. I.e. 
you can't have both:
instance Foo a where ...
instance Show a => Foo a where ....

But you can use default method signatures: 
https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#default-method-signatures


On 29/06/2017 19:27, Jean Lopes wrote:
> It appear more like Show, you can add a  constraint to the generic 
> instance
>
> instance Show a => Foo a where
>     bar x = show x
>
>
>
>
> Em 29 de jun de 2017 2:16 PM, "Silent Leaf" <silent.leaf0 at gmail.com 
> <mailto:silent.leaf0 at gmail.com>> escreveu:
>
>     hi,
>
>     say i have the following typeclass:
>
>     class Foo a where
>       bar :: a  -> String
>
>     looks a lot like the Read typeclass, right? (at least i think it
>     should?)
>     well say it's a different meaning (in other terms i can't or do
>     not want to use Read, but i'd like to implement a default version
>     of bar for those instances that also implement Read. is there a
>     way to do so?
>
>     _______________________________________________
>     Beginners mailing list
>     Beginners at haskell.org <mailto:Beginners at haskell.org>
>     http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>     <http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170629/29946a4d/attachment.html>


More information about the Beginners mailing list