[Haskell-cafe] Inferred type is not general enough

Ben Lippmeier Ben.Lippmeier at anu.edu.au
Thu Jul 8 03:31:23 EDT 2004


Ivan,

I don't yet know how to explain this formally, but I know how to fix 
your problem..

You need to add a parameter to the Packet class so the compiler knows 
what type to use for the Location.

.. The following code works for me.. You'll need to use a 
compiler/interpreter which supports multi-parameter type classes.. like 
ghci with the glasgow extensions turned on


-----------------------------------------
class Location a where
        point         :: a -> String

class Packet a loc where
        source       :: Location loc =>  a -> loc
        destination  :: Location loc =>  a -> loc
        size         :: Num b =>         a -> b

------------------------------------------------------
data TestLocation
    = TestSource
    | TestDestination

data TestPacket = TestPacket

------------------------------------------------------
instance Location TestLocation where
        point a     = "location"

instance Packet TestPacket TestLocation
 where
        source p        = TestSource
        destination p   = TestDestination
        size p          = 99





More information about the Haskell-Cafe mailing list