It's not just newtype
, it works the same with data
. What you seem to be unaware of is named field syntax,
newtype ZipList a = ZipList { getZipList :: [a] }
is almost the same as
newtype ZipList a = ZipList [a]
getZipList :: ZipList a -> [a]
getZipList (ZipList xs) = xs
but the named field syntax allows more convenient updating and pattern matching - in particular it's much more convenient for named fields in data
types with multiple fields.
The named field (implicitly) defines the accessor function that extracts the contained data from the wrapped value.