Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Data/Set/Singletons.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ module Data.Set.Singletons ( IsSet
, asSet
, module Data.List.Singletons
, module Data.Ord.Singletons
, Union
) where

import Data.List.Singletons (Nub, SList, Sort, Union, sNub, sSort,
import Data.List.Singletons (Nub, SList, Sort, sNub, sSort,
sUnion, (%++))
import qualified Data.List.Singletons as S (Union)
import Data.Ord.Singletons (SOrd)

type IsSet a = (a ~ AsSet a)

type AsSet a = Nub (Sort a)

-- | We need unions to be sorted, which the default implementation
-- does not do.
type Union a b = Sort (S.Union a b)

-- TODO need to take care of the singled functions as well.

asSet :: (SOrd k) => SList (a :: [k]) -> SList (AsSet a)
asSet as = sNub $ sSort as
16 changes: 13 additions & 3 deletions src/System/OpenBSD/MultiPledge.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DerivingStrategies #-}
Expand All @@ -24,6 +25,8 @@ module System.OpenBSD.MultiPledge ( trivial
, (System.OpenBSD.MultiPledge.>>=)
, (System.OpenBSD.MultiPledge.>>)
, unpledge
, transPledge
, transPledge'
) where

import Data.Set.Singletons
Expand All @@ -34,7 +37,7 @@ import Control.Monad.IO.Class ()
import Control.Monad.IO.Unlift
import Control.Monad.Trans.Class (MonadTrans, lift)
import qualified Data.Set as S
import Data.Singletons (SingI, fromSing, sing)
import Data.Singletons (SingI, fromSing, sing, Sing)

-- | The wrapper for 'IO' actions
newtype Pledge
Expand Down Expand Up @@ -82,8 +85,8 @@ trivial = Pledge
getAction $ f a'

(>>) :: forall zs ps m qs a b.
( MonadIO m, SingI zs, SingI ps, SingI qs
)
( MonadIO m, SingI zs, SingI ps
, SingI qs)
=> Pledge (zs `Union` ps) qs m a
-> Pledge zs ps m b
-> Pledge zs (ps `Union` qs) m b
Expand Down Expand Up @@ -112,3 +115,10 @@ unpledge :: forall zs ps (m :: * -> *) a.
)
=> Pledge (zs `Union` ps) ps m a -> Pledge zs ps m a
unpledge a = a System.OpenBSD.MultiPledge.>>= (pure :: a -> Pledge zs ps m a)

transPledge :: Sing ps -> Pledge (zs `Union` ps) qs m a -> Pledge zs (ps `Union` qs) m a
transPledge = undefined

transPledge' :: (SingI ps, SingI (zs `Union` ps))
=> Pledge (zs `Union` ps) qs m a -> Pledge zs (ps `Union` qs) m a
transPledge' = Pledge . getAction