https://github.com/wchresta/permonad
An indexed monad used to track permissions on aggregated data on the type level.
https://github.com/wchresta/permonad
Last synced: 3 months ago
JSON representation
An indexed monad used to track permissions on aggregated data on the type level.
- Host: GitHub
- URL: https://github.com/wchresta/permonad
- Owner: wchresta
- License: lgpl-3.0
- Created: 2018-07-26T13:58:10.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-26T14:16:22.000Z (almost 7 years ago)
- Last Synced: 2025-01-31T16:41:42.227Z (5 months ago)
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# perMonad
An indexed monad used to track permissions on aggregated data on the type level.# Idea
Use the `ixmonad` and `type-level-sets` libraries to build a permission monad.The idea is, to use a type-level set of type-level permissions to represent the permissions needed to get a value:
```Haskell
-- Perm is an effect that required permissions
-- n is a list of permissions
-- a is a value that is protected by the list of permissions
data Perm (Set (n :: [k])) (a :: *) = Value atype PersonId = Int
type PersonName = String
modifyPersonName :: (PersonName -> PersonName)
-> PersonId
-> Perm ('Set '[ 'Read 'PersonName, 'Write 'PersonName]) ()
```The unit after this map can only be extracted (and thus the effect executed) by code that has proof they have the neccessary permissions.
Importantly, this is implemented using an indexed monad, such that the programmer does not need to handle type level permissions themselves:
```Haskell
readFirstname :: PersonId -> Perm ('Set '[ 'Read 'PersonFirstname ]) String
readLastname :: PersonId -> Perm ('Set '[ 'Read 'PersonLastname ]) StringreadName :: PersonId -> Perm ('Set '[ 'Read 'PersonFirstname, 'Read 'PersonLastname ]) String
readName pid = do
firstname <- readFirstname pid
lastname <- readLastname pid
return $ firstname ++ " " ++ lastname
```Sadly, this also means that types are getting rather complicated; so most programmers are going to not write type signatures themselves.