[Haskell-beginners] Question about define my own typeclass
ke dou
kd6ck at virginia.edu
Thu Mar 27 15:49:10 UTC 2014
Thanks for your reply.
Yes, I understand that if I specify the 'b' to 'Prelude.Bool', it should
work, but what if I also want use the typeclass Conversion to convert other
types other than MyBool, like MyInt, or MyString?
--Ke
On Thu, Mar 27, 2014 at 11:36 AM, Brandon Allbery <allbery.b at gmail.com>wrote:
> On Thu, Mar 27, 2014 at 11:28 AM, ke dou <kd6ck at virginia.edu> wrote:
>
>> class Conversion a where
>> conversion :: a -> b
>>
>
> b is completely unspecified here, since it's not defined as part of the
> typeclass. The literal meaning of this is that "the caller can request any
> type it pleases, and you have no way of knowing what it is". So the only
> possible result of `conversion` is bottom (e.g. `undefined`).
>
> This is key: it does NOT mean that `conversion` gets to specify the result
> type! You can't do that, except by specifying the type in the type
> signature.
>
> --
> brandon s allbery kf8nh sine nomine
> associates
> allbery.b at gmail.com
> ballbery at sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140327/be9ddd89/attachment-0001.html>
More information about the Beginners
mailing list