[Haskell-cafe] Factoring into type classes
jonathanccast at fastmail.fm
Mon Jan 19 15:31:59 EST 2009
On Mon, 2009-01-19 at 12:10 -0800, Iavor Diatchki wrote:
> >> I usually
> >> avoid using the "newtype" trick as I find it inconvenient: usually
> >> the newtype does not have the same operations as the underlying type
> >> and so it cannot be used directly, and if you are going to wrap thing
> >> just when you use the class methods,
> > OTOH, I think you mean here `when you use class methods and when you use
> > overloaded functions'.
> Sure, the point is that you are essentially adding a type annotation,
> which is like using a non-overloaded function. Compare, for example:
> "mappend add x y" and "getSum (mappend (Sum x) (Sum y))". I think
> that the first one is quite a bit more readable but, of course, this
> is somewhat subjective.
Right. Of course, this issue comes up quite frequently; even
sort :: Ord alpha => [alpha] -> [alpha]
Needs to be specialized to non-standard Ord instances. I think that, if
we're going to restrict type classes to only those cases where we never
want to specialize an overloaded function to a non-standard instance,
that we're going to end up with Eq, Num, and maybe Functor as classes.
I'm not sure a general language mechanism is really needed just for
More information about the Haskell-Cafe