Skip to content

Instantly share code, notes, and snippets.

@reinh
Created September 25, 2012 18:42
Show Gist options
  • Save reinh/3783635 to your computer and use it in GitHub Desktop.
Save reinh/3783635 to your computer and use it in GitHub Desktop.
import Control.Monad
import Control.Monad.Instances
palindrome :: String -> Bool
palindrome = ap (==) reverse
palindrome "radar" --> True
@reinh
Copy link
Author

reinh commented Sep 25, 2012

ap for the instance (-> r) (the function monad) is:

ap g f r = g r (f r)

@KirinDave
Copy link

The function monad is funny. Maybe it's just that I don't work with it too much, but I always find it sort of unpredictable compared to the other monads. Contrast this to, say, the Arrow definition for functions which almost always seems to make code clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment