diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-05-04 16:41:56 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-05-04 16:41:56 +0200 |
commit | d09859323b7213d6b3c3baf485d8389100faf469 (patch) | |
tree | eda20598a3729354cd702e847d648dadfa3acf44 /lc | |
parent | 6066e1154af07dd27733343199fd51758fed6c52 (diff) |
implement constraint kinds
Diffstat (limited to 'lc')
-rw-r--r-- | lc/Builtins.lc | 6 | ||||
-rw-r--r-- | lc/Internals.lc | 32 | ||||
-rw-r--r-- | lc/Prelude.lc | 5 |
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 | ||
490 | type family ImageLC a :: Nat where ImageLC (Image n t) = n | 490 | type family ImageLC a :: Nat where ImageLC (Image n t) = n |
491 | 491 | ||
492 | allSame :: [a] -> Type | 492 | allSame :: [a] -> Constraint |
493 | allSame [] = 'Unit | 493 | allSame [] = 'CUnit |
494 | allSame [x] = 'Unit | 494 | allSame [x] = 'CUnit |
495 | allSame (x: y: xs) = 'T2 (x ~ y) (allSame (y:xs)) | 495 | allSame (x: y: xs) = 'T2 (x ~ y) (allSame (y:xs)) |
496 | 496 | ||
497 | sameLayerCounts a = allSame (map 'ImageLC a) | 497 | sameLayerCounts 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 | ||
19 | unsafeCoerce :: forall a b . a -> b | 19 | unsafeCoerce :: forall a b . a -> b |
20 | 20 | ||
21 | data Constraint where | ||
22 | CUnit :: Constraint | ||
23 | CEmpty :: String -> Constraint | ||
24 | |||
25 | type family CW (c :: Constraint) -- where | ||
26 | {- | ||
27 | CW 'CUnit = Unit | ||
28 | CW ('CEmpty s) = Empty s | ||
29 | -} | ||
21 | -- equality constraints | 30 | -- equality constraints |
22 | type family EqCT (t :: Type) (a :: t) (b :: t) | 31 | type family EqCT (t :: Type) (a :: t) (b :: t) :: Constraint |
23 | {- | 32 | {- |
24 | coe :: forall (a :: Type) (b :: Type) -> EqCT Type a b -> a -> b | 33 | coe :: forall (a :: Type) (b :: Type) -> EqCT Type a b -> a -> b |
25 | coe a b TT x = unsafeCoerce @a @b x | 34 | coe a b TT x = unsafeCoerce @a @b x |
@@ -31,7 +40,12 @@ coe a b TT x = unsafeCoerce @a @b x | |||
31 | parEval :: forall a -> a -> a -> a | 40 | parEval :: forall a -> a -> a -> a |
32 | 41 | ||
33 | -- conjuction of constraints | 42 | -- conjuction of constraints |
34 | type family T2 a b | 43 | type family T2 (x :: Constraint) (y :: Constraint) :: Constraint |
44 | {- | ||
45 | type instance T2 'CUnit c = c | ||
46 | type instance T2 c 'CUnit = c | ||
47 | type instance T2 ('CEmpty s) ('CEmpty s') = 'CEmpty (s {- ++ s' TODO-}) | ||
48 | -} | ||
35 | 49 | ||
36 | match'Type :: forall (m :: Type -> Type) -> m Type -> forall (t :: Type) -> m t -> m t | 50 | match'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 | ||
140 | hlistConsCase @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 | |||
146 | hlistNilCase 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 | |||
126 | data RecordC (xs :: [RecItem]) | 126 | data RecordC (xs :: [RecItem]) |
127 | = RecordCons (HList (map recItemType xs)) | 127 | = RecordCons (HList (map recItemType xs)) |
128 | 128 | ||
129 | isKeyC _ _ [] = 'Empty "" | 129 | isKeyC _ _ [] = 'CEmpty "" |
130 | isKeyC s t (RecItem s' t': ss) = if s == s' then t ~ t' else isKeyC s t ss | 130 | isKeyC s t (RecItem s' t': ss) = if s == s' then t ~ t' else isKeyC s t ss |
131 | 131 | ||
132 | fstTup = hlistConsCase _ (\a _ -> a) | 132 | fstTup = hlistConsCase _ (\a _ -> a) |
@@ -135,7 +135,7 @@ sndTup = hlistConsCase _ (\_ a -> a) | |||
135 | -- todo: don't use unsafeCoerce | 135 | -- todo: don't use unsafeCoerce |
136 | project :: forall a (xs :: [RecItem]) . forall (s :: String) -> isKeyC s a xs => RecordC xs -> a | 136 | project :: forall a (xs :: [RecItem]) . forall (s :: String) -> isKeyC s a xs => RecordC xs -> a |
137 | project @a @('RecItem s' a': xs) s @_ (RecordCons ts) | s == s' = fstTup (unsafeCoerce @_ @(HList '(a : map recItemType xs)) ts) | 137 | project @a @('RecItem s' a': xs) s @_ (RecordCons ts) | s == s' = fstTup (unsafeCoerce @_ @(HList '(a : map recItemType xs)) ts) |
138 | project @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))) | 138 | project @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 | |||