Haskell Error: parse error on input `='

后端 未结 5 2061
执笔经年
执笔经年 2021-01-05 10:14

Specs

GHC 6.12.1

Mac OS X 10.6.4 x64

MacBook Pro

Problem

I\'m having trouble using let

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-05 10:26

    If you insist on TAB characters in your source, the following compiles:

    module Main where
    
    main =
        let x = 1
            y = 2
            z = 3
        in putStrLn $ "X = " ++ show x ++ "\nY = " ++ show y ++ "\nZ = " ++ show z
    

    where all leading whitespace is either one or two TABs, and the whitespace between let and x = 1 is also a TAB. Viewed in vi's list mode to make TABs and line-ends explicit:

    module Main where$
    $
    main =$
    ^Ilet^Ix = 1$
    ^I^Iy = 2$
    ^I^Iz = 3$
    ^Iin putStrLn $ "X = " ++ show x ++ "\nY = " ++ show y ++ "\nZ = " ++ show z$

    Your life will be much simpler and your code prettier if you switch to spaces.

提交回复
热议问题