functions not in type classes

Cagdas Ozgenc co19@cornell.edu
Fri, 18 Jan 2002 13:06:12 +0200


>
> Well, what classes should such functions as const, id and (.) be members
> of?
>
> const :: a -> b -> a;
> const x y = x;
>
> id :: a -> a;
> id x = x;
>
> (.) :: (b -> c) -> (a -> b) -> (a -> c);
> (.) f g x = f (g x);

Well can you give examples of some useful functions? I can live without id,
and (.)

> >For example instead of
> >
> >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,
>
> Actually this would only work on container type-constructors. If you had
> a type that was some kind of container only of Char, you could not make
> it an instance of your Container.

Same story, you shouldn't have had a Container of Char only in the first
place. For example string class in STL is parametrized based on its
character type, ascii, unicode etc. If you really have to have one that
works on non-parametrized containers, add another map function in the
type-class. Besides the original "map" cannot handle Containers of only Char
besides the List. Your argument seems self refuting.