[Haskell-cafe] The "type & data" constructor confused me !

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Thu Jan 13 04:13:35 CET 2011

On 13 January 2011 13:03, z_axis <z_axis at 163.com> 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
Ivan.Miljenovic at gmail.com

More information about the Haskell-Cafe mailing list