为什么在使用[LT .. GT]时,Haskell范围需要空间? [英] Why Haskell range needs spaces when using [LT .. GT]?

查看:127
本文介绍了为什么在使用[LT .. GT]时,Haskell范围需要空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  [LT .. GT] $ b $为什么当我在Haskell中做范围时, b  

但这不是:

  [LT..GT] 

以及这个神秘的错误意味着什么:

 < interactive>:1:2:
加载`LT'界面失败:
使用-v查看搜索的文件列表。

< interactive>:1:2:
一段必须放在括号中,因此:(`LT..` GT)

但是,当我使用Ints时,第二种形式(不含空格)可以工作:

  [1..3] 


解决方案

这是因为 LT .. 被解释为 LT 中的

$ b

< interactive>:1:2 :
无法加载`LT'的接口:
使用-v查看搜索的文件列表。

这意味着GHC找不到名为 LT 。如果您在不存在的库中使用限定名称,则会出现相同的消息:

  Prelude> SDJKASD.sdfhj 

< interactive>:1:1:
无法加载'SDJKASD'的接口:
使用-v查看搜索文件的列表。






 < ;交互式>:1:2:
一节必须放在括号中,因此:(`LT..` GT)

在Haskell中,部分是带有部分应用程序的中缀操作符,例如(* 3),相当于 \ x - > x * 3

在你的情况下, LT .. 被解释为中缀运算符,并且 GT 是由此运算符构成的部分的一部分。



一节必须用括号括起来,并且由于错误解释不会,解析器会像这样抱怨。



<错误的另一个例子:

  Prelude> [* 3] 

<互动>:1:2:
必须用圆括号括起来:(* 3)


Why is it that when I do range in Haskell, this works:

[LT .. GT]

but this doesn't:

[LT..GT]

and what does this cryptic error mean:

<interactive>:1:2:
    Failed to load interface for `LT':
      Use -v to see a list of the files searched for.

<interactive>:1:2:
    A section must be enclosed in parentheses thus: (`LT..` GT)

However, When I use Ints, the second form (without spaces) works:

[1..3]

解决方案

It's because LT.. is interpreted as the . operator in the LT module.


<interactive>:1:2:
    Failed to load interface for `LT':
      Use -v to see a list of the files searched for.

It means GHC cannot find a module named LT. The same message appears if you use a qualified name with a non-existing library:

Prelude> SDJKASD.sdfhj

<interactive>:1:1:
    Failed to load interface for `SDJKASD':
      Use -v to see a list of the files searched for.


<interactive>:1:2:
    A section must be enclosed in parentheses thus: (`LT..` GT)

In Haskell, a section is an infix operator with a partial application, e.g. (* 3), which is equivalent to \x -> x * 3.

In your case, LT.. is interpreted as an infix . operator, and the GT is part of the section formed with this operator.

A section must be enclosed in parenthesis, and since the misinterpretation does not, the parser will complain like this.

Another example of the error:

Prelude> [* 3]

<interactive>:1:2:
    A section must be enclosed in parentheses thus: (* 3)

这篇关于为什么在使用[LT .. GT]时,Haskell范围需要空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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