commit c4b736c11576cb9fe36bea2cecfb1b4face4ffd2
parent 80b7f4b9b74bea444bd1cb5cd44d558a2c443f2a
Author: Robert Russell <robert@rr3.xyz>
Date: Sat, 28 Feb 2026 09:05:54 -0800
Add Kind and Repr modules
Diffstat:
2 files changed, 119 insertions(+), 0 deletions(-)
diff --git a/src/Lude/Kind.hs b/src/Lude/Kind.hs
@@ -0,0 +1,33 @@
+module Lude.Kind (
+ Constraint,
+ Type,
+ TypeL,
+ TypeU,
+ Kind,
+ Lev,
+) where
+
+import GHC.Exts (Constraint)
+import GHC.Exts qualified as GHC
+
+import Lude.Repr qualified as Repr
+
+-- TODO: CONSTRAINT
+
+--------------------------------------------------------------------------------
+
+type Type = GHC.TYPE
+type TypeL = Type Repr.BoxL
+type TypeU = Type Repr.BoxU
+
+-- | An alias for `TypeL`.
+type Kind = TypeL
+
+-- | Used to declare unlifted values at the top-level. For example, for any @r@,
+-- @A :: Type r@, and @bar :: A@:
+-- @
+-- foo :: Lev A
+-- foo = bar
+-- @
+type Lev :: forall r. Type r -> TypeL
+type Lev (a :: Type r) = (() :: Constraint) => a
diff --git a/src/Lude/Repr.hs b/src/Lude/Repr.hs
@@ -0,0 +1,86 @@
+module Lude.Repr (
+ Levity (..),
+ Repr,
+ Tuple,
+ Sum,
+ Box,
+ BoxL,
+ BoxU,
+ Addr,
+ Int,
+ Int8,
+ Int16,
+ Int32,
+ Int64,
+ Nat,
+ Nat8,
+ Nat16,
+ Nat32,
+ Nat64,
+ Flt32,
+ Flt64,
+) where
+
+import GHC.Exts (Levity (..))
+import GHC.Exts qualified as GHC
+
+-- TODO: SIMD
+
+--------------------------------------------------------------------------------
+
+type Repr = GHC.RuntimeRep
+
+type Tuple = GHC.TupleRep
+type Sum = GHC.SumRep
+type Box = GHC.BoxedRep
+type BoxL = GHC.BoxedRep Lifted
+type BoxU = GHC.BoxedRep Unlifted
+type Addr = GHC.AddrRep
+type Int = GHC.IntRep
+type Int8 = GHC.Int8Rep
+type Int16 = GHC.Int16Rep
+type Int32 = GHC.Int32Rep
+type Int64 = GHC.Int64Rep
+type Nat = GHC.WordRep
+type Nat8 = GHC.Word8Rep
+type Nat16 = GHC.Word16Rep
+type Nat32 = GHC.Word32Rep
+type Nat64 = GHC.Word64Rep
+type Flt32 = GHC.FloatRep
+type Flt64 = GHC.DoubleRep
+
+--------------------------------------------------------------------------------
+
+pattern Tuple :: [Repr] -> Repr
+pattern Tuple rs = GHC.TupleRep rs
+
+pattern Sum :: [Repr] -> Repr
+pattern Sum rs = GHC.SumRep rs
+
+pattern Box :: Levity -> Repr
+pattern Box l = GHC.BoxedRep l
+
+pattern BoxL, BoxU :: Repr
+pattern BoxL = Box Lifted
+pattern BoxU = Box Unlifted
+
+pattern Addr :: Repr
+pattern Addr = GHC.AddrRep
+
+pattern Int, Int8, Int16, Int32, Int64 :: Repr
+pattern Int = GHC.IntRep
+pattern Int8 = GHC.Int8Rep
+pattern Int16 = GHC.Int16Rep
+pattern Int32 = GHC.Int32Rep
+pattern Int64 = GHC.Int64Rep
+
+pattern Nat, Nat8, Nat16, Nat32, Nat64 :: Repr
+pattern Nat = GHC.WordRep
+pattern Nat8 = GHC.Word8Rep
+pattern Nat16 = GHC.Word16Rep
+pattern Nat32 = GHC.Word32Rep
+pattern Nat64 = GHC.Word64Rep
+
+pattern Flt32, Flt64 :: Repr
+pattern Flt32 = GHC.FloatRep
+pattern Flt64 = GHC.DoubleRep