Skip to content

Instantly share code, notes, and snippets.

@jroesch
Created August 19, 2014 23:48
Show Gist options
  • Select an option

  • Save jroesch/5c470f299cfabf9746b5 to your computer and use it in GitHub Desktop.

Select an option

Save jroesch/5c470f299cfabf9746b5 to your computer and use it in GitHub Desktop.
data UnAuthErr = MkErr deriving (Eq, Show)
data Req = MkReq deriving (Eq, Show)
data Credentials = MkCredentials deriving (Eq, Show)
data Auth a = Error a
| Request Req a
| Auth Credentials a
deriving (Eq, Show)
instance Functor Auth where
fmap f (Error a) = Error (f a)
fmap f (Request Req a) = Req Req (f a)
fmap f (Auth creds a) = Auth Creds (f a)
onlyIfAuth :: Free Auth (Either UnAuthErr a) ->
onlyIfAuth = iterM $ \auth ->
-- interpret here
tryMe = onlyIfAuth someFreeTerm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment