overlapping instances and modules
hello, i am a bit stuck on the following problem, which seems to be GHC related. consider the following two modules:
{-# OPTIONS -fglasgow-exts -fallow-overlapping-instances #-} module Test where
data T m a = T (m a)
class C m where get :: m a
instance C (T m) instance C m => C (t m)
obs :: T [] Int obs = get
module Test1 where
import Test
obs' :: T [] Int obs' = get
i can load the first one (Test) without problems, but when i load the second one (Test1) a get the error: Test1.hs:6: No instance for (C []) arising from use of `get' at Test1.hs:6 In the definition of `obs'': obs' = get this seems to indicate that the second instance is being used, but i cannot figure out why. am i doing something silly here? -iavor ps: i am not on the GHC users list so please cc me if you replay there -- ================================================== | Iavor S. Diatchki, Ph.D. student | | Department of Computer Science and Engineering | | School of OGI at OHSU | | http://www.cse.ogi.edu/~diatchki | ==================================================
Hi All, Anybody knows why the following code does not work?
class Foo n
data Erk n = Foo n => Erk
test.hs:53: All of the type variables in the constraint `Foo n' are already in scope (at least one must be universally quantified here) When checking the existential context of constructor `Erk' In the data type declaration for `Erk' Failed, modules loaded: none. Is there any reason for this error? -W-M- @ @ | \_/
Wang Meng writes: : | > class Foo n | > data Erk n = Foo n => Erk | | test.hs:53: | All of the type variables in the constraint `Foo n' are already in | scope | (at least one must be universally quantified here) : | Is there any reason for this error? I think it implies that the 'Foo n =>' must follow the 'data' keyword, because there is no 'forall n .' to hold it on the right hand side of the '='. That is, data Foo n => Erk n = Erk But beware that you can still construct values of type Erk n, even when n is not in Foo: class Foo n data Foo n => Erk n = Erk test = case Erk :: Erk () of -- () is not an instance of Foo Erk -> "Unrestricted!" See John Hughes's paper "Restricted Datatypes in Haskell" for more. http://www.md.chalmers.se/~rjmh/Papers/restricted-datatypes.ps Regards, Tom
participants (3)
-
Iavor S. Diatchki -
Tom Pledger -
Wang Meng