Skip to content

Monomorphic Pattern Bindings and Error Messages

Not clear to me if the following should be a type error or if it should be allowed to unify properly. In either case, the error message is borked.

{-# OPTIONS -fglasgow-exts #-}

module Test where

data Foo x y = Foo {foo1 :: x, foo2 :: y}
instance Functor (Foo x) where
    fmap f (Foo x y) = Foo x (f y)

bar :: a -> Foo (forall s. s) a
bar a = Foo undefined a

main = print (foo2 (fmap (*2) (bar 2)))

{-
sclv.hs:12:20:
    Cannot match a monotype with `forall s. s'
    When matching `forall s. s'
              and `forall s. s'
      Expected type: Foo (forall s1. s1) a
      Inferred type: Foo (forall s1. s1) a
    In the first argument of `foo2', namely `(fmap ((* 2)) (bar 2))'
-}
*Test> :t bar (2 :: Integer) 
bar (2 :: Integer) :: Foo (forall s. s) Integer
*Test> :t foo2 (bar (2 :: Integer))
foo2 (bar (2 :: Integer)) :: Integer
*Test> :t fmap (*2) (bar (2 :: Integer)) 
fmap (*2) (bar (2 :: Integer)) :: Foo (forall s. s) Integer
*Test> :t foo2 (fmap (*2) (bar (2 :: Integer)))

<interactive>:1:6:
    Cannot match a monotype with `forall s. s'
    When matching `forall s. s'
              and `forall s. s'
      Expected type: Foo (forall s1. s1) Integer
      Inferred type: Foo (forall s1. s1) Integer
    In the first argument of `foo2', namely
        `(fmap ((* 2)) (bar (2 :: Integer)))'
Trac metadata
Trac field Value
Version 6.8.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Multiple
Architecture Multiple
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information