Created
August 19, 2015 11:11
-
-
Save shigemk2/2c754e79de064ca043e8 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
import Control.Applicative | |
sequenceA :: (Applicative f) => [f a] -> f [a] | |
sequenceA = foldr (liftA2 (:)) (pure []) | |
main = do | |
print $ sequenceA [Just 1, Just 2] | |
print $ sequenceA [Just 3, Just 2, Just 1] | |
print $ sequenceA [Just 3, Nothing, Just 1] | |
print $ sequenceA [[1,2,3],[4,5,6]] | |
print $ sequenceA [[1,2,3],[4,5,6],[3,4,4],[]] | |
print $ sequenceA [(+3),(*2)] 4 | |
-- equal | |
print $ (:) <$> Just 1 <*> sequenceA [Just 2] | |
print $ (:) <$> Just 1 <*> ((:) <$> Just 2 <*> sequenceA []) | |
print $ (:) <$> Just 1 <*> ((:) <$> Just 2 <*> Just []) | |
print $ (:) <$> Just 1 <*> Just [2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment