git.iko.soy/type-level-sets
on master help sign in
Merge pull request #3 from k-bx/delete-operation

Add Delete operation to delete element from Set

commit06a568402d2ee6fe26a102d3e0e6ed9c7aec85fb authorDominic Orchard <dom.orchard@gmail.com> dateMon 19 Oct 2015, 12:00 (11 years ago) parent9fbdaa362c25fd
4 files changed+42−3
.gitignore+1 src/Data/Type/Set.hs+11−2 stack.yaml+29 type-level-sets.cabal+1−1
.gitignorenew file+1
@@ -0,0 +1 @@
1+.stack-work
src/Data/Type/Set.hs+11−2
@@ -1,11 +1,11 @@
11{-# LANGUAGE GADTs, DataKinds, KindSignatures, TypeOperators, TypeFamilies,
22 MultiParamTypeClasses, FlexibleInstances, PolyKinds, FlexibleContexts,
3− UndecidableInstances, ConstraintKinds, OverlappingInstances, ScopedTypeVariables #-}
3+ UndecidableInstances, ConstraintKinds, ScopedTypeVariables #-}
44
55module Data.Type.Set (Set(..), Union, Unionable, union, quicksort, append,
66 Sort, Sortable, Append(..), Split(..), Cmp,
77 Nub, Nubable(..), AsSet, asSet, IsSet, Subset(..),
8− (:->)(..), Var(..)) where
8+ (:->)(..), Var(..), Delete(..)) where
99
1010import GHC.TypeLits
1111import Data.Type.Bool
@@ -144,6 +144,15 @@ type family Filter (f :: Flag) (p :: k) (xs :: [k]) :: [k] where
144144 Filter FMin p (x ': xs) = If (Cmp x p == LT) (x ': (Filter FMin p xs)) (Filter FMin p xs)
145145 Filter FMax p (x ': xs) = If (Cmp x p == GT || Cmp x p == EQ) (x ': (Filter FMax p xs)) (Filter FMax p xs)
146146
147+type family DeleteFromList (e :: elem) (list :: [elem]) where
148+ DeleteFromList elem '[] = '[]
149+ DeleteFromList elem (x ': xs) = If (Cmp elem x == EQ)
150+ xs
151+ (x ': DeleteFromList elem xs)
152+
153+type family Delete elem set where
154+ Delete elem (Set xs) = Set (DeleteFromList elem xs)
155+
147156{-| Value-level quick sort that respects the type-level ordering -}
148157class Sortable xs where
149158 quicksort :: Set xs -> Set (Sort xs)
stack.yamlnew file+29
@@ -0,0 +1,29 @@
1+# For more information, see: https://github.com/commercialhaskell/stack/wiki/stack.yaml
2+
3+# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
4+resolver: lts-3.5
5+
6+# Local packages, usually specified by relative directory name
7+packages:
8+- '.'
9+
10+# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)
11+extra-deps: []
12+
13+# Override default flag values for local packages and extra-deps
14+flags: {}
15+
16+# Control whether we use the GHC we find on the path
17+# system-ghc: true
18+
19+# Require a specific version of stack, using version ranges
20+# require-stack-version: -any # Default
21+# require-stack-version: >= 0.1.4.0
22+
23+# Override the architecture used by stack, especially useful on Windows
24+# arch: i386
25+# arch: x86_64
26+
27+# Extra directories used by stack for building
28+# extra-include-dirs: [/path/to/dir]
29+# extra-lib-dirs: [/path/to/dir]
type-level-sets.cabal+1−1
@@ -1,5 +1,5 @@
11name: type-level-sets
2−version: 0.5
2+version: 0.5.1
33synopsis: Type-level sets (with value-level counterparts and various operations)
44description:
55 This package provides type-level sets (no duplicates, sorted to provide a nomral form) via 'Set',