Skip to content

Instantly share code, notes, and snippets.

@cobalamin
Last active April 26, 2016 18:34
Show Gist options
  • Select an option

  • Save cobalamin/174f06e18b9886f9bd5ad0292b15b9b1 to your computer and use it in GitHub Desktop.

Select an option

Save cobalamin/174f06e18b9886f9bd5ad0292b15b9b1 to your computer and use it in GitHub Desktop.
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