Skip to content

Commit

Permalink
add role annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin committed Mar 1, 2024
1 parent 51f0f7a commit 7a55e2f
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.stack-work
/dist-newstyle
*.graphula
test.db
95 changes: 73 additions & 22 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions graphula.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.36.0.
--
-- see: https://github.com/sol/hpack
--
-- hash: 77f36204ab2afc392bf0f4eb7413aaf8ff36c25b86f28dde5747f3ed9121f0d4

name: graphula
version: 2.1.0.0
Expand Down Expand Up @@ -46,6 +44,8 @@ library
Paths_graphula
hs-source-dirs:
src
default-extensions:
RoleAnnotations
ghc-options: -Weverything -Wno-all-missed-specialisations -Wno-implicit-prelude -Wno-missing-import-lists -Wno-safe -Wno-unsafe
build-depends:
HUnit
Expand Down Expand Up @@ -77,6 +77,8 @@ test-suite readme
Paths_graphula
hs-source-dirs:
test
default-extensions:
RoleAnnotations
ghc-options: -Weverything -Wno-all-missed-specialisations -Wno-implicit-prelude -Wno-missing-import-lists -Wno-safe -Wno-unsafe -pgmL markdown-unlit
build-depends:
QuickCheck
Expand Down
3 changes: 3 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ when:
dependencies:
- base < 5

default-extensions:
- RoleAnnotations

library:
source-dirs:
- src
Expand Down
6 changes: 6 additions & 0 deletions src/Graphula.hs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,18 @@ data Args backend n m = Args
, gen :: IORef QCGen
}

type role Args representational representational representational

newtype RunDB backend n m = RunDB (forall b. ReaderT backend n b -> m b)

type role RunDB representational representational representational

newtype GraphulaT n m a = GraphulaT {runGraphulaT' :: ReaderT (Args SqlBackend n m) m a}
deriving newtype
(Functor, Applicative, Monad, MonadIO, MonadReader (Args SqlBackend n m))

type role GraphulaT representational representational nominal

instance MonadTrans (GraphulaT n) where
lift = GraphulaT . lift

Expand Down
6 changes: 6 additions & 0 deletions src/Graphula/Dependencies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class HasDependencies a where
newtype Only a = Only {fromOnly :: a}
deriving stock (Eq, Show, Ord, Generic, Functor, Foldable, Traversable)

type role Only representational

only :: a -> Only a
only = Only

Expand All @@ -142,8 +144,12 @@ data KeySourceType

newtype Required a = Required a

type role Required representational

newtype Optional a = Optional (Maybe a)

type role Optional representational

-- | When a user of Graphula inserts, this wraps the key they provide.
-- For 'SourceExternal' a key is required; for others it's optional.
type family KeySourceTypeM (t :: KeySourceType) :: Type -> Type where
Expand Down
2 changes: 2 additions & 0 deletions src/Graphula/Dependencies/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ data Match t
= NoMatch t
| Match t

type role Match representational

type family DependenciesTypeInstance nodeTy depsTy where
DependenciesTypeInstance nodeTy depsTy =
'Text "‘type Dependencies "
Expand Down
2 changes: 2 additions & 0 deletions src/Graphula/Idempotent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ newtype GraphulaIdempotentT m a = GraphulaIdempotentT
, MonadReader (IORef (m ()))
)

type role GraphulaIdempotentT representational nominal

instance MonadUnliftIO m => MonadUnliftIO (GraphulaIdempotentT m) where
{-# INLINE withRunInIO #-}
withRunInIO inner = GraphulaIdempotentT $ withRunInIO $ \run ->
Expand Down
2 changes: 2 additions & 0 deletions src/Graphula/Logged.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ newtype GraphulaLoggedT m a = GraphulaLoggedT
, MonadReader (IORef (Seq Text))
)

type role GraphulaLoggedT representational nominal

instance MonadUnliftIO m => MonadUnliftIO (GraphulaLoggedT m) where
{-# INLINE withRunInIO #-}
withRunInIO inner =
Expand Down
4 changes: 4 additions & 0 deletions src/Graphula/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ newtype NodeOptions a = NodeOptions
}
deriving stock (Generic)

type role NodeOptions nominal

instance Semigroup (NodeOptions a) where
(<>) = gmappend
{-# INLINE (<>) #-}
Expand All @@ -80,6 +82,8 @@ instance Monoid (NodeOptions a) where
newtype Kendo m a = Kendo {appKendo :: a -> m a}
deriving stock (Generic)

type role Kendo representational nominal

instance Monad m => Semigroup (Kendo m a) where
Kendo f <> Kendo g = Kendo $ f <=< g
{-# INLINE (<>) #-}
Expand Down

0 comments on commit 7a55e2f

Please sign in to comment.