[Haskell-cafe] Inferred type is not general enough
Ivan Tihonov
kefeer at netangels.ru
Thu Jul 8 02:58:19 EDT 2004
I start some ip networks related work in haskell and wrote two basic
classes Location and Packet. Before writing IpLocation and IpPacket
instances i have written simple TestLocation and TestPacket instances
just to compile this and check for errors in class definitions. But
looks like i misunderstand some haskell principles...
======================================================
class Location a where
point :: a -> String
class Packet a where
source, destination :: Location b => a -> b
size :: Num b => a -> b
------------------------------------------------------
data TestLocation = TestSource | TestDestination
data TestPacket = TestPacket
------------------------------------------------------
instance Location TestLocation where
point a = "location"
instance Packet TestPacket where
source p = TestSource
destination p = TestDestination
size p = 99
$ hugs Test.hs
ERROR Test.hs:20 - Inferred type is not general enough
*** Expression : source
*** Expected type : (Packet TestPacket, Location a) => TestPacket -> a
*** Inferred type : (Packet TestPacket, Location TestLocation) =>
TestPacket -> TestLocation
======================================================
But if i remove source and destination from class and instance
definitions alone "size" compiles well.
How write this in a haskell way?
More information about the Haskell-Cafe
mailing list