1 {-# LANGUAGE AllowAmbiguousTypes #-}
2 {-# LANGUAGE PolyKinds #-}
4 module Symantic.Typer.List where
6 import Data.Function (($), (.))
8 import Text.Show (Show (..))
9 import Prelude qualified
11 -- * Type family @(++)@
12 type family (++) xs ys where
15 (x ': xs) ++ ys = x ': xs ++ ys
19 data Len (xs :: [k]) where
21 LenS :: Len xs -> Len (x ': xs)
23 instance Show (Len vs) where
24 showsPrec _p = showsPrec 10 . intLen
26 addLen :: Len a -> Len b -> Len (a ++ b)
28 addLen (LenS a) b = LenS $ addLen a b
30 shiftLen :: forall t b a. Len a -> Len (a ++ b) -> Len (a ++ t ': b)
31 shiftLen LenZ b = LenS b
32 shiftLen (LenS a) (LenS b) = LenS $ shiftLen @t @b a b
34 intLen :: Len xs -> Int
37 go :: Int -> Len xs -> Int
39 go i (LenS l) = go (1 Prelude.+ i) l
42 class LenInj (vs :: [k]) where
44 instance LenInj '[] where
46 instance LenInj as => LenInj (a ': as) where