Skip to content

Instantly share code, notes, and snippets.

@rahcola
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahcola/1aca91bf835a7b3e7bb8 to your computer and use it in GitHub Desktop.
Save rahcola/1aca91bf835a7b3e7bb8 to your computer and use it in GitHub Desktop.
type bondage
data ResourceId a = ResourceId Integer
data Image
data User
data Authorized a b = Authorized (ResourceId a)
data Create
data Read
data Update
data Delete
authorizeRead :: (ResourceId a)
-> (ResourceId User)
-> Authorized (ResourceId a) Main.Read
authorizeRead resourceId userId = undefined
readResource :: Authorized (ResourceId a) Main.Read
-> EitherT Text IO a
readResource (Authorized id) = undefined
deleteResource :: Authorized (ResourceId a) Delete
-> EitherT Text IO ()
deleteResource (Authorized id) = undefined
readImage :: (ResourceId Image)
-> (ResourceId User)
-> EitherT Text IO Image
readImage imageId userId = readResource $ authorizeRead imageId userId
-- this won't type check
deleteImage :: (ResourceId Image)
-> (ResourceId User)
-> EitherT Text IO ()
deleteImage imageId userId = deleteResource $ authorizeRead imageId userId
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment