diff options
author | Tom Smeding <t.j.smeding@uu.nl> | 2025-03-07 15:11:59 +0100 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2025-03-14 15:37:29 +0100 |
commit | 137eaa13144c2599ac29da9ebd3af24ac1ce8968 (patch) | |
tree | 8fc5221824f671dfc27f8064e3fc537859bb73e8 /src/AST/Accum.hs | |
parent | 1abb0c11efd2ba650c0a20de8047efbde2cc6adf (diff) |
WIP revamp accumulator projection type repr
I stopped working on this because I realised that having sparse products
(and coproducts, prehaps) everywhere is a very bad idea in general, and
that we need to fix that first before really being able to do anything
else productive with performance.
Diffstat (limited to 'src/AST/Accum.hs')
-rw-r--r-- | src/AST/Accum.hs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/AST/Accum.hs b/src/AST/Accum.hs new file mode 100644 index 0000000..163f1c3 --- /dev/null +++ b/src/AST/Accum.hs @@ -0,0 +1,44 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE KindSignatures #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE UndecidableInstances #-} +module AST.Accum where + +import AST.Types +import Data + + +data AcPrj + = APHere + | APFst AcPrj + | APSnd AcPrj + | APLeft AcPrj + | APRight AcPrj + | APJust AcPrj + | APArrIdx AcPrj + | APArrSlice Nat + +-- | @b@ is a small part of @a@, indicated by the projection. +data SAcPrj (p :: AcPrj) (a :: Ty) (b :: Ty) where + SAPHere :: SAcPrj APHere a a + SAPFst :: SAcPrj p a b -> SAcPrj (APFst p) (TPair t a) b + SAPSnd :: SAcPrj p a b -> SAcPrj (APSnd p) (TPair a t) b + SAPLeft :: SAcPrj p a b -> SAcPrj (APLeft p) (TEither t a) b + SAPRight :: SAcPrj p a b -> SAcPrj (APRight p) (TEither t a) b + SAPJust :: SAcPrj p a b -> SAcPrj (APJust p) (TMaybe t) b + SAPArrIdx :: SAcPrj p a b -> SNat n -> SAcPrj (APArrIdx p) (TArr n t) b + SAPArrSlice :: SNat m -> SAcPrj (APArrSlice m) (TArr n t) (TArr (n - m) t) +deriving instance Show (SAcPrj p a b) + +type family AcIdx p t where + AcIdx APHere t = TNil + AcIdx (APFst p) (TPair a b) = AcIdx p a + AcIdx (APSnd p) (TPair a b) = AcIdx p b + AcIdx (APLeft p) (TEither a b) = AcIdx p a + AcIdx (APRight p) (TEither a b) = AcIdx p b + AcIdx (APJust p) (TMaybe a) = AcIdx p a + AcIdx (APArrIdx p) (TArr n a) = TPair (Tup (Replicate n TIx)) (AcIdx p a) + AcIdx (APArrSlice m) (TArr n a) = Tup (Replicate m TIx) |