如何派生(。)。(。)的类型 [英] How to derive the type of (.).(.)

查看:97
本文介绍了如何派生(。)。(。)的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(。)。(。) -

  Prelude> :((。)。(。))
((。)。(。))::(b - > c) - > (a→a1→b)→> a - > a1 - > c。b $ b

这就是我的想法:假设(。)。(。)带有两个参数A和B ,那么

 (。)。(。)AB =(。)。(AB)

并且假设上面有另一个参数C -

 < (。)。(AB)C)(。)((AB)C)



< ($)$($)$($)$($)$($)$($) ).D



其中D,A,B,AB和((AB)C)是返回)函数,以及 -

  D :: a  - > b 
(A.B)C :: b - > c
A.B :: d - > b - > c
A :: e - > b - > c
B :: d - > e。b $ b C :: d

so(。)。(。):: A - > B - > C - > D变成 -

 (。)。(。)::(e  - > b - > c) - > (d  - > e) - > d  - > a  - > b 

距离正确的类型签名只有短短的几年。

什么是适当的推导和我的步骤有什么问题? 三个点的顺序是错误的。

J。 Abrahamson的答案很好,但我不完全按照他的步骤 -

 ((。)(。)(。)::(b'' (a' - > b') - >(a' - > c'))
^^^^^^^^^^^ ^^ ^^^^^^^^

由于他混合了第一和第二



我认为我已经在我的原创思路之后得到了答案 -


$ (。)(。)A =(。)((。)A))==>添加arg B ==> (。)((。)A))B =((。)A).B ==>
add arg C ==> ((。)A).B C =((。)A)(B C)==>添加arg D ==> ((。)A)(BC)D



其中A,((。)A),( BC)是函数 -

  let A :: b  - > ((。)A)::(a  - > b) - > a  - > c 
所以B C :: a - > b
B :: a1 - > a - > b
C :: a1
D :: a

和(。) (。)ABCD扩展为 -

 (。)。(。)::(b  - > c) - > (a1-> a-> b)→> a1  - > a  - > c 


Haskell beginner here having problem deriving the type of (.).(.) --

Prelude> :t ((.).(.))
((.).(.)) :: (b -> c) -> (a -> a1 -> b) -> a -> a1 -> c

This is how I think: suppose (.).(.) takes two arguments A and B, then

(.).(.) A B = (.).(A.B)

and suppose the above takes another argument C --

(.).(A.B) C = (.)((A.B) C)

adding argument D to the above --

(.)((A.B) C) D = ((A.B) C).D

where D, A, B, A.B, and ((A.B) C) are(return) functions, and --

D :: a -> b
(A.B) C :: b -> c
A.B :: d -> b -> c
A :: e -> b -> c
B :: d -> e
C :: d

so (.).(.) :: A -> B -> C -> D becomes --

(.).(.) :: (e -> b -> c) -> (d -> e) -> d -> a -> b

which is light years away from the correct type signature.

What's the proper derivation and what's wrong in my steps?

解决方案

It seems my error comes from applying the three dots in the wrong order.

J. Abrahamson's answer is great, but I'm not exactly following his step --

((.) (.) (.) :: (b'' -> c'') -> (a' -> b') -> (a' -> c'))
                ^^^^^^^^^^^^    ^^^^^^^^^^ 

due to the way his "mixes" up the first and second arguments from the second and the third dot type.

I think I've got the answer following my original track of thoughts --

(.).(.) A = (.)((.) A)) ==> add arg B ==> (.)((.) A)) B = ((.) A).B ==>
add arg C ==> ((.) A).B C = ((.) A)(B C) ==> add arg D ==> ((.) A)(B C) D

where A, ((.) A), (B C) are functions --

let A :: b -> c
then ((.) A) :: (a -> b) -> a -> c
so B C :: a -> b
B :: a1 -> a -> b
C :: a1
D :: a

and (.).(.) A B C D expands to --

(.).(.) :: (b -> c) -> (a1 -> a -> b) -> a1 -> a -> c

这篇关于如何派生(。)。(。)的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆