The "type & data" constructor confused me !

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

The "type & data" constructor confused me !

z_axis
data Layout a = forall l. (LayoutClass l a, Read (l a)) => Layout (l a)

readsLayout :: Layout a -> String -> [(Layout a, String)]
readsLayout (Layout l) s = [(Layout (asTypeOf x l), rs) | (x, rs) <- reads s]

Why is the first parameter of readsLayout "(Layout l)" not "Layout (l a)" ?

Sincerely!
e^(π.i) + 1 = 0
Reply | Threaded
Open this post in threaded view
|

Re: The "type & data" constructor confused me !

Ivan Lazar Miljenovic
On 13 January 2011 13:03, z_axis <[hidden email]> wrote:
>
> data Layout a = forall l. (LayoutClass l a, Read (l a)) => Layout (l a)
>
> readsLayout :: Layout a -> String -> [(Layout a, String)]
> readsLayout (Layout l) s = [(Layout (asTypeOf x l), rs) | (x, rs) <- reads
> s]
>
> Why is the first parameter of readsLayout "(Layout l)" not "Layout (l a)" ?

Look at the data definition: if we replace the constraint with some
"L" type of kind * -> *, we have:

data Layout a = Layout (L a)

Note that the type of the value contained within the actual
constructor is the application of L (originally l) to a.  For example,
if L == Maybe, then this could be a value of type "Layout Int" with
the value "Layout (Just 3)".

As such, there is only one actual internal value to pattern match against.

--
Ivan Lazar Miljenovic
[hidden email]
IvanMiljenovic.wordpress.com

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe