Haskell错误:解析错误输入'=' [英] Haskell Error: parse error on input `='

查看:90
本文介绍了Haskell错误:解析错误输入'='的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

规格



GHC 6.12.1



Mac OS X 10.6。 4 x64



MacBook Pro

问题

我无法使用 let 语法。以下代码拒绝编译:

  module Main其中

main = let x = 1
y = 2
z = 3
in putStrLn $X =++ show x ++\\\
Y =++ show y ++\\\
Z =++ show z

我试着在 y = 2 z = 3 甚至更多。没有骰子。



(不需要)解决方案

获得要编译的代码是


  1. 用空格替换硬标签。
  2. 替换 let 子句,其中其中子句。


赋值必须对齐,而不是 let 本身。只要分配对齐,可以使用硬标签或软标签。



正确的代码:

模块主要其中

main = let
x = 1
y = 2
z = 3
in putStrLn $ X =++ show x ++\\\
Y =++ show y ++\\\
Z =++ show z


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.

解决方案

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

这篇关于Haskell错误:解析错误输入'='的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆