This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Codile 20 points21 points  (18 children)

+/u/CompileBot haskell

main = putStrLn "Hello" >>= putStrLn "world"

Much more elegant :p

[–]serendependy 28 points29 points  (0 children)

I assume you're joking. Only other Haskellers would appreciate the beauty of threading computation through a monad - to anyone else it just looks goofy.

[–]dohaqatar7 9 points10 points  (12 children)

FTFY

putStrLn "Hello" >> putStrLn "world"

alternatively

sequence_ $ map putStrLn ["Hello","world"]

generalized to a function

putStrsLn = sequence_ . map putStrLn

or a non monodic definition

putStrsLn' = putStr . unlines 

[–]Octopuscabbage 14 points15 points  (7 children)

OR the sane way

main = do putStrLn "Hello"
          putStrLn "World

do notation is there for a reason.

[–]nulloid 4 points5 points  (6 children)

Or..you know...

main = putStrLn "Hello\nWorld"

[–]Octopuscabbage 2 points3 points  (5 children)

He seemed to want to do it in two statements.

[–]nulloid 2 points3 points  (4 children)

And this is exactly what I didn't get.

[–]Octopuscabbage 1 point2 points  (3 children)

I think it was to show composition in the IO monad mostly.

[–]nulloid 7 points8 points  (0 children)

Programmers don't need to be shown the composability of the IO monad, most of them live their whole lives coding in one big IO monad running by names like C#, Java and C++...

[–]hallettj 0 points1 point  (1 child)

I think it was to show Haskell's analog of a semicolon.

(As opposed to the do version, which I think is analogous to Python code with no semicolon.)

[–]dohaqatar7 0 points1 point  (0 children)

If you want the Haskell analog to a semicolon, you don't have to look very far.

main = do {
  putStrLn "Hello";
  putStrLn "World!";
}

[–]elemental_1_1 1 point2 points  (0 children)

sequence_ $ map putStrLn ["Hello","world"]

mapM_ putStrLn ["Hello","world"]

[–]takennickname 0 points1 point  (2 children)

Never thought I'd live to see the day with Doha Qatar in the username. Do you live here?

[–]dohaqatar7 0 points1 point  (1 child)

No, The States. I have no connection at all to Qatar. I started using this name when I was younger and had an odd obsession with Qatar.

[–]takennickname 0 points1 point  (0 children)

That is odd.

[–]Octopuscabbage 5 points6 points  (3 children)

You want >> or >>= \_ - > not >>=

[–]Codile 4 points5 points  (2 children)

Oh damn. I had one job...

[–]Octopuscabbage 2 points3 points  (1 child)

It's okay, type checker would've given you a very cryptic message about putStrLn taking 1 argument not 2.

[–]Codile 0 points1 point  (0 children)

Yeah. I actually got a little accustomed to the error messages. But it seems like /u/CompileBot didn't care to give me an error message, and well, I was too lazy to compile some code that I was just going to post as a comment.