Last active
April 26, 2016 18:34
-
-
Save cobalamin/174f06e18b9886f9bd5ad0292b15b9b1 to your computer and use it in GitHub Desktop.
NoopMonad (https://jazzy.id.au/2015/04/01/noop-monad.html)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Noop ( | |
| Noop(..), | |
| noop | |
| ) where | |
| -- Groundbreaking work to do nothing safely | |
| import Control.Applicative | |
| import Control.Monad | |
| newtype Noop a = Noop { runNoop :: a -> () } | |
| noop :: Noop a | |
| noop = Noop $ const () | |
| instance Eq (Noop a) where | |
| (==) _ _ = True | |
| instance Ord (Noop a) where | |
| compare _ _ = EQ | |
| instance Enum (Noop a) where | |
| fromEnum _ = 0 | |
| toEnum _ = noop | |
| instance Bounded (Noop a) where | |
| minBound = noop | |
| maxBound = noop | |
| instance Read (Noop a) where | |
| readsPrec _ s = [(noop , "")] | |
| instance Show (Noop a) where | |
| show _ = "<noop>" | |
| instance Monoid (Noop a) where | |
| mempty = noop | |
| mappend _ _ = noop | |
| instance Alternative Noop where | |
| empty = mempty | |
| (<|>) = mappend | |
| instance MonadPlus Noop where | |
| mzero = mempty | |
| mplus = mappend | |
| instance Functor Noop where | |
| fmap _ _ = noop | |
| {-# INLINE fmap #-} | |
| instance Applicative Noop where | |
| pure _ = noop | |
| {-# INLINE pure #-} | |
| _ <*> _ = noop | |
| {-# INLINE (<*>) #-} | |
| instance Monad Noop where | |
| return = pure | |
| {-# INLINE return #-} | |
| _ >>= _ = noop | |
| {-# INLINE (>>=) #-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment