小编Che*_*ish的帖子

Haskell列表类型错误列表

在GHCi中,我输入

let xs = [1, 'a']
Run Code Online (Sandbox Code Playgroud)

它会立即抱怨错误:

<interactive>:28:11:
No instance for (Num Char) arising from the literal ‘1’
In the expression: 1
In the expression: [1, 'a']
In an equation for ‘xs’: xs = [1, 'a']
Run Code Online (Sandbox Code Playgroud)

但是,当我输入

let xs = [1, [1, 1]]
Run Code Online (Sandbox Code Playgroud)

它刚刚过去了.当我尝试打印xs时它会抱怨:

<interactive>:5:1:
No instance for (Num [t0]) arising from a use of ‘it’
In a stmt of an interactive GHCi command: print it
Run Code Online (Sandbox Code Playgroud)

我认为Haskell是一种静态类型语言,因此任何类型错误都应该在编译时捕获.我想知道为什么在不同时间捕获上述2个错误?

haskell types ghci

5
推荐指数
1
解决办法
114
查看次数

标签 统计

ghci ×1

haskell ×1

types ×1