[Hat] Qualified variable in pattern: T.mkRoot

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Wed Jun 29 12:20:42 EDT 2005

Thomas Davie <tom.davie at gmail.com> writes:

> > No, 'foo' does not literally gain the value of 'undefined'.  In fact,
> > foo gets no value at all, because the computation diverges before the
> > pattern can be matched.  /Semantically/ divergence is equivalent to
> > 'undefined', but syntactically, 'foo' and 'undefined' are separate
> > bindings, and their types are therefore not constrained to be equal.
> Okay, but does this not force undefined to have the type Maybe a?
> i.e.
> Just x = undefined
> File y = undefined
> would cause a type error?

'undefined :: forall a . a' is a truly polymorphic value, in fact
the only possible value of such an unconstrained type.  In your
example, it is instantiated twice, at different actual types, just
as for instance the polymorphic function 'map' can be instantiated
at several different actual types:
    map toUpper "hello"
    map (+1) [1,2,3]

The only place where instantiating a polymorphic value at different
types might cause a problem is in a recursive definition where the
usage occurrence is at a different type to the defining occurrence, e.g.
    f x = f [x]
Most functional languages do not permit this because it makes type
inference undecidable.  However Haskell allows it, provided that you
give an explicit type signature so full inference is not required.


More information about the Hat mailing list