Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ new ] Factoring out unsafe parts of the library (#414)
- Loading branch information
1 parent
4a37c36
commit 8885d7a
Showing
28 changed files
with
1,516 additions
and
331 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
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
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
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,58 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- Unsafe Char operations and proofs | ||
------------------------------------------------------------------------ | ||
|
||
module Data.Char.Unsafe where | ||
|
||
open import Data.Bool.Base using (Bool; true; false) | ||
open import Relation.Nullary using (yes; no) | ||
open import Relation.Nullary.Decidable using (⌊_⌋) | ||
open import Relation.Binary using (Decidable; DecSetoid) | ||
open import Relation.Binary.PropositionalEquality as PropEq using (_≡_) | ||
open import Relation.Binary.PropositionalEquality.TrustMe | ||
|
||
open import Agda.Builtin.Char using (primCharEquality) | ||
open import Data.Char | ||
|
||
------------------------------------------------------------------------ | ||
-- An informative equality test. | ||
|
||
infix 4 _≟_ | ||
|
||
_≟_ : Decidable {A = Char} _≡_ | ||
s₁ ≟ s₂ with primCharEquality s₁ s₂ | ||
... | true = yes trustMe | ||
... | false = no whatever | ||
where postulate whatever : _ | ||
|
||
------------------------------------------------------------------------ | ||
-- Boolean equality test. | ||
-- | ||
-- Why is the definition _==_ = primCharEquality not used? One reason | ||
-- is that the present definition can sometimes improve type | ||
-- inference, at least with the version of Agda that is current at the | ||
-- time of writing: see unit-test below. | ||
|
||
infix 4 _==_ | ||
|
||
_==_ : Char → Char → Bool | ||
c₁ == c₂ = ⌊ c₁ ≟ c₂ ⌋ | ||
|
||
private | ||
|
||
-- The following unit test does not type-check (at the time of | ||
-- writing) if _==_ is replaced by primCharEquality. | ||
|
||
data P : (Char → Bool) → Set where | ||
p : (c : Char) → P (c ==_) | ||
|
||
unit-test : P ('x' ==_) | ||
unit-test = p _ | ||
|
||
------------------------------------------------------------------------ | ||
-- Decidable equality | ||
|
||
decSetoid : DecSetoid _ _ | ||
decSetoid = PropEq.decSetoid _≟_ |
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,24 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- Unsafe Float operations | ||
------------------------------------------------------------------------ | ||
|
||
module Data.Float.Unsafe where | ||
|
||
open import Data.Float | ||
open import Data.Bool.Base using (false; true) | ||
open import Relation.Nullary using (Dec; yes; no) | ||
open import Relation.Binary.PropositionalEquality using (_≡_) | ||
open import Relation.Binary.PropositionalEquality.TrustMe | ||
|
||
------------------------------------------------------------------------ | ||
-- Equality testing | ||
|
||
infix 4 _≟_ | ||
|
||
_≟_ : (x y : Float) → Dec (x ≡ y) | ||
x ≟ y with primFloatEquality x y | ||
... | true = yes trustMe | ||
... | false = no whatever | ||
where postulate whatever : _ |
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
Oops, something went wrong.