functions not in type classes
18 Jan 2002 12:18:20 +0100
"Cagdas Ozgenc" <firstname.lastname@example.org> writes:
> Why does Haskell let you write functions that are not a part of type class?
> For example instead of
the goal of type class is to allow overloading of function, so for example
id x = x is not subject to overloading => no use to put it in a type class.
> elem :: Eq a => a -> [a] -> Bool
> map :: (a -> b) -> [a] -> [b]
> class Container a where
> elem :: Eq b => b -> a b -> Bool
> map :: (b -> c) -> a b -> a c
> would define methods that can work on all containers, and create a
> discipline to write more reusable and generic functions.
yes, that's right that map and elem could be put in a type class, but that's hard and require
more advanced feature of haskell (here you use constructor class but you need more : multi-parameter class, ....)
> Haskell-Cafe mailing list
Yoann Padioleau, INSA de Rennes, France,
Opinions expressed here are only mine. Je n'écris qu'à titre personnel.
**____ Get Free. Be Smart. Simply use Linux and Free Software. ____**