summaryrefslogtreecommitdiff
path: root/lc
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-05-04 16:41:56 +0200
committerPéter Diviánszky <divipp@gmail.com>2016-05-04 16:41:56 +0200
commitd09859323b7213d6b3c3baf485d8389100faf469 (patch)
treeeda20598a3729354cd702e847d648dadfa3acf44 /lc
parent6066e1154af07dd27733343199fd51758fed6c52 (diff)
implement constraint kinds
Diffstat (limited to 'lc')
-rw-r--r--lc/Builtins.lc6
-rw-r--r--lc/Internals.lc32
-rw-r--r--lc/Prelude.lc5
3 files changed, 21 insertions, 22 deletions
diff --git a/lc/Builtins.lc b/lc/Builtins.lc
index 0ff2f3b1..03970dbd 100644
--- a/lc/Builtins.lc
+++ b/lc/Builtins.lc
@@ -489,9 +489,9 @@ rasterizePrimitives ctx is s = concat (map (rasterizePrimitive is ctx) s)
489 489
490type family ImageLC a :: Nat where ImageLC (Image n t) = n 490type family ImageLC a :: Nat where ImageLC (Image n t) = n
491 491
492allSame :: [a] -> Type 492allSame :: [a] -> Constraint
493allSame [] = 'Unit 493allSame [] = 'CUnit
494allSame [x] = 'Unit 494allSame [x] = 'CUnit
495allSame (x: y: xs) = 'T2 (x ~ y) (allSame (y:xs)) 495allSame (x: y: xs) = 'T2 (x ~ y) (allSame (y:xs))
496 496
497sameLayerCounts a = allSame (map 'ImageLC a) 497sameLayerCounts a = allSame (map 'ImageLC a)
diff --git a/lc/Internals.lc b/lc/Internals.lc
index 170f2c39..d8a08a33 100644
--- a/lc/Internals.lc
+++ b/lc/Internals.lc
@@ -18,8 +18,17 @@ data Empty (a :: String)
18 18
19unsafeCoerce :: forall a b . a -> b 19unsafeCoerce :: forall a b . a -> b
20 20
21data Constraint where
22 CUnit :: Constraint
23 CEmpty :: String -> Constraint
24
25type family CW (c :: Constraint) -- where
26{-
27 CW 'CUnit = Unit
28 CW ('CEmpty s) = Empty s
29-}
21-- equality constraints 30-- equality constraints
22type family EqCT (t :: Type) (a :: t) (b :: t) 31type family EqCT (t :: Type) (a :: t) (b :: t) :: Constraint
23{- 32{-
24coe :: forall (a :: Type) (b :: Type) -> EqCT Type a b -> a -> b 33coe :: forall (a :: Type) (b :: Type) -> EqCT Type a b -> a -> b
25coe a b TT x = unsafeCoerce @a @b x 34coe a b TT x = unsafeCoerce @a @b x
@@ -31,7 +40,12 @@ coe a b TT x = unsafeCoerce @a @b x
31parEval :: forall a -> a -> a -> a 40parEval :: forall a -> a -> a -> a
32 41
33-- conjuction of constraints 42-- conjuction of constraints
34type family T2 a b 43type family T2 (x :: Constraint) (y :: Constraint) :: Constraint
44{-
45type instance T2 'CUnit c = c
46type instance T2 c 'CUnit = c
47type instance T2 ('CEmpty s) ('CEmpty s') = 'CEmpty (s {- ++ s' TODO-})
48-}
35 49
36match'Type :: forall (m :: Type -> Type) -> m Type -> forall (t :: Type) -> m t -> m t 50match'Type :: forall (m :: Type -> Type) -> m Type -> forall (t :: Type) -> m t -> m t
37 51
@@ -136,18 +150,4 @@ hlistConsCase
136 -> c 150 -> c
137 151
138{- 152{-
139-- TODO: unsafeCoerce is not really needed here
140hlistConsCase @e @f c fv x = 'HListCase
141 (\_ _ -> c)
142 undefined
143 (\ @t @lt y ys -> fv (unsafeCoerce @t @e y) (unsafeCoerce @(HList lt) @(HList f) ys))
144 x
145
146hlistNilCase c x v = 'HListCase
147 (\_ _ -> c)
148 x
149 (\_ _ -> undefined :: c)
150 v
151-} 153-}
152
153
diff --git a/lc/Prelude.lc b/lc/Prelude.lc
index aa065096..5446df0d 100644
--- a/lc/Prelude.lc
+++ b/lc/Prelude.lc
@@ -126,7 +126,7 @@ recItemType (RecItem _ t) = t
126data RecordC (xs :: [RecItem]) 126data RecordC (xs :: [RecItem])
127 = RecordCons (HList (map recItemType xs)) 127 = RecordCons (HList (map recItemType xs))
128 128
129isKeyC _ _ [] = 'Empty "" 129isKeyC _ _ [] = 'CEmpty ""
130isKeyC s t (RecItem s' t': ss) = if s == s' then t ~ t' else isKeyC s t ss 130isKeyC s t (RecItem s' t': ss) = if s == s' then t ~ t' else isKeyC s t ss
131 131
132fstTup = hlistConsCase _ (\a _ -> a) 132fstTup = hlistConsCase _ (\a _ -> a)
@@ -135,7 +135,7 @@ sndTup = hlistConsCase _ (\_ a -> a)
135-- todo: don't use unsafeCoerce 135-- todo: don't use unsafeCoerce
136project :: forall a (xs :: [RecItem]) . forall (s :: String) -> isKeyC s a xs => RecordC xs -> a 136project :: forall a (xs :: [RecItem]) . forall (s :: String) -> isKeyC s a xs => RecordC xs -> a
137project @a @('RecItem s' a': xs) s @_ (RecordCons ts) | s == s' = fstTup (unsafeCoerce @_ @(HList '(a : map recItemType xs)) ts) 137project @a @('RecItem s' a': xs) s @_ (RecordCons ts) | s == s' = fstTup (unsafeCoerce @_ @(HList '(a : map recItemType xs)) ts)
138project @a @('RecItem s' a': xs) s @_ (RecordCons ts) = project @a @xs s @(undefined @(isKeyC s a xs)) (RecordCons (sndTup (unsafeCoerce @_ @(HList '(a : map recItemType xs)) ts))) 138project @a @('RecItem s' a': xs) s @_ (RecordCons ts) = project @a @xs s @(undefined @(CW (isKeyC s a xs))) (RecordCons (sndTup (unsafeCoerce @_ @(HList '(a : map recItemType xs)) ts)))
139 139
140--------------------------------------- HTML colors 140--------------------------------------- HTML colors
141 141
@@ -388,4 +388,3 @@ fromTo a b
388(x : _) !! 0 = x 388(x : _) !! 0 = x
389(_ : xs) !! n = xs !! (n-1) 389(_ : xs) !! n = xs !! (n-1)
390 390
391