Opened 7 years ago

Closed 7 years ago

#2259 closed bug (invalid)

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

Reported by: jsnx Owned by:
Priority: normal Milestone:
Component: Compiler (Parser) Version: 6.8.2
Keywords: Cc:
Operating System: MacOS X Architecture: x86
Type of failure: Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

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 (1)

comment:1 Changed 7 years ago by igloo

  • difficulty set to Unknown
  • Resolution set to invalid
  • Status changed from new to closed

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

Note: See TracTickets for help on using tickets.