[Haskell-cafe] Inferred type is not general enough

Stefan Holdermans sholderm at students.cs.uu.nl
Thu Jul 8 04:46:30 EDT 2004


  IT> Stefan Holdermans wrote:
  IT> Huh. I'm really get stuck. Can someone write me working 
  IT> implementation of my crap?

Huh? Did *I* wrote that ... ? ;)

{-# -OPTIONS -fglasgow-exts #-}

class Location a where
  point :: a -> String
class (Location b) => Packet a b where
  source      :: a -> b
  destination :: a -> b
  size        :: forall c . (Num c) => a -> c
data TestLocation = TestSource | TestDestination
                  deriving (Show)

instance Location TestLocation where
  point = show
data TestPacket = TestPacket

instance Packet TestPacket TestLocation where
  source      = const TestSource
  destination = const TestDestination
  size        = const 99
main :: IO ()
main =  print $ (source TestPacket :: TestLocation)  

As I mentioned, depending on your needs, there are other options: enriching
the Location class, parameterizing the packet types, ...



More information about the Haskell-Cafe mailing list