
Hi, Seems that Haskell allows to specify "dummy" type variables in a declaration of a type synonym, which do not appear in its right-hand side. This can lead to interesting effects, which appears differently in GHC and Hugs. I would like to know, what behavior is correct according to the haskell 98 report. 1) ------------------------------------------ type F a = Int class A a where foo :: A b => a (F b) ------------------------------------------ GHC - OK Hugs - Illegal type "F b" in constructor application 2) ------------------------------------------ type F a = Int class A a where foo :: F a instance A Bool where foo = 1 instance A Char where foo = 2 xs = [foo :: F Bool, foo :: F Char] ------------------------------------------ GHC: M.hs:14:6: Ambiguous type variable `a' in the constraint: `A a' arising from a use of `foo' at M.hs:14:6-8 Probable fix: add a type signature that fixes these type variable(s) M.hs:14:21: Ambiguous type variable `a1' in the constraint: `A a1' arising from a use of `foo' at M.hs:14:21-23 Probable fix: add a type signature that fixes these type variable(s) Hugs: [1,2] Thanks, Vladimir

------------------------------------------ type F a = Int
class A a where foo :: A b => a (F b) ------------------------------------------
GHC - OK Hugs - Illegal type "F b" in constructor application
This time, I'd say Hugs is wrong (though eliminating that initial complaint leads back to an ambiguous and unusable method 'foo'). 4.2.2 Type Synonym Declarations, lists only class instances as exceptions for type synonyms, and 'Int' isn't illegal there.
------------------------------------------ type F a = Int
class A a where foo :: F a
instance A Bool where foo = 1
instance A Char where foo = 2
xs = [foo :: F Bool, foo :: F Char] ------------------------------------------
GHC:
M.hs:14:6: Ambiguous type variable `a' in the constraint: `A a' arising from a use of `foo' at M.hs:14:6-8 Probable fix: add a type signature that fixes these type variable(s)
M.hs:14:21: Ambiguous type variable `a1' in the constraint: `A a1' arising from a use of `foo' at M.hs:14:21-23 Probable fix: add a type signature that fixes these type variable(s)
Hugs: [1,2]
Neither seems correct? 4.3.1 Class Declarations, says: The type of the top-level class method vi is: vi :: forall u,w. (C u, cxi) =>ti The ti must mention u; .. 'foo's type, after synonym expansion, does not mention 'a'. Claus

------------------------------------------ type F a = Int
class A a where foo :: A b => a (F b) ------------------------------------------
GHC - OK Hugs - Illegal type "F b" in constructor application
This time, I'd say Hugs is wrong (though eliminating that initial complaint leads back to an ambiguous and unusable method 'foo').
I only just recognized the horrible error message from the first example.. what Hugs is trying to tell us about is a kind error! The kind of 'a' in 'F' defaults to '*', but in 'A', 'F' is applied to 'b', which, via 'A b' is constrained to '*->*'. So Hugs is quite right (I should have known!-). The error message can be improved drastically, btw: :set +k ERROR file:.\hugs-vs-ghc.hs:19 - Kind error in constructor application *** expression : F b *** constructor : b *** kind : a -> b *** does not match : * See http://cvs.haskell.org/Hugs/pages/hugsman/started.html and search for '+k' - highly recommended if you're investigating kinds. Claus
participants (2)
-
Claus Reinke
-
Vladimir Reshetnikov