Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Post Timeline

Explicitly set syntax highlighting languages, remove smart quotes
Source Link
Bob
  • 16.9k
  • 3
  • 30
  • 47
[1,2,3].map(x => x + 1)
[1,2,3].map(x => x + 1)
[1,2,3].flatMap(x => [x + 1])
[1,2,3].flatMap(x => [x + 1])
[1,2,3].map(a => a + 1).filter(b => b != 3)
[1,2,3].map(a => a + 1).filter(b => b != 3)
[1,2,3].flatMap(a => [a + 1]).flatMap(b => b != 3 ? [b] : [])
[1,2,3].flatMap(a => [a + 1]).flatMap(b => b != 3 ? [b] : [])
[1,2,3].flatMap(a => [a + 1].flatMap(b => b != 3 ? [b] : []))
[1,2,3].flatMap(a => [a + 1].flatMap(b => b != 3 ? [b] : []))
[1,2,3] >>= \a -> [a+1] >>= \b -> if b == 3 then [] else [b] 
[1,2,3] >>= \a -> [a+1] >>= \b -> if b == 3 then [] else [b] 
do 
 a <- [1,2,3] 
 b <- [a+1] 
 if b == 3 then [] else [b] 
do 
 a <- [1,2,3] 
 b <- [a+1] 
 if b == 3 then [] else [b] 
streetName = getStreetName (getAddress (getUser 17)) 
streetName = getStreetName (getAddress (getUser 17)) 
case getUser 17 of
 Nothing -> Nothing 
 Just user ->
 case getAddress user of
 Nothing -> Nothing 
 Just address ->
 getStreetName address
case getUser 17 of
 Nothing -> Nothing 
 Just user ->
 case getAddress user of
 Nothing -> Nothing 
 Just address ->
 getStreetName address
do
 user <- getUser 17
 addr <- getAddress user
 getStreetName addr
do
 user <- getUser 17
 addr <- getAddress user
 getStreetName addr
add2 :: State Integer Integer
add2 = do
 -- add 1 to state
 x <- get
 put (x + 1)
 -- increment in another way
 modify (+1)
 -- return state
 get
evalState add2 7
=> 9
add2 :: State Integer Integer
add2 = do
 -- add 1 to state
 x <- get
 put (x + 1)
 -- increment in another way
 modify (+1)
 -- return state
 get
evalState add2 7
=> 9
main :: IO ()
main = do 
 putStrLn "Hello World"
main :: IO ()
main = do 
 putStrLn "Hello World"
main = do
 putStrLn "What is your name?"
 name <- getLine
 putStrLn ("hello" ++ name)
main = do
 putStrLn "What is your name?"
 name <- getLine
 putStrLn ("hello" ++ name)
[1,2,3].map(x => x + 1)
[1,2,3].flatMap(x => [x + 1])
[1,2,3].map(a => a + 1).filter(b => b != 3)
[1,2,3].flatMap(a => [a + 1]).flatMap(b => b != 3 ? [b] : [])
[1,2,3].flatMap(a => [a + 1].flatMap(b => b != 3 ? [b] : []))
[1,2,3] >>= \a -> [a+1] >>= \b -> if b == 3 then [] else [b] 
do 
 a <- [1,2,3] 
 b <- [a+1] 
 if b == 3 then [] else [b] 
streetName = getStreetName (getAddress (getUser 17)) 
case getUser 17 of
 Nothing -> Nothing 
 Just user ->
 case getAddress user of
 Nothing -> Nothing 
 Just address ->
 getStreetName address
do
 user <- getUser 17
 addr <- getAddress user
 getStreetName addr
add2 :: State Integer Integer
add2 = do
 -- add 1 to state
 x <- get
 put (x + 1)
 -- increment in another way
 modify (+1)
 -- return state
 get
evalState add2 7
=> 9
main :: IO ()
main = do 
 putStrLn "Hello World"
main = do
 putStrLn "What is your name?"
 name <- getLine
 putStrLn ("hello" ++ name)
[1,2,3].map(x => x + 1)
[1,2,3].flatMap(x => [x + 1])
[1,2,3].map(a => a + 1).filter(b => b != 3)
[1,2,3].flatMap(a => [a + 1]).flatMap(b => b != 3 ? [b] : [])
[1,2,3].flatMap(a => [a + 1].flatMap(b => b != 3 ? [b] : []))
[1,2,3] >>= \a -> [a+1] >>= \b -> if b == 3 then [] else [b] 
do 
 a <- [1,2,3] 
 b <- [a+1] 
 if b == 3 then [] else [b] 
streetName = getStreetName (getAddress (getUser 17)) 
case getUser 17 of
 Nothing -> Nothing 
 Just user ->
 case getAddress user of
 Nothing -> Nothing 
 Just address ->
 getStreetName address
do
 user <- getUser 17
 addr <- getAddress user
 getStreetName addr
add2 :: State Integer Integer
add2 = do
 -- add 1 to state
 x <- get
 put (x + 1)
 -- increment in another way
 modify (+1)
 -- return state
 get
evalState add2 7
=> 9
main :: IO ()
main = do 
 putStrLn "Hello World"
main = do
 putStrLn "What is your name?"
 name <- getLine
 putStrLn ("hello" ++ name)

Like any other practical language, Haskell has a bunch of built-in functions which interface with the outside world: putStrLineputStrLn, readLinegetLine and so on. These functions are called "impure" because they either cause side effects or have non-deterministic results. Even something simple like getting the time is considered impure because the result is non-deterministic – calling it twice with the same arguments may return different values.

Like any other practical language, Haskell has a bunch of built-in functions which interface with the outside world: putStrLine, readLine and so on. These functions are called "impure" because they either cause side effects or have non-deterministic results. Even something simple like getting the time is considered impure because the result is non-deterministic – calling it twice with the same arguments may return different values.

Like any other practical language, Haskell has a bunch of built-in functions which interface with the outside world: putStrLn, getLine and so on. These functions are called "impure" because they either cause side effects or have non-deterministic results. Even something simple like getting the time is considered impure because the result is non-deterministic – calling it twice with the same arguments may return different values.

Corrected missing parentheses around putStrLn. The given code would not have executed
Source Link
do a <- [1,2,3] 
 b <- [a+1] 
 if b == 3 then [] else [b] 
main = do
 putStrLn "What is your name?"
 name <- getLine
 putStrLn ("hello" ++ name)
do a <- [1,2,3] 
 b <- [a+1] 
 if b == 3 then [] else [b] 
main = do
 putStrLn "What is your name?"
 name <- getLine
 putStrLn "hello" ++ name
do a <- [1,2,3] 
 b <- [a+1] 
 if b == 3 then [] else [b] 
main = do
 putStrLn "What is your name?"
 name <- getLine
 putStrLn ("hello" ++ name)
edited body
Source Link
JacquesB
  • 43k
  • 13
  • 77
  • 89
Loading
Small grammar fix
Source Link
Matt Thomas
  • 5.9k
  • 4
  • 32
  • 65
Loading
Fixed some minor grammar mistakes and spelling, changed all "monadic" to "monad", small clerical edits
Source Link
Loading
Updated examples
Source Link
JacquesB
  • 43k
  • 13
  • 77
  • 89
Loading
added 21 characters in body
Source Link
JacquesB
  • 43k
  • 13
  • 77
  • 89
Loading
Greately expanded examples based on feedback
Source Link
JacquesB
  • 43k
  • 13
  • 77
  • 89
Loading
Fix MSDN blog broken link, HTTPS
Source Link
Callum Watkins
  • 3k
  • 4
  • 34
  • 54
Loading
Improve the desugaring of the list comprehension example
Source Link
Loading
added 2 characters in body
Source Link
nbro
  • 16k
  • 34
  • 122
  • 219
Loading
added 211 characters in body
Source Link
sekhar
  • 700
  • 1
  • 7
  • 13
Loading
added 1 character in body
Source Link
amalloy
  • 93k
  • 8
  • 150
  • 216
Loading
Trivial grammar fix
Source Link
Mohit Jain
  • 30.6k
  • 8
  • 80
  • 105
Loading
Copy edited (e.g. ref. <http://en.wikipedia.org/wiki/Input/output>). (its = possessive, it's = "it is" or "it has". See for example <http://www.wikihow.com/Use-Its-and-It%27s>.)
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 110
  • 134
Loading
Added explanation of how list comprehensions are in facts examples of using monads.
Source Link
Loading
Adding an apostrophe to "monads".
Source Link
michaelrp
  • 663
  • 4
  • 10
Loading
Noticed a few word usage errors.
Source Link
fncomp
  • 6.2k
  • 4
  • 36
  • 43
Loading
Post Made Community Wiki by MathematicalOrchid
Typo.
Source Link
arrowd
  • 34.6k
  • 8
  • 89
  • 123
Loading
extracted abbrevation (your post is far too nice, to interrupt the reader with such things :) ) I hope you dont mind, and accept it
Source Link
Loading
Spelling fixes
Source Link
Jim Ferrans
  • 31.1k
  • 12
  • 59
  • 83
Loading
added 710 characters in body
Source Link
JacquesB
  • 43k
  • 13
  • 77
  • 89
Loading
added 2103 characters in body
Source Link
JacquesB
  • 43k
  • 13
  • 77
  • 89
Loading
1
2
lang-hs

AltStyle によって変換されたページ (->オリジナル) /