[Haskell-beginners] Re: Classes in Polymorphic Constructors
Ertugrul Soeylemez
es at ertes.de
Mon Aug 23 11:32:19 EDT 2010
John Smith <voldermort at hotmail.com> wrote:
> Why can polymorphic data constructors not be instantiated as a class?
> (not sure if I used the right terminology there)
>
> For example,
>
> a = [1,True]::[Show]
> b = "foo":a
> c = map show b
>
> This would obviate the need for wrapper types
Your type signature doesn't make sense. You are confusing type classes
with types. Show is a type class.
As far as I see, you will need a wrapper type:
data Object = forall a. Show a => Object { unObject :: a }
a = [Object 1, Object True]
b = Object "foo" : a
c = map (show . unObject) b
I have not tested this code, though. At least I can get the following
list to type-check (using RankNTypes and ImpredicativeTypes extensions):
[1,2,3] :: [forall a. Num a => a]
but I can't use it in any way. And somehow I also can't mix data types
here.
Greets,
Ertugrul
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
More information about the Beginners
mailing list