是什么
无可辩驳的模式因模式而失败
意思?什么情况会导致此运行时错误?
请考虑以下代码段:
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) 背景:我不明白〜并且正在请求用例.
鉴于:
{-# 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)
在什么情况下会是使用有用f了g?
我正在玩一下zipWith并遇到以下情况:
Prelude Control.Applicative> :t zipWith id
zipWith id :: [b -> c] -> [b] -> [c]
Run Code Online (Sandbox Code Playgroud)
为什么编译器期望下一个参数是一个函数列表?
我试图分析,但无法断定,为什么下一个参数必须是函数列表.
当我id转到时,签名是如何申请的zipWith?