commit a6a71f9862a4f3706e9b0f5955c9db2d67037565
parent c5db2fca4fb3dd4a23cae34a8829a8b77fe8cbc0
Author: Robert Russell <robert@rr3.xyz>
Date: Thu, 15 Oct 2026 17:55:30 -0700
Haskell.Exception: init
Diffstat:
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/src/Lude/Haskell.hs b/src/Lude/Haskell.hs
@@ -8,6 +8,7 @@ import Lude.Haskell.Bool as X (ifThenElse)
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.Exception as X
import Lude.Haskell.Functional as X
import Lude.Haskell.Generic as X hiding (Rep, Rep1, from, from1, to, to1)
import Lude.Haskell.Partial as X
diff --git a/src/Lude/Haskell/Exception.hs b/src/Lude/Haskell/Exception.hs
@@ -0,0 +1,31 @@
+{-# LANGUAGE ImplicitParams #-}
+
+module Lude.Haskell.Exception (
+ module X,
+ --
+ withFrozenCallStack,
+ raise,
+ unsafe_raise,
+) where
+
+import Control.Exception as X (Exception (..))
+import GHC.Stack as X (HasCallStack)
+
+import Control.Exception qualified as Base
+import GHC.Stack qualified as GHC
+
+import Lude.Haskell.Core
+import Lude.Haskell.Partial
+import Lude.Haskell.Type
+
+--------------------------------------------------------------------------------
+
+-- | Representation-polymorphic version of @GHC.Stack.withFrozenCallStack@
+withFrozenCallStack :: forall {r :: Repr} (a :: Type# r). (HasCallStack) => ((HasCallStack) => a) -> a
+withFrozenCallStack k = k where ?callStack = GHC.freezeCallStack (GHC.popCallStack GHC.callStack)
+
+raise :: forall (e :: Type) {r :: Repr} (a :: Type# r). (HasCallStack, Exception e, Partial) => e -> a
+raise = withFrozenCallStack Base.throw
+
+unsafe_raise :: forall (e :: Type) {r :: Repr} (a :: Type# r). (HasCallStack, Exception e) => e -> a
+unsafe_raise = withFrozenCallStack (unsafe_partial raise)
diff --git a/src/Lude/Haskell/Partial.hs b/src/Lude/Haskell/Partial.hs
@@ -31,7 +31,5 @@ class Partial_ where capability :: Capability
type Partial :: Constraint
type Partial = Partial_
---------------------------------------------------------------------------------
-
unsafe_partial :: forall {r :: Repr} (a :: Type# r). ((Partial) => a) -> a
unsafe_partial = GHC.withDict Unsafe_MkCapability