相关疑难解决方法(0)

是什么导致"无可辩驳的模式因模式而失败",这是什么意思?

是什么

无可辩驳的模式因模式而失败

意思?什么情况会导致此运行时错误?

haskell runtime-error pattern-matching

24
推荐指数
3
解决办法
9308
查看次数

`~`(代字号)在实例上下文中意味着什么,为什么在某些情况下需要解决重叠?

一个复杂的问题.

请考虑以下代码段:

class                        D u a     where printD :: u -> a -> String
instance                     D a a     where printD _ _ = "Same type instance."
instance {-# overlapping #-} D u (f x) where printD _ _ = "Instance with a type constructor."
Run Code Online (Sandbox Code Playgroud)

这就是它的工作原理:

? printD 1 'a'
...
...No instance for (D Integer Char)...
...

? printD 1 1
"Same type instance."

? printD [1] [1]
...
...Overlapping instances for D [Integer] [Integer]
...

? printD [1] ['a'] …
Run Code Online (Sandbox Code Playgroud)

haskell typeclass

6
推荐指数
1
解决办法
233
查看次数

用2个函数理解`~`

背景:我不明白并且正在请求用例.

鉴于:

{-# LANGUAGE GADTs #-}

f :: a ~ b => a -> b -> b
f a b = a

g :: a -> a -> a
g a b = a
Run Code Online (Sandbox Code Playgroud)

在我看来,两个函数都是相同的:

Prelude> :r
[1 of 1] Compiling Main             ( TypeEq.hs, interpreted )
Ok, modules loaded: Main.
*Main> f 10 20
10
*Main> g 10 20
10
Run Code Online (Sandbox Code Playgroud)

在什么情况下会是使用有用fg

haskell

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

第二个参数如何成为函数列表?

我正在玩一下zipWith并遇到以下情况:

Prelude Control.Applicative> :t zipWith id
zipWith id :: [b -> c] -> [b] -> [c]
Run Code Online (Sandbox Code Playgroud)

为什么编译器期望下一个参数是一个函数列表?

我试图分析,但无法断定,为什么下一个参数必须是函数列表.

当我id转到时,签名是如何申请的zipWith

haskell zipwith

5
推荐指数
2
解决办法
156
查看次数