-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
assert
function to Haskell.Control.Exception
- Loading branch information
1 parent
1bf9d3a
commit 7cae101
Showing
6 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Haskell.Control.Exception where | ||
|
||
open import Haskell.Prim | ||
|
||
open import Haskell.Extra.Dec | ||
open import Haskell.Extra.Refinement | ||
|
||
assert : (@0 b : Set ℓ) → {{Dec b}} → (@0 {{b}} → a) → a | ||
assert _ {{True ⟨ p ⟩}} x = x {{p}} | ||
assert _ {{False ⟨ _ ⟩}} x = oops | ||
where postulate oops : _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
open import Haskell.Prelude | ||
open import Haskell.Control.Exception | ||
open import Haskell.Law.Ord | ||
open import Haskell.Extra.Dec | ||
|
||
subtractChecked : Nat → Nat → Nat | ||
subtractChecked x y = assert (IsFalse (x < y)) (x - y) | ||
|
||
{-# COMPILE AGDA2HS subtractChecked #-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,4 +88,5 @@ import ProjectionLike | |
import FunCon | ||
import Issue308 | ||
import Issue324 | ||
import Assert | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Assert where | ||
|
||
import Control.Exception (assert) | ||
import Numeric.Natural (Natural) | ||
|
||
subtractChecked :: Natural -> Natural -> Natural | ||
subtractChecked x y = assert (not (x < y)) (x - y) | ||
|