Skip to content

Commit

Permalink
Improve partial monad interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellis Kesterton committed Mar 28, 2024
1 parent 1cb8eff commit 37fab2e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions libs/base/Control/Monad/Partial.idr
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Control.Monad.Partial

import Data.Nat

%default total


Expand Down Expand Up @@ -40,13 +42,13 @@ never = Later never

public export
data Total : Partial a -> Type where
TNow : Total (Now x)
TNow : (x : a) -> Total (Now x)
TLater : Total (Force x) -> Total (Later x)


||| Extract the value from a partial computation if you have a proof it is
||| actually total.
public export
runPartial : (x : Partial a) -> Total x -> a
runPartial (Now v) TNow = v
runPartial (Later x) (TLater t) = runPartial x t
runPartial : {x : Partial a} -> (0 _ : Total x) -> a
runPartial (TNow x) = x
runPartial (TLater t) = runPartial t

0 comments on commit 37fab2e

Please sign in to comment.