lude

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

commit c5db2fca4fb3dd4a23cae34a8829a8b77fe8cbc0
parent 76d021fb8eb5ed9b65a8f1acdb7c9698641e5452
Author: Robert Russell <robert@rr3.xyz>
Date:   Thu, 15 Oct 2026 17:28:45 -0700

Haskell.Partial: init

Diffstat:
Msrc/Lude/Haskell.hs | 1+
Asrc/Lude/Haskell/Partial.hs | 37+++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/src/Lude/Haskell.hs b/src/Lude/Haskell.hs @@ -10,6 +10,7 @@ import Lude.Haskell.Constraint as X import Lude.Haskell.Core 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 import Lude.Haskell.Tuple as X import Lude.Haskell.Type as X diff --git a/src/Lude/Haskell/Partial.hs b/src/Lude/Haskell/Partial.hs @@ -0,0 +1,37 @@ +module Lude.Haskell.Partial ( + Partial, + unsafe_partial, +) where + +import GHC.Exts qualified as GHC + +import Lude.Haskell.Constraint +import Lude.Haskell.Core +import Lude.Haskell.Type + +-- NOTE: We prevent writing an instance of Partial by only exporting a +-- constraint synonym, which GHC disallows in the head of an instance +-- declaration. + +-- NOTE: We need a dummy method to use `GHC.withDict`, hence `capability`. +-- Keeping the constructor of that method private helps avoid users +-- "accidentally" calling `GHC.withDict` on partial computations themselves. + +-- NOTE: This is inspired by PureScript's Partial constraint: +-- https://pursuit.purescript.org/packages/purescript-partial + +-------------------------------------------------------------------------------- + +type Capability :: Type +data Capability = Unsafe_MkCapability + +type Partial_ :: Constraint +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