Last active
November 15, 2021 15:40
-
-
Save jmitchell/9b9e1f3a473060841d50 to your computer and use it in GitHub Desktop.
Haskell typeclass flashcards (Anki-importable)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Monoids | |
Basic description of Monoid; Types with an associative binary operation and an identity element; typeclass-doc monoid | |
Monoid typeclass methods?; "mempty :: a | |
mappend :: a -> a -> a | |
mconcat :: [a] -> a"; typeclass-methods monoid | |
Monoid inherits from?; Nothing; typeclass-inherits-from monoid | |
typeclass of mempty?; Monoid; method-type monoid | |
typeclass of mappend?; Monoid; method-type monoid | |
typeclass of mconcat?; Monoid; method-type monoid | |
Minimal complete definition of Monoid?; mempty, mappend; typeclass-minimal-def monoid | |
mempty description?; Identity of mappend; method-doc monoid | |
mappend description?; An associative binary operation; method-doc monoid | |
mconcat description?; Fold a list using the monoid; method-doc monoid | |
Law: mappend mempty x == ?; x; typeclass-law monoid | |
Law: mappend x mempty == ?; x; typeclass-law monoid | |
Law: mappend x (mappend y z) == ?; mappend (mappend x y) z; typeclass-law monoid | |
Law: mconcat == ?; foldr mappend mempty; typeclass-law monoid | |
(<>) shorthand for?; mappend; method-synonym monoid | |
# Functors | |
Basic description of Functor; Types that can be mapped over; typeclass-doc functor | |
Functor typeclass methods?; "fmap :: (a -> b) -> f a -> f b"; typeclass-methods functor | |
Functor inherits from?; Nothing; typeclass-inherits-from functor | |
typeclass of fmap?; Functor; method-type functor | |
Minimal complete definition of Functor?; fmap; typeclass-minimal-def functor | |
fmap description?; Map from one functor type to another; method-doc functor | |
Law: fmap id == ?; id; typeclass-law functor | |
Law: fmap (f . g) == ?; fmap f . fmap g; typeclass-law functor | |
# Applicatives | |
Basic description of Applicative; A functor with sequential application; typeclass-doc applicative | |
Applicative typeclass methods?; "pure :: a -> f a | |
(<*>) :: f (a -> b) -> f a -> f b"; typeclass-methods applicative | |
Applicative inherits from?; Functor; typeclass-inherits-from applicative | |
typeclass of pure?; Applicative; method-type applicative | |
typeclass of (<*>)?; Applicative; method-type applicative | |
Minimal complete definition of Applicative?; pure, (<*>); typeclass-minimal-def applicative | |
pure description?; Lift a value into applicative; method-doc applicative | |
(<*>) description?; Sequential application; method-doc applicative | |
Law: pure id <*> v == ?; v; typeclass-law applicative | |
Law: pure (.) <*> u <*> v <*> w == ?; u <*> (v <*> w); typeclass-law applicative | |
Law: pure f <*> pure x == ?; pure (f x); typeclass-law applicative | |
Law: u <*> pure y == ?; pure ($ y) <*> u; typeclass-law applicative | |
Law: pure f <*> x == ?; fmap f x; typeclass-law applicative | |
# Foldables | |
Basic description of Foldable; Data structures that can be folded (combined, reduced, summarized); typeclass-doc foldable | |
Foldable typeclass methods?; "fold :: Monoid m => t m -> m | |
foldMap :: Monoid m => (a -> m) -> t a -> m | |
foldr :: (a -> b -> b) -> b -> t a -> b | |
foldr' :: (a -> b -> b) -> b -> t a -> b | |
foldl :: (b -> a -> b) -> b -> t a -> b | |
foldl' :: (b -> a -> b) -> b -> t a -> b | |
foldr1 :: (a -> a -> a) -> t a -> a | |
foldl1 :: (a -> a -> a) -> t a -> a"; typeclass-methods foldable | |
Foldable inherits from?; Nothing; typeclass-inherits-from foldable | |
typeclass of foldMap?; Foldable; method-type foldable | |
typeclass of foldr?; Foldable; method-type foldable | |
typeclass of foldr'?; Foldable; method-type foldable | |
typeclass of foldl?; Foldable; method-type foldable | |
typeclass of foldl'?; Foldable; method-type foldable | |
typeclass of foldr1?; Foldable; method-type foldable | |
typeclass of foldl1?; Foldable; method-type foldable | |
Minimal complete definition of Foldable?; foldMap | foldr; typeclass-minimal-def foldable | |
fold description?; Combine the elements of a structure using a monoid; method-doc foldable | |
foldMap description?; Map each element of the structure to a monoid, and combine the results; method-doc foldable | |
Foldable.foldr description?; Right-associative fold of a structure; method-doc foldable | |
foldr' description?; Right-associative fold of a structure, but with strict application of the operator; method-doc foldable | |
Foldable.foldl; Left-associative fold of a structure; method-doc foldable | |
foldl' description?; Left-associative fold of a structure, but with strict application of the operator; method-doc foldable | |
foldr1 description?; A variant of foldr that has no base case, and thus may only be applied to non-empty structures; method-doc foldable | |
foldl1 description?; A variant of foldl that has no base case, and thus may only be applied to non-empty structures; method-doc foldable | |
# Traversables | |
Basic description of Traversable; Functors representing data structures that can be traversed from left to right; typeclass-doc traversable | |
Traversable typeclass methods?; "traverse :: Applicative f => (a -> f b) -> t a -> f (t b) | |
sequenceA :: Applicative f => t (f a) -> f (t a) | |
mapM :: Monad m => (a -> m b) -> t a -> m (t b) | |
sequence :: Monad m => t (m a) -> m (t a)"; typeclass-methods traversable | |
Traversable inherits from?; Functor, Foldable; typeclass-inherits-from traversable | |
typeclass of traverse?; Traversable; method-type traversable | |
typeclass of sequenceA?; Traversable; method-type traversable | |
typeclass of mapM?; Traversable; method-type traversable | |
typeclass of sequence?; Traversable; method-type traversable | |
Minimal complete definition of Traversable?; traverse | sequenceA; typeclass-minimal-def traversable | |
traverse description?; Map each element of a structure to an action, evaluate these actions from left to right, and collect the results; method-doc traversable | |
sequenceA description?; Evaluate each action in the structure from left to right, and collect the results; method-doc traversable | |
mapM description?; Map each element of a structure to a monadic action, evaluate these actions from left to right, and collect the results; method-doc traversable | |
sequence description?; Evaluate each monadic action in the structure from left to right, and collect the results; method-doc traversable | |
Law: t . traverse f == ?; traverse (t . f); typeclass-law traversable | |
Law: traverse Identity == ?; Identity; typeclass-law traversable | |
Law: traverse (Compose . fmap g . f) == ?; Compose . fmap (traverse g) . traverse f; typeclass-law traversable | |
Law: t . sequenceA == ?; sequenceA . fmap t; typeclass-law traversable | |
Law: sequenceA . fmap Identity == ?; Identity; typeclass-law traversable | |
Law: sequenceA . fmap Compose == ?; Compose . fmap sequenceA . sequenceA; typeclass-law traversable | |
# Monads | |
Basic description of Monad; Abstract datatype of actions; typeclass-doc monad | |
Monad typeclass methods?; "(>>=) :: forall a b. m a -> (a -> m b) -> m b | |
(>>) :: forall a b. m a -> m b -> m b | |
return :: a -> m a"; typeclass-methods monad | |
Monad inherits from?; Nothing (except Applicative in GHC 7.10+); typeclass-inherits-from monad | |
typeclass of (>>=)?; Monad; method-type monad | |
typeclass of (>>)?; Monad; method-type monad | |
typeclass of return?; Monad; method-type monad | |
Minimal complete definition of Monad?; (>>=), return; typeclass-minimal-def monad | |
(>>=) description?; Sequentially compose two actions, passing any value produced by the first as an argument to the second; method-doc monad | |
(>>) description?; Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages; method-doc monad | |
return description?; Inject a value into the monadic type; method-doc monad | |
Law: return a >>= k == ?; k a; typeclass-law monad | |
Law: m >>= return == ?; m; typeclass-law monad | |
Law: m >>= (\x -> k x >>= h) == ?; (m >>= k) >>= h; typeclass-law monad |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment