commit 22c569316476595abb81eb64ed1eeb7946491314
parent fbda0ed45df1d814ffa27e1cdd0cbf94cfd5b039
Author: Robert Russell <robert@rr3.xyz>
Date: Tue, 6 Oct 2026 16:36:30 -0700
Haskell: add type-level composition operators
Diffstat:
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/src/Lude/Haskell/Core.hs b/src/Lude/Haskell/Core.hs
@@ -3,16 +3,24 @@ module Lude.Haskell.Core (
KindOrType#,
KindOrType,
Kind,
+ --
Brand,
OpenKind,
+ --
Endo,
Biendo,
+ type (.),
+ type (∘),
) where
import GHC.Exts qualified as GHC
--------------------------------------------------------------------------------
+infixr 9 ., ∘
+
+--------------------------------------------------------------------------------
+
-- | 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
@@ -32,6 +40,9 @@ type KindOrType = KindOrType# GHC.LiftedRep
type Kind :: KIND
type Kind = KindOrType
+--------------------------------------------------------------------------------
+-- Open Kinds (i.e., extensible kinds)
+
-- | The kind of brands for `OpenKind`
type Brand :: KIND
type Brand = Kind
@@ -57,8 +68,21 @@ type Brand = Kind
type OpenKind :: Brand -> Kind
type OpenKind b = b -> Kind
+--------------------------------------------------------------------------------
+-- Util
+
+-- TODO: Move?
+
+-- | @Endo a = a -> a@
type Endo :: forall (r :: Repr). KindOrType# r -> KindOrType
-type Endo i = i -> i
+type Endo a = a -> a
+-- | @Biendo a = a -> a -> a@
type Biendo :: forall (r :: Repr). KindOrType# r -> KindOrType
-type Biendo i = i -> i -> i
+type Biendo a = a -> a -> a
+
+type (.) :: forall i j k. (j -> k) -> (i -> j) -> (i -> k)
+type (f . g) x = f (g x)
+
+type (∘) :: forall i j k. (j -> k) -> (i -> j) -> (i -> k)
+type (f ∘ g) x = f (g x)
diff --git a/src/Todo/DependentKinds.hs b/src/Todo/DependentKinds.hs
@@ -7,11 +7,6 @@ import Lude
--------------------------------------------------------------------------------
-type (.) :: forall i j k. (j -> k) -> (i -> j) -> (i -> k)
-type (f . g) x = f (g x)
-
---------------------------------------------------------------------------------
-
type Forall :: forall k. (k -> Kind) -> Kind
type Forall @k f = forall (a :: k). f a