The "type & data" constructor confused me !

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 -- View this message in context: http://haskell.1045720.n5.nabble.com/The-type-data-constructor-confused-me-t... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

On 13 January 2011 13:03, 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)" ?
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 Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com
participants (2)
-
Ivan Lazar Miljenovic
-
z_axis