[ ghc-Bugs-479616 ] fundep bug across module boundary

noreply@sourceforge.net noreply@sourceforge.net
Thu, 08 Nov 2001 07:22:25 -0800


Bugs item #479616, was opened at 2001-11-08 07:22
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=108032&aid=479616&group_id=8032

Category: Compiler
Group: 5.02
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: fundep bug across module boundary

Initial Comment:
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.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=108032&aid=479616&group_id=8032