Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Let indentation inside proc notation

I have the following code

{-# LANGUAGE Arrows #-}

test :: Int -> Int
test =
  proc x -> do
    let x = case x of
              3 -> 2
              2 -> 1
              _ -> 0
    returnA -< x

test2 =
  proc x -> do
    let x =
      case x of
        3 -> 2
        2 -> 1
        _ -> 0
    returnA -< x

test compiles, but test2 does not parse. Is it possible to have the case on a separate line after the =?

like image 743
yong Avatar asked Jul 23 '14 01:07

yong


1 Answers

This is unrelated to proc notation. The case must be at least as indented as one character after the start name being bound by let.

For example, this compiles:

test x =
  let y =
       case x of
         3 -> 2
         1 -> 1
         _ -> 0
  in ()

and so does this:

test2 x =
  let abcdefghi =
       case x of
         3 -> 2
         1 -> 1
         _ -> 0
  in ()

but this doesn't:

test3 x =
  let abcdefghi =
      case x of
        3 -> 2
        1 -> 1
        _ -> 0
  in ()

because the case is at the same level as the first character of abcdefghi.

like image 103
David Young Avatar answered Oct 25 '22 00:10

David Young