Ticket #2259 (closed bug: invalid)

Opened 7 months ago

Last modified 7 months ago

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

Reported by: jsnx Assigned to:
Priority: normal Milestone:
Component: Compiler (Parser) Version: 6.8.2
Severity: minor Keywords:
Cc: Difficulty: Unknown
Test Case: Operating System: MacOS X
Architecture: x86

Description

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?

Change History

05/03/08 05:36:43 changed by igloo

  • status changed from new to closed.
  • difficulty set to Unknown.
  • resolution set to invalid.

Thanks for the report. However, GHC is just following the language standard here. There is a proposal to fix this for Haskell' (the next version of the language standard): http://hackage.haskell.org/trac/haskell-prime/wiki/DoAndIfThenElse