[Haskell-cafe] type class design

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Fri Oct 29 08:52:31 EDT 2010


On 29 October 2010 23:28, Uwe Schmidt <uwe at fh-wedel.de> wrote:
> Dear Haskellers,
>
> I've a question about type class design. When
> developing the set of functions for a class, there
> are often two or more functions, let's say f and g,
> where the semantics of g can be expressed by f.
>
> When writing down the code, there are two choices
> for g. First g is included in the type class, second
> g is defined outside and the signature has a context
> referencing the class.
>
> 1. case
>
> class Foo a where
>  f :: ... a ...
>  g :: ... a ...
>  g = expr[f]
>
> 2. case
>
> class Foo a where
>  f :: ... a ...
>
> g :: Foo a => ... a ...
> g = expr[f]
>
> [snip]
>
> My argument for 2.:
>
> c) Correctness: The semantics for g are fix (relative to f),
>  All laws for g hold everywhere, assuming f is implemented
>  correctly.

Another possible argument: large type classes can look daunting for
both implementors and users, even if only one or two methods need to
be defined for a minimal instantiation (I'm tring to work out what to
do here myself, as I have some typeclasses that for efficiency reasons
it might be nice to have more methods in the class, but it makes it a
little overwhelming).

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list