lude

Haskell prelude alternative
git clone git://git.rr3.xyz/lude | git clone gits://git.rr3.xyz/lude
Log | Files | Refs | README | LICENSE

commit 3094cae6e65c32030842fef2c4ec768f8e9f0012
parent 096ca08e9ca3b8cc987fdb2d15f3bd2cad9f318d
Author: Robert Russell <robert@rr3.xyz>
Date:   Thu, 24 Sep 2026 10:41:58 -0700

Haskell: reorganize

Diffstat:
Msrc/Lude/Haskell.hs | 6++++--
Msrc/Lude/Haskell/BaseInterop.hs | 2+-
Msrc/Lude/Haskell/Category.hs | 3+--
Msrc/Lude/Haskell/Constraint.hs | 3+--
Asrc/Lude/Haskell/Core.hs | 37+++++++++++++++++++++++++++++++++++++
Msrc/Lude/Haskell/Defunctionalization.hs | 2+-
Msrc/Lude/Haskell/Functional.hs | 4++--
Msrc/Lude/Haskell/Generic.hs | 3+--
Dsrc/Lude/Haskell/Kind.hs | 36------------------------------------
Asrc/Lude/Haskell/List.hs | 7+++++++
Msrc/Lude/Haskell/Repr.hs | 117++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Msrc/Lude/Haskell/Type.hs | 3+--
Msrc/Lude/List.hs | 2+-
13 files changed, 125 insertions(+), 100 deletions(-)

diff --git a/src/Lude/Haskell.hs b/src/Lude/Haskell.hs @@ -1,3 +1,4 @@ +-- | Import Lude.Haskell.Repr qualified. module Lude.Haskell ( module X, ) where @@ -7,11 +8,12 @@ import GHC.Exts as X (IsList (..), IsString (..)) import Lude.Haskell.BaseInterop as X import Lude.Haskell.Category as X -- TODO: Probably hide some stuff from here. import Lude.Haskell.Constraint as X +import Lude.Haskell.Core as X import Lude.Haskell.Equality as X import Lude.Haskell.Functional as X import Lude.Haskell.Generic as X hiding (Rep, Rep1, from, from1, to, to1) -import Lude.Haskell.Kind as X -import Lude.Haskell.Repr as X (Repr) import Lude.Haskell.Type as X -- TODO: Data.Coerce + +-------------------------------------------------------------------------------- diff --git a/src/Lude/Haskell/BaseInterop.hs b/src/Lude/Haskell/BaseInterop.hs @@ -3,7 +3,7 @@ module Lude.Haskell.BaseInterop ( BaseInterop1 (..), ) where -import Lude.Haskell.Kind +import Lude.Haskell.Core import Lude.Haskell.Type -------------------------------------------------------------------------------- diff --git a/src/Lude/Haskell/Category.hs b/src/Lude/Haskell/Category.hs @@ -53,9 +53,8 @@ module Lude.Haskell.Category ( import GHC.Exts qualified as GHC import Lude.Haskell.Constraint +import Lude.Haskell.Core import Lude.Haskell.Functional -import Lude.Haskell.Kind -import Lude.Haskell.Repr import Lude.Haskell.Type -- NOTE: `Entailment`/`:-` is to `Constraint` what `Function`/`->` is to `Type`. diff --git a/src/Lude/Haskell/Constraint.hs b/src/Lude/Haskell/Constraint.hs @@ -10,8 +10,7 @@ module Lude.Haskell.Constraint ( import Data.Tuple.Experimental qualified as GHC import GHC.Exts qualified as GHC -import Lude.Haskell.Kind -import Lude.Haskell.Repr (Repr) +import Lude.Haskell.Core import Lude.Haskell.Repr qualified as Repr -- TODO: Delete Constraint1/Constraint2 in favor of Predicate/Relation? diff --git a/src/Lude/Haskell/Core.hs b/src/Lude/Haskell/Core.hs @@ -0,0 +1,37 @@ +module Lude.Haskell.Core ( + Repr, + KindOrType#, + KindOrType, + Kind, + Endo, + Biendo, +) where + +import GHC.Exts qualified as GHC + +-------------------------------------------------------------------------------- + +-- This is just so "kind-level primitives" (@Kind@, @Repr@, etc.) receive a +-- valid Lude signature in GHC diagnostic messages +type KIND = GHC.TYPE GHC.LiftedRep + +type Repr :: KIND +type Repr = GHC.RuntimeRep + +-- NOTE: We typically avoid conflating types and kinds for clarity, +-- but when we do conflate them, we use KindOrType. + +type KindOrType# :: Repr -> KIND +type KindOrType# = GHC.TYPE + +type KindOrType :: KIND +type KindOrType = KindOrType# GHC.LiftedRep + +type Kind :: KIND +type Kind = KindOrType + +type Endo :: forall (r :: Repr). KindOrType# r -> KindOrType +type Endo i = i -> i + +type Biendo :: forall (r :: Repr). KindOrType# r -> KindOrType +type Biendo i = i -> i -> i diff --git a/src/Lude/Haskell/Defunctionalization.hs b/src/Lude/Haskell/Defunctionalization.hs @@ -4,7 +4,7 @@ module Lude.Haskell.Defunctionalization ( ) where -import Lude.Haskell.Kind +import Lude.Haskell.Core -- TODO: All this is tentative. It's mostly for functors which aren't determined -- by their object map. diff --git a/src/Lude/Haskell/Functional.hs b/src/Lude/Haskell/Functional.hs @@ -8,7 +8,7 @@ module Lude.Haskell.Functional ( import Data.Tuple.Experimental qualified as GHC import Lude.Haskell.Constraint -import Lude.Haskell.Repr +import Lude.Haskell.Core import Lude.Haskell.Repr qualified as Repr import Lude.Haskell.Type @@ -43,7 +43,7 @@ app2# f x y = f `app#` x `app#` y -------------------------------------------------------------------------------- instance Functional# Repr.BoxL where lam# f = \x -> f x; {-# INLINE lam# #-}; app# f = \x -> f x; {-# INLINE app# #-} -instance Functional# Repr.BoxU where lam# f = \x -> f x; {-# INLINE lam# #-}; app# f = \x -> f x; {-# INLINE app# #-} +instance Functional# Repr.BoxE where lam# f = \x -> f x; {-# INLINE lam# #-}; app# f = \x -> f x; {-# INLINE app# #-} instance Functional# Repr.Addr where lam# f = \x -> f x; {-# INLINE lam# #-}; app# f = \x -> f x; {-# INLINE app# #-} instance Functional# Repr.Int where lam# f = \x -> f x; {-# INLINE lam# #-}; app# f = \x -> f x; {-# INLINE app# #-} instance Functional# Repr.Int8 where lam# f = \x -> f x; {-# INLINE lam# #-}; app# f = \x -> f x; {-# INLINE app# #-} diff --git a/src/Lude/Haskell/Generic.hs b/src/Lude/Haskell/Generic.hs @@ -34,9 +34,8 @@ import GHC.Generics (Generic, Generic1) import GHC.Generics qualified as G import Lude.Haskell.Constraint +import Lude.Haskell.Core import Lude.Haskell.Functional -import Lude.Haskell.Kind -import Lude.Haskell.Repr import Lude.Haskell.Type -------------------------------------------------------------------------------- diff --git a/src/Lude/Haskell/Kind.hs b/src/Lude/Haskell/Kind.hs @@ -1,36 +0,0 @@ -module Lude.Haskell.Kind ( - KindOrType#, - KindOrType, - Kind, - Endo, - Biendo, -) where - -import GHC.Exts qualified as GHC - -import Lude.Haskell.Repr (Repr) -import Lude.Haskell.Repr qualified as Repr - --------------------------------------------------------------------------------- - --- This is just so @Kind@ itself receives a non-confusing kind in GHC --- diagnostic messages -type KIND = GHC.TYPE Repr.BoxL - --- NOTE: We typically avoid conflating types and kinds for clarity, --- but when we do conflate them, we use KindOrType. - -type KindOrType# :: Repr -> KIND -type KindOrType# = GHC.TYPE - -type KindOrType :: KIND -type KindOrType = KindOrType# Repr.BoxL - -type Kind :: KIND -type Kind = KindOrType - -type Endo :: forall (r :: Repr). KindOrType# r -> KindOrType -type Endo i = i -> i - -type Biendo :: forall (r :: Repr). KindOrType# r -> KindOrType -type Biendo i = i -> i -> i diff --git a/src/Lude/Haskell/List.hs b/src/Lude/Haskell/List.hs @@ -0,0 +1,7 @@ +module Lude.Haskell.List ( + List, +) where + +import Prelude.Experimental (List) + +-------------------------------------------------------------------------------- diff --git a/src/Lude/Haskell/Repr.hs b/src/Lude/Haskell/Repr.hs @@ -1,92 +1,111 @@ module Lude.Haskell.Repr ( - Levity (..), - Repr, + EvalOrder, + Lazy, + Eager, Unit, Tuple, Sum, Box, BoxL, - BoxU, + BoxE, Addr, - Int, - Int8, - Int16, - Int32, - Int64, Nat, Nat8, Nat16, Nat32, Nat64, + Int, + Int8, + Int16, + Int32, + Int64, Flt32, Flt64, ) where -import GHC.Exts (Levity (..)) import GHC.Exts qualified as GHC +import Lude.Haskell.Core +import Lude.Haskell.List + -- TODO: SIMD --- TODO: Export patterns? (Non-exhaustive until we add SIMD support.) +-- TODO: Export Repr patterns? (Non-exhaustive until we add SIMD support.) -- TODO: Rename "Tuple" and "Sum". I don't like how asymmetric these names are. +-- TODO: Rename Int and Nat. The name should clearly indicate that the bit size +-- is implementation-dependent. + -------------------------------------------------------------------------------- -type Repr = GHC.RuntimeRep +type EvalOrder :: Kind +type EvalOrder = GHC.Levity +type Lazy :: EvalOrder +type Lazy = GHC.Lifted + +type Eager :: EvalOrder +type Eager = GHC.Unlifted + +-------------------------------------------------------------------------------- + +-- NOTE: There is no Void repr, because there are no values of type Void to +-- represent! + +type Unit :: Repr type Unit = GHC.TupleRep [] + +type Tuple :: List Repr -> Repr type Tuple = GHC.TupleRep + +type Sum :: List Repr -> Repr type Sum = GHC.SumRep + +type Box :: EvalOrder -> Repr type Box = GHC.BoxedRep -type BoxL = GHC.BoxedRep Lifted -type BoxU = GHC.BoxedRep Unlifted + +type BoxL :: Repr +type BoxL = GHC.BoxedRep Lazy + +type BoxE :: Repr +type BoxE = GHC.BoxedRep Eager + +type Addr :: Repr 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 :: Repr type Nat = GHC.WordRep + +type Nat8 :: Repr type Nat8 = GHC.Word8Rep + +type Nat16 :: Repr type Nat16 = GHC.Word16Rep -type Nat32 = GHC.Word32Rep -type Nat64 = GHC.Word64Rep -type Flt32 = GHC.FloatRep -type Flt64 = GHC.DoubleRep --------------------------------------------------------------------------------- +type Nat32 :: Repr +type Nat32 = GHC.Word32Rep --- pattern Tuple :: [Repr] -> Repr --- pattern Tuple rs = GHC.TupleRep rs +type Nat64 :: Repr +type Nat64 = GHC.Word64Rep --- pattern Sum :: [Repr] -> Repr --- pattern Sum rs = GHC.SumRep rs +type Int :: Repr +type Int = GHC.IntRep --- pattern Box :: Levity -> Repr --- pattern Box l = GHC.BoxedRep l +type Int8 :: Repr +type Int8 = GHC.Int8Rep --- pattern BoxL, BoxU :: Repr --- pattern BoxL = Box Lifted --- pattern BoxU = Box Unlifted +type Int16 :: Repr +type Int16 = GHC.Int16Rep --- pattern Addr :: Repr --- pattern Addr = GHC.AddrRep +type Int32 :: Repr +type Int32 = GHC.Int32Rep --- 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 +type Int64 :: Repr +type 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 +type Flt32 :: Repr +type Flt32 = GHC.FloatRep --- pattern Flt32, Flt64 :: Repr --- pattern Flt32 = GHC.FloatRep --- pattern Flt64 = GHC.DoubleRep +type Flt64 :: Repr +type Flt64 = GHC.DoubleRep diff --git a/src/Lude/Haskell/Type.hs b/src/Lude/Haskell/Type.hs @@ -9,8 +9,7 @@ module Lude.Haskell.Type ( import Data.Tuple.Experimental qualified as GHC import GHC.Exts qualified as GHC -import Lude.Haskell.Kind -import Lude.Haskell.Repr (Repr) +import Lude.Haskell.Core import Lude.Haskell.Repr qualified as Repr -------------------------------------------------------------------------------- diff --git a/src/Lude/List.hs b/src/Lude/List.hs @@ -2,6 +2,6 @@ module Lude.List ( List, ) where -import Prelude.Experimental (List) +import Lude.Haskell.List (List) --------------------------------------------------------------------------------