haskell - Using Functions of `a` on `newtype a` -
haskell - Using Functions of `a` on `newtype a` - let's have next newtype : newtype foo = foo integer deriving (eq, show) is there concise way add together 2 foo 's: (foo 10) + (foo 5) == foo 15 or max: max (foo 10) (foo 5) == foo 5 ? i'm curious if it's possible utilize functions of a newtype a rather do: addfoo :: foo -> foo -> foo addfoo (foo x) (foo y) = foo $ x + y just haskell98 knows how derive eq , show instances you, can turn on generalizednewtypederiving extension ghc num , ord instances need: prelude> :set -xgeneralizednewtypederiving prelude> newtype foo = foo integer deriving (eq, show, num, ord) prelude> (foo 10) + (foo 5) == foo 15 true prelude> max (foo 10) (foo 5) == foo 5 false haskell newtype