Skip to content

Instantly share code, notes, and snippets.

@cutsea110
Created February 5, 2013 05:03
Show Gist options
  • Save cutsea110/4712287 to your computer and use it in GitHub Desktop.
Save cutsea110/4712287 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleInstances, ImplicitParams #-}
import Control.Monad
import Control.Applicative
instance (Monad m, Num b) => Num (a -> m b) where
a + b = liftM2 (+) <$> a <*> b
a * b = liftM2 (*) <$> a <*> b
negate a = liftM negate <$> a
abs a = liftM abs <$> a
signum a = liftM signum <$> a
fromInteger = const . return . fromInteger
main = print $ (m >>= 1) ()
where m = const 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment