> a) - > a - >一个是正确的答案。让我们把它分成几部分来找出原因。
- 你的函数有两个参数,
f
和 x
,因此签名将包含三个部分 - 比如 a - > c - > d
- 这些参数中的第一个是一元函数 - 它使得
a =(a - > b)$ c $ (请记住, a
可以是任何类型,只要它在签名中只出现一次)并且签名看起来像(a - > ; b) - > c - > d
- 结果
两次
与第一个参数的结果相同 - 这使得 d = b
和签名(a - > b) - > c - > b
-
f
第二个参数为两次
作为它的参数 - 这使得 c = a
并且签名看起来像这样:(a - > b) - > a - > b
-
两次
应用于其自己的输出,这意味着 a = b
- 这使得最终签名(a - > a) - > a - > a
I have to define the type profile of this function:
twice f x = f (f x);
The result should be the following, but I don't really get why.
('a -> 'a) -> 'a -> 'a
解决方案
(a -> a) -> a -> a
is the right answer. Let's split it to pieces to find out why.
- your function takes two arguments,
f
and x
, so the signature will have three parts - say, a -> c -> d
- first of these arguments is an unary function - that makes
a = (a -> b)
(remember that a
can be any type, as long as it appears only once in the signature) and the signature look like (a -> b) -> c -> d
- result of
twice
is same as the result of its first argument - that makes d = b
and the signature (a -> b) -> c -> b
f
takes second argument of twice
as its argument - this makes c = a
and the signature look like this: (a -> b) -> a -> b
twice
is applied to its own output, which means that a = b
- this makes the final signature (a -> a) -> a -> a
这篇关于如何定义此功能的类型配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!