forall a (Ord a => a-> a) -> Int is an illegal type???
Brian Hulley
brianh at metamilk.com
Fri Feb 10 04:58:15 EST 2006
David Menendez wrote:
> Ben Rudiak-Gould writes:
>
>> Also, the rule would not be quite as simple as you make it out to be,
>> since
>>
>> forall a. (forall b. Foo a b => a -> b) -> Int
>>
>> is a legal type, for example.
>
> Is it? GHCi gives me an error if I try typing a function like that.
>
>> {-# OPTIONS -fglasgow-exts #-}
>> class Foo a b
>>
>> f :: forall a. (forall b. Foo a b => a -> b) -> Int
>> f = undefined
>
> No instance for (Foo a b)
> arising from instantiating a type signature at x.hs:5:4-12
> Probable fix: add (Foo a b) to the type signature(s) for `f'
> Expected type: (forall b1. (Foo a b1) => a -> b1) -> Int
> Inferred type: (a -> b) -> Int
> In the definition of `f': f = undefined
>
> I think there would need to be a top-level constraint on |a| to
> guarantee that an instance of |Foo a b| exists, like
>
> forall a. (exists c. Foo a c) =>
> (forall b. Foo a b => a -> b) -> Int
Is "exists" enough to ensure that 'f' is given a dictionary that will work
with all possible choices for 'b'?
I'd have thought it would need:
forall a. (forall c. Foo a c) =>
(forall b. Foo a b=> a->b)->Int
Regards, Brian.
More information about the Glasgow-haskell-users
mailing list