Matthias
Thanks for the report. GHC only claims to deal with rank-2 types,
but you are giving it a rank-3 type:
foo2 :: ((forall a. a->Integer) -> Bool) -> Char
The error message is a disaster, and I'll improve it, but that will
just make GHC reject both foo2 and the eta-expanded foo2'.
The point is really that GHC can't unify forall-types (that's what the
message is saying, badly); but it happens in foo2' that it doesn't
need to. But as you discovered, the property of "not needing to
unify forall-types" is fragile to minor changes in the code.
Unless someone can think of a nice way to extend the current rank-2
story to higher ranks, I propose only to improve the error message.
Thanks for reporting it -- I always like to make GHC emit comprehensible
messages!
Simon
| -----Original Message-----
| From: Matthias Neubauer [mailto:[EMAIL PROTECTED]]
| Sent: 09 July 2001 19:47
| To: [EMAIL PROTECTED]
| Subject: Strange Type-checking with Rank-2 Polymorphism
|
|
|
| Dear GHC team,
|
| when loading my latest hackery using rank-2 polymorphic
| functions into the latest version of ghci (5.00.2, started
| with option -fglasgow-exts), ghci responds with some funny
| error messages. I boiled down my code to the following:
|
| ------------------------------------
|
| main = print 42
|
| type R2Type = forall a.a -> Integer
|
| -- type-checks just fine
|
| foo1 :: R2Type -> Char
| foo1 f = bar1 f
|
| bar1 :: R2Type -> Char
| bar1 f = 'x'
|
| -- type-checks only after eta-expanding f1
|
| foo2 :: (R2Type -> Bool) -> Char
| foo2 f = bar2 f
|
| foo2' :: (R2Type -> Bool) -> Char
| foo2' f = bar2 (\x -> f x)
|
| bar2 :: (R2Type -> Bool) -> Char
| bar2 f = 'x'
|
| -- i dunno ...
|
| foo3 :: (Bool -> R2Type) -> Char
| foo3 f = bar3 f
|
| bar3 :: (Bool -> R2Type) -> Char
| bar3 f = 'x'
|
| ---------------------------------------
|
| The function *foo1* type-checks just fine. Whereas, the
| function *foo2*---having the rank-2 polymorphic R2Type type
| at the operator position of its argument---results in the
| following error message:
|
| R2Poly.hs:17:
| Couldn't match `R2Type' against `R2Type'
| Expected type: R2Type -> Bool
| Inferred type: R2Type -> Bool
| In the first argument of `bar2', namely `f1'
| in the definition of function `foo2': bar2 f1
|
| Luckily, I managed to avoid the error message by
| eta-expanding *f1* in the definition of *foo2* as shown in
| *foo2'*. Anyhow, applying a couple of eta-expansions to all
| my functions leads to pretty ugly code...
|
| For the sake of completeness, I also tested the function
| *foo3*, which uses the R2Type type in the result position of
| its argument (which fortunately never occurred in real life).
| The result is the same---
|
| R2Poly.hs:28:
| Couldn't match `R2Type' against `R2Type'
| Expected type: Bool -> R2Type
| Inferred type: Bool -> R2Type
| In the first argument of `bar3', namely `f1'
| in the definition of function `foo3': bar3 f1
|
| ---except that my simple kludge won't do it here.
|
| -Matthias
|
| --
| Matthias Neubauer |
| Universit�t Freiburg, Institut f�r Informatik | tel
| +49 761 203 8060
| Georges-K�hler-Allee 79, 79085 Freiburg i. Br., Germany | fax
| +49 761 203 8242
|
|
| _______________________________________________
| Glasgow-haskell-bugs mailing list
| [EMAIL PROTECTED]
| http://www.haskell.org/mailman/listinfo/glasgow-| haskell-bugs
|
_______________________________________________
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs