Skip to content

fundep bug across module boundary

Consider these two files:

BugImport.hs

module BugImport where
import IOExts

class Monad m => RefMonad m r | m -> r where
  newRef :: a -> m (r a)
  readRef :: r a -> m a
  writeRef :: r a -> a -> m ()

instance RefMonad IO IORef where
  newRef = newIORef
  readRef = readIORef
  writeRef = writeIORef

Bug.hs

import IOExts
import BugImport

foo () = do r <- newRef 1
               readRef r

main = do i <- foo ()
              print i

The type of foo is 

(RefMonad m r, Num a) => () -> m a

so the fundep is needed to resolve the overloading. Bug
ghc complains:

Ambiguous type variable(s) 'r' in the constraint
`RefMonad IO r'
arising from use of `foo' at Bug.hs:7
In a do statement: i <- foo ()

i.e. the fundep is lost. This is compiled with
ghc5.02.1, -package 
lang, -fglasgow-exts.

If all the definitions are placed in one module, on the
other hand,
then compilation succeeds. Alternatively, if these two
modules are
loaded into ghci, then they are accepted.
Trac metadata
Trac field Value
Version 5.02
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution ResolvedNoReason
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information