Dave Bayer <[EMAIL PROTECTED]> wrote in article <[EMAIL PROTECTED]> in
gmane.comp.lang.haskell.glasgow.user:
> test1 :: Box a -> a -> [a]
> test1 box x = go box x
> where
> go :: Box a -> a -> [a]
> go b y = [(val b), y]
The type signature "go :: Box a -> a -> [a]"
is equivalent to "go :: Box b -> b -> [b]"
or "go :: forall a. Box a -> a -> [a]"
or "go :: forall b. Box b -> b -> [b]"
because the type variable "a" in the type signature for "test1" does not
scope over the type signature for "go". Fortunately, "go" here does
have that type.
> test2 :: Box a -> a -> [a]
> test2 box x = go x
> where
> -- go :: a -> [a]
> go y = [(val box), y]
Here "go" does not have the type "forall a. a -> [a]"; it is not
polymorphic enough.
To write the signature for "go" inside "test2", you need lexically
scoped type variables:
http://www.haskell.org/ghc/docs/latest/html/users_guide/other-type-extensions.html#scoped-type-variables
--
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
2008-11-20 Universal Children's Day http://unicef.org/
1948-12-10 Universal Declaration of Human Rights http://everyhumanhasrights.org
_______________________________________________
Glasgow-haskell-users mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users