Last active
December 2, 2015 16:55
-
-
Save ivanperez-keera/3587de224c9effac4391 to your computer and use it in GitHub Desktop.
Strange MultiWayIf indentation problem in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE MultiWayIf #-} | |
test1 :: Maybe String -> String | |
test1 x = | |
case () of | |
_ | True | |
-> "Good morning" | |
test2 :: Maybe String -> String | |
test2 x = | |
if | True -> "Good morning" | |
| False -> "Nope" | |
test3 :: Maybe String -> String | |
test3 x = | |
if | Just n <- x -> "Hi" | |
| otherwise -> "Nope" | |
-- The following fails to parse because the -> are aligned with the | | |
test4 :: Maybe String -> String | |
test4 x = | |
if | Just n <- x | |
-> "Hi" | |
| otherwise | |
-> "Nope" | |
test5 :: Maybe String -> String | |
test5 x = | |
if | Just n <- x | |
, length n > 5 -- Works only if line is more indented than previous line | |
-> "Hi" | |
| otherwise | |
-> "Nope" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It may be unintuitive, but I don't think this is a bug. The threshold for the required indentation is set the next token following "of" for the case expression, or following "if" for the MultiWayIf. In the former case this is the pattern, and in the latter case this is the vertical bar. If you aligned the "->" with the beginning of the pattern (the underscore) in the case expression you'd get the same error. The continuation line has to be more indented than the token that began the block.