functions not in type classes

Yoann Padioleau Yoann.Padioleau@irisa.fr
18 Jan 2002 12:18:20 +0100


"Cagdas Ozgenc" <co19@cornell.edu> writes:

> Greetings.
> 
> 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, ....) 
see http://www.cse.ogi.edu/~mpj/fds.html.


> 
> Thanks
> 
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 

-- 
          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.   ____**