我用pointfree.io玩了一下,当我输入"\ x - > x*x"(又名方形函数)时,它输出了这个
join (*)
Run Code Online (Sandbox Code Playgroud)
我不知道这个,我在Hoogle上查了一下:
-- | The 'join' function is the conventional monad join operator. It
-- is used to remove one level of monadic structure, projecting its
-- bound argument into the outer level.
join :: (Monad m) => m (m a) -> m a
join x = x >>= id
Run Code Online (Sandbox Code Playgroud)
我不知道这是如何工作来创建一个返回其参数的平方的函数.任何的想法 ?
该((->)r)
类型使用以下实例定义形成monad
instance Monad ((->) r) where
f >>= k = \ r -> k (f r) r
Run Code Online (Sandbox Code Playgroud)
并join
具有以下定义
join x = x >>= id
Run Code Online (Sandbox Code Playgroud)
所以让我们开始填补内容.
join (*)
= (*) >>= id
= \r -> id ((*) r) r
= \r -> r * r
Run Code Online (Sandbox Code Playgroud)