Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell lambdabot建议加入,但它不';行不通_Haskell_Join_Monads_Higher Order Functions_Lambdabot - Fatal编程技术网

Haskell lambdabot建议加入,但它不';行不通

Haskell lambdabot建议加入,但它不';行不通,haskell,join,monads,higher-order-functions,lambdabot,Haskell,Join,Monads,Higher Order Functions,Lambdabot,下面是一个高阶函数,它将参数应用于给定函数两次: dapp :: (a -> a -> a) -> a -> a dapp = \f x -> f x x ghci> dapp (*) 5 25 我们能把它缩短一点吗?让我们问问兰博特: lambdabot> @pl \f x -> f x x join 万岁!让我们试一下: import Control.Monad (join) dapp :: (a -> a -> a) -&

下面是一个高阶函数,它将参数应用于给定函数两次:

dapp :: (a -> a -> a) -> a -> a
dapp = \f x -> f x x

ghci> dapp (*) 5
25
我们能把它缩短一点吗?让我们问问兰博特:

lambdabot> @pl \f x -> f x x
join
万岁!让我们试一下:

import Control.Monad (join)

dapp :: (a -> a -> a) -> a -> a
dapp = join
但它不起作用:(

为什么会发生这种情况?我是否导入了错误的
join
?我在Hoogle上找不到另一个
join

(>)r
Functor
Monad
实例在
控件中。Monad.instances

但是,从
base-4.6.0.0
(GHC 7.6.1)开始,这些实例已移动到前奏和(现在为空)
控件.Monad.instances


所以要使用这些实例,要么导入
Control.Monad.instances
,要么升级您的GHC。

只要导入
Control.Monad.instances
-我想那个实例就在那里。@Thomas我怎么才能有选择地只导入
Monad((->)r)
instance?@freduisson您不能有选择地导入实例。您可以
导入Control.Monad.instances()
,它将导入所有实例,而不会导入其他任何实例。@ThomasM.DuBuisson:我也没有。由于某种原因,在中没有提到这一点。
No instance for (Monad ((->) a))
  arising from a use of `join'
Possible fix: add an instance declaration for (Monad ((->) a))
In the expression: join
In an equation for `dapp': dapp = join