Last active
August 29, 2015 14:04
-
-
Save fnx-ableton/74380ed44a7989f60db2 to your computer and use it in GitHub Desktop.
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
-- what does this function do? | |
someFn :: (a -> b) -> [a] -> [b] | |
-- map! | |
map :: (a -> b) -> [a] -> [b] | |
-- not only lists are mappable | |
data Maybe a = Totes a | Nada | |
mapMaybe :: a -> b -> Maybe a -> Maybe b | |
mapMaybe f (Totes x) = Totes (f x) | |
mapMaybe f Nada = Nada | |
-- abstraction \o/ | |
class Mappable m where | |
mmap :: (a -> b) -> m a -> m b | |
instance Mappable List where | |
mmap = map | |
instance Mappable Maybe where | |
mmap f (Totes x) = Totes (f x) | |
mmap f Nada = Nada | |
-- what do we know about this function without looking at implementations? | |
someFn :: Mappable m, Num a => m a => m a | |
-- either it returns its input or it applies a numerical operation to all items contained in it | |
-- e.g.: | |
someFn stuff = mmap (*2) stuff |
how about adding Joinable
?
class Joinable j where
join :: j (j a) -> j a
and then? hm.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
maybe i could reverse things and start with the desired function type