[Haskell-cafe] Inferred type is not general enough

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


Ivan,

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

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

\begin{code}
{-# -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)  
\end{code}

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

HTH,

Stefan




More information about the Haskell-Cafe mailing list