[Haskell-cafe] data/newtype vs. class
martin.drautzburg at web.de
Mon Jun 16 18:54:30 UTC 2014
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
More information about the Haskell-Cafe