Skip to content

Instantly share code, notes, and snippets.

@derekmorr
Created March 10, 2017 00:49
Show Gist options
  • Save derekmorr/e9ffb0abe0bfe4761b592457567c3e2b to your computer and use it in GitHub Desktop.
Save derekmorr/e9ffb0abe0bfe4761b592457567c3e2b to your computer and use it in GitHub Desktop.
module Lib where
-- 18.7 Question 1
data Nope a = NopeDotJpg deriving (Eq, Show)
instance Functor Nope where
fmap _ NopeDotJpg = NopeDotJpg
instance Applicative Nope where
pure _ = NopeDotJpg
_ <*> _ = NopeDotJpg
instance Monad Nope where
return _ = NopeDotJpg
_ >>= _ = NopeDotJpg
-- Question 2
data PhhhbbtttEither b a = Left' a | Right' b deriving (Eq, Show)
instance Functor (PhhhbbtttEither x) where
fmap f (Left' a) = Left' (f a)
fmap _ (Right' b) = Right' b
instance Applicative (PhhhbbtttEither b) where
pure a = Left' a
Right' e <*> _ = Right' e
Left' f <*> a = fmap f a
instance Monad (PhhhbbtttEither b) where
return = pure
Left' l >>= f = f l
Right' r >>= _ = Right' r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment