On 25-Jan-2002, Hal Daume III <[EMAIL PROTECTED]> wrote:
> consider the following definition:
> 
> > class C a where foo :: a -> Int
> > instance C Bool where foo _ = 5
> 
> I can then say:
> 
> > bar :: C a => a -> Int
> > bar (x :: a) = foo (undefined :: a)
> 
> But not:
> 
> > bar :: C a => a -> Int
> > bar x = foo (undefined :: a)
> 
> because it tries to use a new scope for the type variable a and doesn't
> unify it with the one in the type spec.  Why not?

I don't know why it isn't the case in Haskell.
In Mercury we do allow type variables in function type declarations
to scope over explicit type qualifications in clause bodies.

One drawback with allowing this is that the type declaration may be
separated from the clause by an arbitrary amount of text,
e.g.
        bar :: C a => a -> Int          -- type var `a' introduced here...
        foo :: Int
        quux :: String

        foo = 42
        quux = "hello world"
        bar x = foo (undefined :: a)    -- ... and used here.

which means that this feature can be used in ways that have the
potential to make programs harder to read.

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.

_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to