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

Reply via email to