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

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

问题描述

我是Haskell的新手,开始 ghci 之后我试过了:

  fx = 2 * x 

我得到:

 < interactive>:1:4:对输入'='的解析错误

我不明白。

奇怪的是,它以前运作良好。我想我做了错误配置的Haskell。重新安装ghc6并不能解决问题。



有关信息,我使用的是Ubuntu 10.4,而ghc6的版本是6.12.1-12


在GHCi 7.x或更低版本中,你需要一个 let 来定义它。

  Prelude>让f x = x * 2 
Prelude> f 4
8

从GHC 8.0.1开始, GHCi支持顶级绑定,所以OP的代码无需修改即可正常工作。

  GHCi,版本8.0.1.20161213:http://www.haskell.org/ghc/:?寻求帮助
Prelude> f x = x * 2
前奏> f 4
8


I'm new to Haskell and after starting ghci I tried:

f x = 2 * x

and I obtained:

<interactive>:1:4: parse error on input `='

which I don't understand.

Strangely, it worked well before. I suppose that I have done misconfigured Haskell. Reinstalling ghc6 doesn't solve the problem.

For information, I use Ubuntu 10.4 and the version of ghc6 is 6.12.1-12

解决方案

In GHCi 7.x or below, you need a let to define things in it.

Prelude> let f x = x * 2
Prelude> f 4
8

Starting from GHC 8.0.1, top-level bindings are supported in GHCi, so OP's code will work without change.

GHCi, version 8.0.1.20161213: http://www.haskell.org/ghc/  :? for help
Prelude> f x = x * 2
Prelude> f 4
8

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

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