Hi,
I'm playing around with typeclasses and trying to a feel on how you implement "inheritance"
(not sure if that's the good word here) in Haskell. I have the following code that doesn't compile:
class (Show a) => IPHost a where
class (Show a) => IPMask a where
class IPAddr a where
host :: (IPHost b) => a -> b
mask :: (IPMask b) => a -> b
showIPAddr :: (IPAddr a) => a -> String
showIPAddr a = (show . host $ a) ++ "/" ++ (show . mask $ a)
ghci says:
Net/IP.hs:23:23:
Ambiguous type variable `b' in the constraint:
`IPHost b' arising from a use of `host' at Net/IP.hs:23:23-26
Probable fix: add a type signature that fixes these type variable(s)
Net/IP.hs:23:51:
Ambiguous type variable `b1' in the constraint:
`IPMask b1' arising from a use of `mask' at Net/IP.hs:23:51-54
Probable fix: add a type signature that fixes these type variable(s)
What exactly does this error mean in this case? It's no tclear to me what needs to be made more specific. Am I approaching the problem in the wrong way?
Any help is appreciated.
Thanks,
Patrick
--
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada