[Haskell-beginners] Question about define my own typeclass

ke dou kd6ck at virginia.edu
Thu Mar 27 15:28:01 UTC 2014


Hi,

Sorry for the spam.

I am new to Haskell.
I want to define my own typeclass which can convert from my own types like
MyBool, MyInt, and MyString to according Haskell types.

Here is my code:

    module Conversion where

    import qualified Prelude

    class Conversion a where
        conversion :: a  -> b

    data MyBool = MyTrue | MyFalse

    instance Conversion MyBool where
        conversion MyTrue = Prelude.True
        conversion MyFalse =Prelude.False

Here is the error message:

 Couldn't match expected type `b' with actual type `Prelude.Bool'
      `b' is a rigid type variable bound by
          the type signature for conversion :: MyBool -> b
          at Conversion.hs:11:5

Does anyone know what's wrong with my code, and how to fix it?
Any hints will be appreciated !!

Best,
--Ke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140327/f521be52/attachment.html>


More information about the Beginners mailing list