Skip to content

Confusing parse error for missing do keyword

import Control.Monad (when)

main = do
    when (True == True) $ 
        x <- getLine
        print "y"

This piece of code is missing the do keyword before the block, yet the error message that is returned is:

poc.hs:4:11: Parse error in pattern: True == True

Yet the next variant provides a bit more helpful information

import Control.Monad (when)

main = do
    when (True == True) $ 
        print "x"
        print "y"
poc.hs:5:9:
    Couldn't match expected type `(a0 -> IO ()) -> [Char] -> m0 ()'
                with actual type `IO ()'
    The function `print' is applied to three arguments,
    but its type `[Char] -> IO ()' has only one
    In the second argument of `($)', namely `print "x" print "y"'
    In a stmt of a 'do' block:
      when (True == True) $ print "x" print "y"
Trac metadata
Trac field Value
Version 7.6.3
Type Bug
TypeOfFailure OtherFailure
Priority low
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