Created
March 10, 2017 00:49
-
-
Save derekmorr/e9ffb0abe0bfe4761b592457567c3e2b to your computer and use it in GitHub Desktop.
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 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