no non-typevariable in instance declarations
José Romildo Malaquias
Tue, 14 Nov 2000 13:22:13 -0200
Content-Type: text/plain; charset=iso-8859-1
I found that Hugs differs from GHC 4.08.1 and from NHC98 1.00
in instance declarations where the instance head has only
type variables: Hugs accepts them while the other two rejects.
Attached is a small program that demonstrates it.
Hugs happily runs the program and outputs the list
NHC98 spits the message
In file ./t.hs:
6:23 Found a but expected one of [ ( <conid>
GHC is more verbose in its message:
Illegal instance declaration for `C a'
(There must be at least one non-type-variable in the instance head)
Compilation had errors
Why GHC and NHC98 are more restrictive than Hugs?
This style of instantiation would be very helpful when
dealing with type extensions in Haskell (based on classes
to provide the interface for common operations on
the extendable type).
Prof. José Romildo Malaquias <firstname.lastname@example.org>
Departamento de Computação
Universidade Federal de Ouro Preto
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="t.hs"
module Main where
class C a where
ty :: a -> String
instance (Num a) => C a where
ty _ = "NUM"
instance C Integer where
ty _ = "Integer"
main = print [ty (234::Int), ty (234::Integer), ty (234::Double)]