Skip to content

can not make `if` look nice in a `do`

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?

Trac metadata
Trac field Value
Version 6.8.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Parser)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information