git.iko.soy/type-level-sets
on master help sign in
change the modularisation for nub; better documentatioN
commitda03b6405ba7567b6eeb68a75e8aaa43a98c417c authorDominic Orchard <dom.orchard@gmail.com> dateThu 11 Sep 2014, 15:18 (12 years ago) parent0466aa7
3 files changed+10−10
README+1−1 example.hs+5−7 src/Data/Type/Set.hs+4−2
README+1−1
@@ -3,7 +3,7 @@ subsets, and split sets. Also included is a "mapping" type constructor that pair
33sets of variable-type pairs, which is used in the paper "Embedding effect systems in Haskell" (Dominic Orchard,
44Tomas Petricek <http://www.cl.cam.ac.uk/~dao29/publ/haskell14-effects.pdf>) to embed effect sets.
55
6−A full example can be seen in 'example.hs'. Here is a shorter version:
6+The following shows an example:
77
88 {-# LANGUAGE DataKinds, TypeOperators #-}
99
example.hs+5−7
@@ -1,20 +1,18 @@
1−{-# LANGUAGE DataKinds, TypeOperators, FlexibleInstances, FlexibleContexts, GADTs #-}
1+{-# LANGUAGE DataKinds, TypeOperators #-}
22
33import Data.Type.Set
44
5−instance Nubable ((v :-> a) ': s) => Nubable ((v :-> a) ': (v :-> a) ': s) where
6− nub (Ext _ (Ext x xs)) = nub (Ext x xs)
7−
8−foo :: Set '["x" :-> Integer, "z" :-> Integer, "w" :-> Integer]
5+foo :: Set '["x" :-> Int, "z" :-> Int, "w" :-> Int]
96foo = Ext ((Var :: (Var "x")) :-> 2) $
107 Ext ((Var :: (Var "z")) :-> 4) $
118 Ext ((Var :: (Var "w")) :-> 5) $
129 Empty
1310
14−bar :: Set '["y" :-> Integer, "w" :-> Integer]
11+bar :: Set '["y" :-> Int, "w" :-> Int]
1512bar = Ext ((Var :: (Var "y")) :-> 3) $
1613 Ext ((Var :: (Var "w")) :-> 1) $
1714 Empty
1815
19−foobar :: Set '["w" :-> Integer, "x" :-> Integer, "y" :-> Integer, "z" :-> Integer]
16+-- GHC can easily infer this type, so an explicit signature not necessary
17+-- foobar :: Set '["w" :-> Int, "x" :-> Int, "y" :-> Integer, "z" :-> Int]
2018foobar = foo `union` bar
src/Data/Type/Set.hs+4−2
@@ -1,7 +1,6 @@
11{-# LANGUAGE GADTs, DataKinds, KindSignatures, TypeOperators, TypeFamilies,
22 MultiParamTypeClasses, FlexibleInstances, PolyKinds, FlexibleContexts,
3− UndecidableInstances, ConstraintKinds, OverlappingInstances, ScopedTypeVariables,
4− AllowAmbiguousTypes #-}
3+ UndecidableInstances, ConstraintKinds, OverlappingInstances, ScopedTypeVariables #-}
54
65module Data.Type.Set (Set(..), Union, Unionable, union, quicksort, append,
76 Sort, Sortable, Append(..), Split(..), Cmp,
@@ -111,6 +110,9 @@ instance Nubable '[] where
111110instance Nubable '[e] where
112111 nub (Ext x Empty) = Ext x Empty
113112
113+instance Nubable (e ': s) => Nubable (e ': e ': s) where
114+ nub (Ext _ (Ext e s)) = nub (Ext e s)
115+
114116instance (Nub (e ': f ': s) ~ (e ': Nub (f ': s)),
115117 Nubable (f ': s)) => Nubable (e ': f ': s) where
116118 nub (Ext e (Ext f s)) = Ext e (nub (Ext f s))