[Haskell-cafe] Data declaration vs type classes

Imants Cekusins imantc at gmail.com
Fri Jan 8 10:38:47 UTC 2016


> How should one go about deciding to use data or class?

class:
class lets specify more than one method. when you define instance yet
do not implement all methods, compiler warns.
if you try to call class method without an instance for that type,
compiler warns.

pattern matching:
compiler does not warn if methods do not match every constructor of
the data type.

one way to decide if not sure, is to pick one way which seems easier
to refactor. when more code is written, it usually becomes obvious if
this approach does not fit. then refactor.


> Which is more appropriate here?
depends on the rest of the code. if this is it, then there is no real
difference.


More information about the Haskell-Cafe mailing list