Here is a higher-order function that applies an argument to a given function twice:
dapp :: (a -> a -> a) -> a -> a
dapp = \f x -> f x x
ghci> dapp (*) 5
25
Can we make that shorter? Let's ask lambdabot:
lambdabot> @pl \f x -> f x x
join
Hooray! Let's try it out:
import Control.Monad (join)
dapp :: (a -> a -> a) -> a -> a
dapp = join
But it doesn't work :(
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
Why does this happen? Am I importing the wrong join
? I couldn't find another join
on Hoogle.
Until recently, the Functor
and Monad
instances for (->) r
were orphan instances in Control.Monad.Instances
.
However, starting from base-4.6.0.0
(GHC 7.6.1), these instances have been moved to the Prelude and the (now empty) Control.Monad.Instances
has been deprecated.
So to use these instances, either import Control.Monad.Instances
or upgrade your GHC.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With