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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…