[Haskell-cafe] data/newtype vs. class

martin martin.drautzburg at web.de
Mon Jun 16 18:54:30 UTC 2014

Hello all,

I find myself trying to define a class, where a newtype would suffice.

E.g. once I was pondering over "named" things and my initial thought was "well that's a class, which asks for a function
'getName'". But then here http://www.haskell.org/pipermail/haskell-cafe/2010-June/078803.html someone showed me a
solution without any classes.

Recently I was pondering over "timed things" (things which change at specific ponts in time) and again my initial
thought was "that's a class, which asks for a method 'at'".

Then I remembered things like State, i.e. data types which wrap around functions. State is not a class, which asks for a
function 'nextState', it is all defined with data.

Can someone give me some guidance, when to use classes and when to use data? Are the two concepts interchangeable in
some scenarios?


More information about the Haskell-Cafe mailing list