
Am Dienstag 15 September 2009 23:13:59 schrieb Cristiano Paris:
On Wed, Sep 2, 2009 at 7:16 AM, zaxis
wrote: Isnot it clear without the 'forall' ? data Branch tok st a = Branch (PermParser tok st (b -> a)) (GenParser tok st b)
thanks!
I elaborated on this and I wish to add my personal way of figuring out what the "forall" keyword means.
When you define:
foo :: a -> a
you are actually defining a _function for every type of a_, which can be read: for every a there exists a function foo which can operate on it (universal quantification).
When you define something like:
foo :: forall a. a -> a
This is exactly the same type as foo :: a -> a (unless you're using ScopedTypeVariables and there's a type variable a in scope), since type signatures are implicitly forall'd.
you are actually defining a _single_ function which must work for every a (that's why we use the "forall" keyword). The difference is subtle but the direct consequences of this are: a) that one function can't use any information about a apart from the fact that it eventually belongs to the type classes specified in the context, b) in the case of [a] (or any other type of higher kind, * -> *, * -> * -> * and so on) you can mix values of different types.
I hope I haven't written anything wrong :)
Cristiano