Last active
August 29, 2015 14:21
-
-
Save wecing/1b00c4fd29c20232686a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// scala | |
for ( p <- e1 ) yield e2 | |
// translation | |
e1 map { case p => e2 } | |
// haskell | |
(\p -> e2) <$> e1 // i.e. "fmap (\p -> e2) e1" | |
// aka | |
do p <- e1 | |
e2 | |
// scala | |
for ( p <- e1 ) e2 | |
// translation | |
e1 foreach { case p => e2 } | |
// haskell | |
(\p -> e2) <$> e1 // but has side-effect, and result is discarded | |
// scala | |
for ( p1 <- e1; p2 <- e2; ...) yield e | |
// translation | |
e1 flatMap { case p1 => for ( p2 <- e2; ...) yield e } | |
// haskell | |
e1 >>= \p1 -> "for ( p2 <- e2; ...) yield e" // should expand, of course | |
// aka | |
do p1 <- e1 | |
p2 <- e2 | |
... | |
e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment