[Haskell-cafe] What's wrong with the classes/insances?
Bulat Ziganshin
bulat.ziganshin at gmail.com
Fri Jun 20 18:22:45 EDT 2008
Hello Pieter,
Saturday, June 21, 2008, 2:04:10 AM, you wrote:
for me, it seems just like you directly translated OOP classes into
Haskell that is the wrong way. you may look into
http://haskell.org/haskellwiki/OOP_vs_type_classes and
ghc user manual which discuss functional dependencies on the example
of collection classes
> HI,
> What 's wrong with this:
> type Id = String
> class Catalog a where
> listItems :: a -> IO [String]
> getItem :: a -> Id -> IO (Maybe String)
> class Item a where
> getCatalog :: Catalog catalog => a -> catalog
data Catalog c =>> Content c = Content {auteur :: String, inhoud::
> String, catalog::c}
> instance Catalog c => Item (Content c) where
> getCatalog (Content _ _ c) = c
> I get this as error from ghci:
> Couldn't match expected type `catalog' against inferred type `c'
> `catalog' is a rigid type variable bound by
> the type signature for `getCatalog'
> at
> ../Sites/liberaleswebsite/www.liberales.be/cgi-bin/Test.hs:16:26
> `c' is a rigid type variable bound by
> the instance declaration
> at
> ../Sites/liberaleswebsite/www.liberales.be/cgi-bin/Test.hs:20:17
> In the expression: c
> In the definition of `getCatalog': getCatalog (Content _ _ c) = c
> In the definition for method `getCatalog'
> Failed, modules loaded: none.
> thanks in advance,
> P
--
Best regards,
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe
mailing list