<div dir="ltr">There is nothing to fix.  It is doing exactly as you intended.  You are confusing types vs values.  Integer is a type, 1, 2, and 3 are values.<br><br>toHaskell takes a type (MyOption a) and converts it to a type (Maybe a).  But in your actual code you will use values ie. toHaskell (Some 'a' :: MyOption Char) and get back a (Just 'a' :: Maybe Char).<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Apr 11, 2014 at 1:13 PM, ke dou <span dir="ltr"><<a href="mailto:kd6ck@virginia.edu" target="_blank">kd6ck@virginia.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Thank you, Bob.<div>I also noticed that, but don't know how to fix it.</div><div>Any suggestions?</div><div class="gmail_extra"><br clear="all"><div><div>--Ke</div></div>
<br><br><div class="gmail_quote"><div><div class="h5">On Fri, Apr 11, 2014 at 1:05 PM, Bob Ippolito <span dir="ltr"><<a href="mailto:bob@redivi.com" target="_blank">bob@redivi.com</a>></span> wrote:<br></div></div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>On Fri, Apr 11, 2014 at 9:50 AM, ke dou <span dir="ltr"><<a href="mailto:kd6ck@virginia.edu" target="_blank">kd6ck@virginia.edu</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Hi,<div><br></div><div>I want to define a typeclass that can convert my own types like MyBool, MyInt, MyOption to according Haskell types -- Bool, Int, Maybe.</div><div><br></div><div>Currently I can convert the first two types, but for MyOption, I don't how to do, since it is a polymophic type.</div>



<div><br></div><div>Here is my toy program:</div><div>--------------------------------------------------------------</div><div>{-# LANGUAGE TypeFamilies #-}<div><br></div><div>module Coercible where</div><div><br></div><div>



import qualified Prelude</div><div><br></div><div>data MyBool = MyTrue | MyFalse</div><div>data MyInt = Zero | One | Two</div><div>data MyOption a =</div><div>   Some a</div><div> | None</div><div><br></div><div>class Coercible a where</div>



<div>  type Return a :: *</div><div>  toHaskell :: a -> (Return a)</div><div><br></div><div>instance Coercible MyBool where</div><div>  type Return MyBool = Prelude.Bool</div><div>  toHaskell MyTrue = Prelude.True</div>



<div>  toHaskell MyFalse = Prelude.False</div><div><br></div><div>instance Coercible MyInt where</div><div>  type Return MyInt = Prelude.Int</div><div>  toHaskell Zero = 0</div><div>  toHaskell One = 1</div><div>  toHaskell Two = 2</div>



<div><br></div><div><div>instance Coercible (MyOption a) where</div><div>  type Return (MyOption a) = Prelude.Maybe a</div><div>  toHaskell (Some a) = Prelude.Just a</div><div>  toHaskell None = Prelude.Nothing</div></div>



<div>--------------------------------------------------------------------------</div><div>The problem occurs when I am trying to use "toHaskell (Some MyBool)", the error message is "Not in scope: data constructor `MyBool'".</div>



<div><div style="font-family:arial,sans-serif;font-size:13px">Any hints will be appreciated !!</div></div></div></div></blockquote><div><br></div></div></div><div>`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.</div>


</div></div></div>
<br></div></div>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>