Quantcast
Channel: Should do-notation be avoided in Haskell? - Stack Overflow
Viewing all articles
Browse latest Browse all 8

Should do-notation be avoided in Haskell?

$
0
0

Most Haskell tutorials teach the use of do-notation for IO.

I also started with the do-notation, but that makes my code look more like an imperative language more than a FP language.

This week I saw a tutorial use IO with <$>

stringAnalyzer <$> readFile "testfile.txt"

instead of using do

main = do    strFile <- readFile "testfile.txt"    let analysisResult = stringAnalyzer strFile    return analysisResult

And the log analysis tool is finished without the do.

So my question is "Should we avoid do-notation in any case?".

I know maybe do will make the code better in some cases.

Also, why do most tutorials teach IO with do?

In my opinion <$> and <*> makes the code more FP than IO.


Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles



Latest Images