Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Quine: "ap" Monad

What is the proper way to use the "ap" monad in Haskell? I want to do something similar to this:

main = (putStr . ap (++) show) "main = (putStr . ap (++) show) "

but I get the error "Not in scope: 'ap'."

Using "import Control.Monad" does nothing. And I have tried giving it

"ap :: Monad m => m (a -> b) -> m a -> m b" 

then I get "The type signature for `ap' lacks an accompanying binding"

like image 734
GossJ Avatar asked Apr 29 '13 17:04

GossJ


1 Answers

Importing Control.Monad should give you ap. However, in all but the most recent versions of GHC (7.6.1 and newer), you'll also need to import Control.Monad.Instances to use the monad instance for functions.

Alternatively, you can import Control.Applicative which gives you the <*> operator, which is ap generalized to Applicative, as well as the necessary instances to use it with functions.

like image 69
hammar Avatar answered Oct 23 '22 08:10

hammar