Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Error: parse error on input `='

Specs

GHC 6.12.1

Mac OS X 10.6.4 x64

MacBook Pro

Problem

I'm having trouble using let syntax. The following code refuses to compile:

module Main where

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

I tried tabbing in y = 2 and z = 3 even more. No dice.

(Undesirable) Solutions

The only way I've gotten the code to compile is either

  1. Replacing hard tabs with spaces.
  2. Replacing the let clause with a where clause.
like image 338
mcandre Avatar asked Aug 09 '10 01:08

mcandre


1 Answers

Saizan on #haskell explains that the assignments in a let expression have to align, not let itself. As long as the assignments line up, it's okay to use hard tabs or soft tabs.

Correct code:

module Main where

main = let
        x = 1
        y = 2
        z = 3
    in putStrLn $ "X = " ++ show x ++ "\nY = " ++ show y ++ "\nZ = " ++ show z
like image 57
mcandre Avatar answered Oct 19 '22 16:10

mcandre