Thank you, Bob.I also noticed that, but don't know how to fix it.Any suggestions?--KeOn Fri, Apr 11, 2014 at 1:05 PM, Bob Ippolito <bob@redivi.com> wrote:_______________________________________________On Fri, Apr 11, 2014 at 9:50 AM, ke dou <kd6ck@virginia.edu> wrote:
Hi,I want to define a typeclass that can convert my own types like MyBool, MyInt, MyOption to according Haskell types -- Bool, Int, Maybe.Currently I can convert the first two types, but for MyOption, I don't how to do, since it is a polymophic type.Here is my toy program:--------------------------------------------------------------{-# LANGUAGE TypeFamilies #-}module Coercible whereimport qualified Preludedata MyBool = MyTrue | MyFalsedata MyInt = Zero | One | Twodata MyOption a =Some a| Noneclass Coercible a wheretype Return a :: *toHaskell :: a -> (Return a)instance Coercible MyBool wheretype Return MyBool = Prelude.BooltoHaskell MyTrue = Prelude.TruetoHaskell MyFalse = Prelude.Falseinstance Coercible MyInt wheretype Return MyInt = Prelude.InttoHaskell Zero = 0toHaskell One = 1toHaskell Two = 2instance Coercible (MyOption a) wheretype Return (MyOption a) = Prelude.Maybe atoHaskell (Some a) = Prelude.Just atoHaskell None = Prelude.Nothing--------------------------------------------------------------------------The problem occurs when I am trying to use "toHaskell (Some MyBool)", the error message is "Not in scope: data constructor `MyBool'".Any hints will be appreciated !!`Some MyBool` isn't valid Haskell. MyBool is the name of a type, there's no binding or constructor with that name. `toHaskell (Some MyTrue)` evaluates to `Just MyTrue` as expected.
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners