Skip to content

Commit 46e77ea

Browse files
Changed the implementation of Foreign.Haskell.Maybe/Pair back to datatypes
1 parent c395075 commit 46e77ea

File tree

3 files changed

+47
-49
lines changed

3 files changed

+47
-49
lines changed

CHANGELOG.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Highlights
1111
* Large increases in performance for `Nat`, `Integer` and `Rational` datatypes,
1212
particularly in compiled code.
1313

14-
* Generic n-ary programming (projₙ, congₙ, substₙ etc.)
14+
* Generic n-ary programming (`projₙ`, `congₙ`, `substₙ` etc.)
1515

1616
* General argmin/argmax/min/max over `List`.
1717

@@ -47,7 +47,7 @@ Bug-fixes
4747
* `Data.Rational` previously accidently exported queries from `Data.Nat.Base`
4848
instead of `Data.Rational.Base`. This has now been fixed.
4949

50-
#### Fixed name in `Data.Nat.Properties`
50+
#### Fixed inaccurate name in `Data.Nat.Properties`
5151

5252
* The proof `m+n∸m≡n` in `Data.Nat.Properties` was incorrectly named as
5353
it proved `m + (n ∸ m) ≡ n` rather than `m + n ∸ m ≡ n`. It has
@@ -60,37 +60,36 @@ Bug-fixes
6060
was previously set such that when it was inherited by the records `Ring`,
6161
`CommutativeRing` etc. it had the same predence as `_*_` rather than `_+_`.
6262
This lead to `x - x * x` being ambigous instead of being parsed as `x - (x * x)`.
63-
To fix this the precedence of `_-_` has been reduced from 7 to 6.
63+
To fix this, the precedence of `_-_` has been reduced from 7 to 6.
6464

6565
#### Fixed operator precedents in `Reasoning` modules
6666

6767
* The infix precedence of the generic order reasoning combinators (`_∼⟨_⟩_`,
68-
`_≈⟨_⟩_`, etc.) in `Relation.Binary.Reasoning.Base.{Double,Triple}` were
69-
lowered when implementing new style reasoning (issue #185). This lead to
70-
inconsistencies in modules that add custom combinators (e.g. `StarReasoning`
71-
from `Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties`)
72-
using the original fixity. The old fixity has been restored now.
68+
`_≈⟨_⟩_`, etc.) in `Relation.Binary.Reasoning.Base.Double/Triple` were
69+
accidentally lowered when implementing new style reasoning in `v1.0`.
70+
This lead to inconsistencies in modules that add custom combinators (e.g.
71+
`StarReasoning` from `Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties`)
72+
using the original fixity. The old fixity has now been restored.
7373

7474
Other non-backwards compatible changes
7575
--------------------------------------
7676

7777
#### Improved performance of arithmetic decision procedures & operations
7878

7979
* The functions `_≤?_` and `<-cmp` in `Data.Nat.Properties` have been
80-
reimplemented so that, when compiled or when the generated proof is
81-
unused, now uses only built-in primitives. This should result in a
82-
significant performance increase.
80+
reimplemented uses only built-in primitives. Consequently this should
81+
result in a significant performance increase when these functions are
82+
compiled or when the generated proof is ignored.
8383

8484
* The function `show` in `Data.Nat.Show` has been reimplemented and,
8585
when compiled, now runs in time `O(log₁₀(n))` rather than `O(n)`.
8686

8787
* The functions `gcd` and `lcm` in `Data.Nat.GCD` and `Data.Nat.LCM`
8888
have been reimplemented via the built-ins `_/_` and `mod` so that
89-
they run much faster when compiled. The new functions now have type
90-
`ℕ → ℕ → ℕ` instead of the old functions of type
91-
`(m n : ℕ) → ∃ λ d → GCD/LCM m n d`. The old functions have been renamed
92-
`mkGCD`/`mkLCM`. The alternative `gcd′` in `Data.Nat.Coprimality` has
93-
been deprecated.
89+
they run much faster when compiled and normalised. Their types have also
90+
been changed to `ℕ → ℕ → ℕ` instead of `(m n : ℕ) → ∃ λ d → GCD/LCM m n d`.
91+
The old functions still exist and have been renamed `mkGCD`/`mkLCM`.
92+
The alternative `gcd′` in `Data.Nat.Coprimality` has been deprecated.
9493

9594
* As a consequence of the above, the performance of all decidability procedures
9695
in `Data.Integer` and `Data.Rational` should also have improved. Normalisation
@@ -105,20 +104,21 @@ Other non-backwards compatible changes
105104

106105
#### Consistent field names in `IsDistributiveLattice`
107106

108-
* The module `IsDistributiveLattice` in `Algebra.Structures` has had its field
109-
renamed from `∨-∧-distribʳ` to `∨-distribʳ-∧` in order to match the conventions
110-
found elsewhere in the library. To maximise backwards compatability the record
111-
still exports the name `∨-∧-distribʳ` but it has been deprecated.
107+
* In order to match the conventions found elsewhere in the library, the module
108+
`IsDistributiveLattice` in `Algebra.Structures` has had its field renamed
109+
from `∨-∧-distribʳ` to `∨-distribʳ-∧` . To maximise backwards compatability,
110+
the record still exports `∨-∧-distribʳ` but the name is deprecated.
112111

113112
#### Making categorical traversal functions easier to use
114113

115-
* At the moment the functions `sequenceA`, `mapA`, `forA`, `sequenceM`,
116-
`mapM` and `forM` in the `Data.X.Categorical` modules all require the
117-
`Applicative`/`Monad` to be passed each time they're used. To avoid this they
118-
have now been placed in parameterised, modules named `TraversableA` and
114+
* Previously the functions `sequenceA`, `mapA`, `forA`, `sequenceM`,
115+
`mapM` and `forM` in the `Data.X.Categorical` modules required the
116+
`Applicative`/`Monad` to be passed each time they were used. To avoid this
117+
they have now been placed in parameterised modules named `TraversableA` and
119118
`TraversableM`. To recover the old behaviour simply write `open TraversableA`.
120-
However the applicative may avoid being passed by writing `open TraversableA app`.
121-
The change has occured in the following modules:
119+
However you may now, for example, avoid passing the applicative every time
120+
by writing `open TraversableA app`. The change has occured in the following
121+
modules:
122122
```adga
123123
Data.Maybe.Categorical
124124
Data.List.Categorical
@@ -161,7 +161,7 @@ The following new modules have been added to the library:
161161
Data.List.Extrema
162162
Data.List.Extrema.Nat
163163
Data.List.Extrema.Core
164-
```
164+
```
165165

166166
* Additional properties of membership with the `--with-k` option enabled.
167167
```
@@ -336,7 +336,7 @@ attached to all deprecated names to discourage their use.
336336
```
337337

338338
* In `Relation.Binary.Core`:
339-
```agdas
339+
```agda
340340
Conn ↦ Connex
341341
```
342342

src/Foreign/Haskell/Maybe.agda

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
module Foreign.Haskell.Maybe where
1010

1111
open import Level
12-
import Data.Maybe as Data
12+
open import Data.Maybe.Base as Data using (just; nothing)
1313

1414
private
1515
variable
@@ -19,21 +19,20 @@ private
1919
------------------------------------------------------------------------
2020
-- Definition
2121

22-
abstract
23-
24-
Maybe : Set a Set a
25-
Maybe = Data.Maybe
22+
data Maybe (A : Set a) : Set a where
23+
just : A Maybe A
24+
nothing : Maybe A
2625

2726
{-# FOREIGN GHC type AgdaMaybe l a = Maybe a #-}
2827
{-# COMPILE GHC Maybe = data AgdaMaybe (Just | Nothing) #-}
2928

3029
------------------------------------------------------------------------
3130
-- Conversion
3231

33-
abstract
34-
35-
toForeign : Data.Maybe A Maybe A
36-
toForeign x = x
32+
toForeign : Data.Maybe A Maybe A
33+
toForeign (just x) = just x
34+
toForeign nothing = nothing
3735

38-
fromForeign : Maybe A Data.Maybe A
39-
fromForeign x = x
36+
fromForeign : Maybe A Data.Maybe A
37+
fromForeign (just x) = just x
38+
fromForeign nothing = nothing

src/Foreign/Haskell/Pair.agda

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,20 @@ private
2020
------------------------------------------------------------------------
2121
-- Definition
2222

23-
abstract
24-
25-
Pair : Set a Set b Set (a ⊔ b)
26-
Pair = _×_
23+
record Pair (A : Set a) (B : Set b) : Set (a ⊔ b) where
24+
constructor _,_
25+
field fst : A
26+
snd : B
27+
open Pair public
2728

2829
{-# FOREIGN GHC type AgdaPair l1 l2 a b = (a , b) #-}
2930
{-# COMPILE GHC Pair = data MAlonzo.Code.Foreign.Haskell.AgdaPair ((,)) #-}
3031

3132
------------------------------------------------------------------------
3233
-- Conversion
3334

34-
abstract
35-
36-
toForeign : A × B Pair A B
37-
toForeign x = x
35+
toForeign : A × B Pair A B
36+
toForeign (a , b) = (a , b)
3837

39-
fromForeign : Pair A B A × B
40-
fromForeign x = x
38+
fromForeign : Pair A B A × B
39+
fromForeign (a , b) = (a , b)

0 commit comments

Comments
 (0)