我怎么理解 "(.) .(.)"? [英] How can I understand "(.) . (.)"?
问题描述
我相信我理解 fmap .fmap
用于函子,但在函数上它已经让我头疼好几个月了.
I believe I understand fmap . fmap
for Functors, but on functions it's hurting my head for months now.
我已经看到您可以将 (.)
的定义应用于 (.) .(.)
,但我忘了怎么做.
当我自己尝试时,结果总是错的:
I've seen that you can just apply the definition of (.)
to (.) . (.)
, but I've forgot how to do that.
When I try it myself it always turns out wrong:
(.) f g = x -> f (g x)
(.) (.) (.) = x -> (.) ((.) x)
x f -> (.) ((.) x) f
x f y -> (((.)(f y)) x)
x f y g-> (((.)(f y) g) x)
x f y g-> ((f (g y)) x)
x f y g-> ((f (g y)) x):: t2 -> (t1 -> t2 -> t) -> t3 -> (t3 -> t1) -> t
如果只是应用定义"是唯一的方法,那么有人是怎么想出 (.) 的.(.)
?
我一定缺少一些更深层次的理解或直觉.
If "just applying the definition" is the only way of doing it, how did anybody come up with (.) . (.)
?
There must be some deeper understanding or intuition I'm missing.
推荐答案
你也可以使用你对 fmap 的理解.fmap
.
如果你有两个 Functor
s foo
和 bar
,那么
If you have two Functor
s foo
and bar
, then
fmap . fmap :: (a -> b) -> foo (bar a) -> foo (bar b)
fmap .fmap
接受一个函数,并为两个 Functor
的组合产生一个诱导函数.
fmap . fmap
takes a function and produces an induced function for the composition of the two Functor
s.
现在,对于任何类型 t
,(->) t
是一个 Functor
,而 fmap
> 对于那个 Functor
是 (.)
.
Now, for any type t
, (->) t
is a Functor
, and the fmap
for that Functor
is (.)
.
所以 (.) .(.)
是 fmap .fmap
对于两个 Functor
是 (->) s
和 (->) t
的情况,以及因此
So (.) . (.)
is fmap . fmap
for the case where the two Functor
s are (->) s
and (->) t
, and thus
(.) . (.) :: (a -> b) -> ((->) s) ((->) t a) -> ((->) s) ((->) t b)
= (a -> b) -> (s -> (t -> a)) -> (s -> (t -> b))
= (a -> b) -> (s -> t -> a ) -> (s -> t -> b )
它组合"了一个函数 f :: a ->b
带有两个参数的函数,g :: s ->t->一个
,
it "composes" a function f :: a -> b
with a function of two arguments, g :: s -> t -> a
,
((.) . (.)) f g = x y -> f (g x y)
该观点还清楚地表明,该模式以及如何扩展到采用更多参数的函数,
That view also makes it clear that, and how, the pattern extends to functions taking more arguments,
(.) :: (a -> b) -> (s -> a) -> (s -> b)
(.) . (.) :: (a -> b) -> (s -> t -> a) -> (s -> t -> b)
(.) . (.) . (.) :: (a -> b) -> (s -> t -> u -> a) -> (s -> t -> u -> b)
等
这篇关于我怎么理解 "(.) .(.)"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!