问题描述
我有点想参加考试.我想通过手动应用统一算法来找出这两个函数的类型:
I'm kind of stuck with an assignement concerning my exams. I want to find out the types of those two functions by applying the unifying algorithm by hand:
map map
(\x -> x >>= (\y -> y))
有人可以指出我正确的方向吗?到目前为止,我只能找到的唯一资源是Wikipedia条目,该条目并没有真正帮助我,因为其抽象程度很高.
Could someone point me to the right direction? The only ressource I could find until now was the wikipedia entry which is not really aiding me because of the high level of abstraction.
问候,谢谢.
推荐答案
让我们先做一个.
map :: (a -> b) -> [a] -> [b]
为了清楚起见,现在我们可以使用两个不同的名称再次编写它:
Now we can write it again with two different names, for clarity:
map :: (c -> d) -> [c] -> [d]
现在,我们将第二个替换为第一个的第一个参数,得到:
Now we substitute the second as the first parameter of the first, getting:
(a -> b) === (c -> d) -> ([c] -> [d]) (recall the associativity of (->))
a === (c -> d)
b === ([c] -> [d])
现在,我们将这些类型分配替换为第一个签名的其余部分,得到
Now we substitute those type assignments into the remaining portion of the first signature, getting
map map :: [c -> d] -> [[c] -> [d]]
清除?
这篇关于Haskell中的统一类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!