git.iko.soy/type-level-sets
on master help sign in
set example
commit7556e5b8b2fc5e3f8e5f2629a1e7a22c0c8e4351 authordominic <dom.orchard@gmail.com> dateTue 23 Feb 2016, 15:33 (11 years ago) parent7a1030a
1 file changed+23
example-set.hs+23
example-set.hsnew file+23
@@ -0,0 +1,23 @@
1+{-# LANGUAGE DataKinds, KindSignatures, GADTs, TypeOperators, TypeFamilies, PolyKinds, EmptyDataDecls #-}
2+{-# OPTIONS_GHC -fplugin=TySet #-}
3+
4+import GHC.TypeLits
5+import TySet
6+
7+data Container (a :: *) where
8+ Empty :: Container (Set '[])
9+ Ext :: a -> Container (Set s) -> Container (Set (Union '[a] s))
10+
11+data Natural (a :: Nat) where
12+ Z :: Natural 0
13+ S :: Natural n -> Natural (n + 1)
14+
15+-- Should be typeable with the plugin
16+{-
17+foo :: Container (Set '[Natural 1, Natural 2, Natural 3])
18+foo = Ext (S $ S Z) (Ext (S Z) (Ext (S $ S $ S Z) Empty))
19+-}
20+
21+dup :: Container (Set s) -> Container (Set (Union s s))
22+dup Empty = Empty
23+dup (Ext x xs) = Ext x (Ext x (dup xs))