concept newtype in category haskell

appears as: newtype, newtype, newtypes
Haskell in Depth MEAP V12

This is an excerpt from Manning's book Haskell in Depth MEAP V12.

Remember that a String is a synonym for a list of Char, so the first two examples share an instance for lists (and this operation is just list concatenation). The third and fourth examples apply instances that represent addition and multiplication—two basic operations over numeric types. They feature newtype wrappers Sum and Product for any type a with an instance of Num a.

Remember that we use the deriving clause on data (or newtype) declarations to ask a compiler to derive instances. We can also use standalone deriving via the StandaloneDeriving GHC extension. The ideas we discuss below don’t depend on the actual way to run deriving algorithms. So I assume that we always use the deriving clause.

Age {age = 33}
"{\"age\":33}"
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest