[Haskell-cafe] Factoring into type classes

Patai Gergely patai_gergely at fastmail.fm
Thu Jan 22 16:12:00 EST 2009

Hello again,

> I think that I have done all of the above in different situations, and
> so I don't think that there is a single correct answer.  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, then you may as well use the
> non-overloaded operations.
Yes, I had the same thought. If I have to explicitly convert between
various wrappers, that's basically the same as defining separate
functions from the start. The newtype trick is certainly nice when you
don't want to mix the different uses on the same piece of data, but that
was exactly my problem. I'd say your posts as well as wren ng thornton's
answer my question as thoroughly as possible at this point, although
wren's lengthy letter could probably even be extended and turned into a
tutorial on the topic.

Of course type classes are not only important just for making dictionary
passing implicit, but also because of their interactions, which is
nicely demonstrated by the sigfpe blog entry that someone also linked
from this thread. That's probably why I feel kind of uncomfortable when
not taking advantage of standard classes wherever possible.

Thanks for the answers,


http://www.fastmail.fm - Access all of your messages and folders
                          wherever you are

More information about the Haskell-Cafe mailing list