I am curious about where getZipList is defined in ghc.
Control.Applicative has this definition for ZipList.
newtype ZipList a = ZipList { getZipList :: [a] }
One way to use ZipLists is (from LYAH):
ghci> getZipList $ (+) <$> ZipList [1,2,3] <*> ZipList [100,100,100]
[101,102,103]
I am curious how getZipList knows what to return.
Perhaps I am missing something about the newtype keyword.
Thanks!
It’s not just
newtype, it works the same withdata. What you seem to be unaware of is named field syntax,is almost the same as
but the named field syntax allows more convenient updating and pattern matching – in particular it’s much more convenient for named fields in
datatypes with multiple fields.The named field (implicitly) defines the accessor function that extracts the contained data from the wrapped value.