Skip to content

Commit

Permalink
membership predicate for sets, and generalise sets to arbitrary kind
Browse files Browse the repository at this point in the history
  • Loading branch information
dorchard committed Jan 11, 2018
1 parent 28fe8b8 commit 850dd32
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Data/Type/Map.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class IsMember v t m where
instance {-# OVERLAPS #-} IsMember v t ((v ':-> t) ': m) where
lookp _ (Ext _ x _) = x

instance IsMember v t m => IsMember v t (x ': m) where
instance {-# OVERLAPPABLE #-} IsMember v t m => IsMember v t (x ': m) where
lookp v (Ext _ _ m) = lookp v m


Expand Down
16 changes: 14 additions & 2 deletions src/Data/Type/Set.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
module Data.Type.Set (Set(..), Union, Unionable, union, quicksort, append,
Sort, Sortable, (:++), Split(..), Cmp, Filter, Flag(..),
Nub, Nubable(..), AsSet, asSet, IsSet, Subset(..),
Delete(..), Proxy(..), remove, Remove, (:\)) where
Delete(..), Proxy(..), remove, Remove, (:\),
Member) where

import GHC.TypeLits
import Data.Type.Bool
Expand All @@ -15,7 +16,7 @@ import Data.Type.Equality
data Proxy (p :: k) = Proxy

-- Value-level 'Set' representation, essentially a list
data Set (n :: [*]) where
data Set (n :: [k]) :: * where
{--| Construct an empty set -}
Empty :: Set '[]
{--| Extend a set with an element -}
Expand Down Expand Up @@ -215,3 +216,14 @@ instance Conder False where
{-| Open-family for the ordering operation in the sort -}

type family Cmp (a :: k) (b :: k) :: Ordering

{-| Membership of an element in a set, with an acommanying
value-level function that returns a bool -}
class Member a s where
member :: Proxy a -> Set s -> Bool

instance {-# OVERLAPS #-} Member a (a ': s) where
member _ (Ext x _) = True

instance {-# OVERLAPPABLE #-} Member a s => Member a (b ': s) where
member a (Ext _ xs) = member a xs
2 changes: 1 addition & 1 deletion type-level-sets.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: type-level-sets
version: 0.8.6.0
version: 0.8.7.0
synopsis: Type-level sets and finite maps (with value-level counterparts)
description:
This package provides type-level sets (no duplicates, sorted to provide a normal form) via 'Set' and type-level
Expand Down

0 comments on commit 850dd32

Please sign in to comment.