2

我试图推导出的类型zipWith . uncurry

zipWith . uncurry = (.) zipWith uncurry-- 串联作为函数

(.) :: (b1 -> c1) -> (a1 -> b1) -> a1 -> c1
zipWith :: (a2 -> b2 -> c2) -> [a2] -> [b2] -> [c2]
uncurry :: (a3 -> b3 -> c3) -> (a3, b3) -> c3

b1 ~ (a2 -> b2 -> c2)
c1 ~ [a2] -> [b2] -> [c2]
a1 ~ (a3 -> b3 -> c3)
b1 ~ (a3, b3) -> c3

a1(a3 -> b3 -> c3)和替换我得到c1[a2] -> [b2] -> [c2]

(.) zipWith uncurry :: a1 -> c1 ~ (a3 -> b3 -> c3) -> [a2] -> [b2] -> [c2]

如果我查询 GHCi:t zipWith . uncurry我得到:(a -> b1 -> b -> c) -> [(a, b1)] -> [b] -> [c]

我认为关键在于,b1 ~ (a2 -> b2 -> c2) ~ (a3, b3) -> c3但我不知道如何将我的结果与预期相匹配。

有什么帮助吗?

谢谢,
塞巴斯蒂安。

4

1 回答 1

4

如果我们从

(.) :: (b -> c) -> (a -> b) -> (a -> c)
zipWith :: (x -> y -> z) -> [x] -> [y] -> [z]
uncurry :: (u -> v -> w) -> (u, v) -> w

然后我们将zipWith' 类型与(b -> c)'uncurry类型与 ' 匹配(a -> b)

b             -> c
(x -> y -> z) -> ([x] -> [y] -> [z])

a             -> b
(u -> v -> w) -> ((u, v) -> w)

b然后我们必须将这些术语等同起来

b ~ x      -> (y -> z)
b ~ (u, v) -> w

所以w ~ (y -> z)x ~ (u, v)。到目前为止我们已经确定的表格:

a ~ u -> v -> w
b ~ x -> y -> z
c ~ [x] -> [y] -> [z]
x ~ (u, v)
w ~ y -> z

所以我们可以用xand代替w

a ~ u -> v -> (y -> z)
b ~ (u, v) -> y -> z
c -> [(u, v)] -> [y] -> [z]

我们现在可以完成类型zipWith . uncurry

(u -> v -> y -> z) -> ([(u, v)] -> [y] -> [z])

这也符合 GHCi 的答案。

The trick to these is just to line up the arrows and then just substitute back in until you can't reduce it any more.

于 2014-05-03T00:56:25.873 回答