The handling of if within a do block is not consistent with it's handling outside of it.
import Text.ParserCombinators.Parsec
date AesthErr
= LineTooLong SourcePos Int
-- works fine
shorty0 len = do
s <- manyTill anyChar newLine
case length s > len of
True -> do
pos <- getPosition
return $ Left $ LineTooLong pos len
_ -> return $ Right s
-- epic fail
shorty1 len = do
s <- manyTill anyChar newLine
if length s > len then
do
pos <- getPosition
return $ Left $ LineTooLong pos len
else
return $ Right s
-- epic fail
shorty2 len = do
s <- manyTill anyChar newLine
if length s > len then
fmap (Left . flip LineTooLong len) getPosition
else
return $ Right s
Whereas this is fine:
f n =
if n > 7 then
"Great!"
else
"Less!"
Is this something I can fix?