Skip to main content

Posts

Showing posts from June, 2020

Notes on Learn you a Haskell (Newtype and Monoids)

We're reading Learn You a Haskell for Great Good! at the office's non-fiction book club! This covers the second two parts o f chapter 11 (Functors, Applicative Functors and Monoids) — from the section entitled 'The newtype keyword' and onwards. Legend Regular text summarizes a point the document made. Italicize d font expresses my terrible, terrible opinions or attempts at explanation. Highlighted   text indicates that this note was important to my understanding, and if it's italicized, then I even thought of it myself! Notes The newtype keyword Recap Data = ADT Type = type synonym <*> can logically have different implementations for e.g. a list Such as ZipList vs [] Adding additional typeclass instances for a type Can be done by wrapping the existing type in a `data` with a single constructor. Use a record to make it easier to extract contents. Downside: slight perf overhead. Use newtype: wraps an existing ...

Notes on Learn you a Haskell (Functors and Applicative Functors)

We're reading Learn You a Haskell for Great Good! at the office's non-fiction book club! This covers the first two parts o f chapter 11 (Functors, Applicative Functors and Monoids) up to the end of the discussion on applicative functors. Legend Regular text summarizes a point the document made. Italicize d font expresses my terrible, terrible opinions or attempts at explaination. Highlighted   text indicates that this note was important to my understanding, and if it's italicized, then I even thought of it myself! Notes Haskell's type system doesn't require placing types in a hierarchy, which can be useful for designs. Typeclasses are "open" for extension Recap: `Eq` (equateable) and `Functor` (mappable) Functors Recap e.g. lists, Maybe, trees. Typeclass fmap :: (a->b) -> f a -> f b Functors are "computational context" e.g. that a value exists or not, that there are multipl...