Skip to content

Commit aed00e3

Browse files
HeinrichApfelmusomelkonian
authored andcommittedMar 10, 2025·
Rename Set to Type in documentation
1 parent aef3643 commit aed00e3

File tree

3 files changed

+39
-35
lines changed

3 files changed

+39
-35
lines changed
 

‎docs/source/features.md

+33-29
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Standard data type declarations have a simple equivalent in Agda.
3131

3232
Agda:
3333
```agda
34-
data Nat : Set where
34+
data Nat : Type where
3535
Zero : Nat
3636
Suc : Nat Nat
3737

@@ -43,11 +43,13 @@ Haskell:
4343
data Nat = Zero | Suc Nat
4444
```
4545

46+
In the definition above, we have to explicitly indicate that `Nat` is a data `Type` by writing the signature `Nat : Type`.
47+
4648
You can also use polymorphic types in the data declarations.
4749

4850
Agda:
4951
```agda
50-
data Tree (a : Set) : Set where
52+
data Tree (a : Type) : Type where
5153
Leaf : a Tree a
5254
Branch : a Tree a Tree a Tree a
5355

@@ -62,13 +64,15 @@ data Tree a = Leaf a
6264

6365
**UNSUPPORTED: term-indexed datatypes**
6466

67+
(For Agda users: We have renamed `Set` to `Type` in order to follow nomenclature in Haskell.)
68+
6569
### Records
6670

6771
Data definitions with fields are represented by records on the Agda side.
6872

6973
Agda:
7074
```agda
71-
record Citation : Set where
75+
record Citation : Type where
7276
field
7377
id : Int
7478
author : String
@@ -93,19 +97,19 @@ Data declaration using the `newtype` keyword can be created by adding a `newtype
9397
Agda:
9498
```agda
9599
-- data newtype
96-
data Indexed (a : Set) : Set where
100+
data Indexed (a : Type) : Type where
97101
MkIndexed : Int × a Indexed a
98102

99103
{-# COMPILE AGDA2HS Indexed newtype #-}
100104

101105
-- data newtype with deriving
102-
data Pair (a b : Set) : Set where
106+
data Pair (a b : Type) : Type where
103107
MkPair : a × b Pair a b
104108

105109
{-# COMPILE AGDA2HS Pair newtype deriving ( Show, Eq ) #-}
106110

107111
-- record newtype
108-
record Identity (a : Set) : Set where
112+
record Identity (a : Type) : Type where
109113
constructor MkIdentity
110114
field
111115
runIdentity : a
@@ -114,7 +118,7 @@ open Identity public
114118
{-# COMPILE AGDA2HS Identity newtype #-}
115119

116120
-- record newtype with erased proof
117-
record Equal (a : Set) : Set where
121+
record Equal (a : Type) : Type where
118122
constructor MkEqual
119123
field
120124
pair : a × a
@@ -144,7 +148,7 @@ Unfortunately, Agda does not allow the constructor name to be the same as the da
144148
However, it _is_ possible to achieve this with Agda2HS if you do not explicitly add a constructor name to a record definition (this requires the use of `record { ... }` syntax on the Agda side):
145149

146150
```agda
147-
record Duo (a : Set) : Set where
151+
record Duo (a : Type) : Type where
148152
field
149153
duo : a × a
150154
open Duo public
@@ -243,7 +247,7 @@ The type signatures of both `if_then_else_` and `case_of_` on the Agda side cont
243247

244248
This allows for the following Agda code to type check:
245249
```agda
246-
data Range : Set where
250+
data Range : Type where
247251
MkRange : (low high : Int)
248252
→ {{ @0 h : ((low <= high) ≡ True) }}
249253
→ Range
@@ -303,7 +307,7 @@ Parameters can be annotated with a _quantity_ of either `0` or `ω` (the default
303307

304308
Agda:
305309
```agda
306-
data GhostInt : Set where
310+
data GhostInt : Type where
307311
MakeGhostInt : @0 Int → GhostInt
308312
309313
-- fails
@@ -327,7 +331,7 @@ addGhostInts MakeGhostInt MakeGhostInt = MakeGhostInt
327331

328332
Agda:
329333
```agda
330-
data Stream (a : Set) (@0 i : Size) : Set where
334+
data Stream (a : Type) (@0 i : Size) : Type where
331335
Nil : Stream a i
332336
Cons : a → Thunk (Stream a) i → Stream a i
333337
{-# COMPILE AGDA2HS Stream #-}
@@ -351,7 +355,7 @@ To construct an instance of a type class, you can simply do the following:
351355

352356
Agda:
353357
```agda
354-
record Circle : Set where
358+
record Circle : Type where
355359
constructor MkCircle
356360
field
357361
radius : Int
@@ -379,7 +383,7 @@ In this case, you can also implement the `IsLawful` instance for the data type a
379383

380384
Agda:
381385
```agda
382-
record Equal (a : Set) : Set where
386+
record Equal (a : Type) : Type where
383387
constructor MkEqual
384388
field
385389
pair : a × a
@@ -425,17 +429,17 @@ constructEqualCircle c d = constructEqual c d
425429

426430
Agda:
427431
```agda
428-
record Class1 (a : Set) : Set where
432+
record Class1 (a : Type) : Type where
429433
field
430434
field1 : a
431435
{-# COMPILE AGDA2HS Class1 class #-}
432436
433-
record Class2 (a : Set) : Set where
437+
record Class2 (a : Type) : Type where
434438
field
435439
field2 : a
436440
{-# COMPILE AGDA2HS Class2 class #-}
437441
438-
class1-implies-class2 (a : Set) : Class1 a → Class2 a
442+
class1-implies-class2 (a : Type) : Class1 a → Class2 a
439443
class1-implies-class2 _ class1 = record { field2 = class1.field1 }
440444
{-# COMPILE AGDA2HS class1-implies-class2 #-}
441445
```
@@ -456,12 +460,12 @@ instance Class1 a => Class2 a where
456460

457461
Agda:
458462
```agda
459-
record Class1 (a : Set) : Set where
463+
record Class1 (a : Type) : Type where
460464
field
461465
field1 : a
462466
{-# COMPILE AGDA2HS Class1 class #-}
463467
464-
record Class2 (a : Set) : Set where
468+
record Class2 (a : Type) : Type where
465469
field
466470
overlap ⦃ super ⦄ : ClassA b
467471
field2 : a
@@ -481,18 +485,18 @@ class Class1 a => Class2 a where
481485

482486
Agda:
483487
```agda
484-
record Ord (a : Set) : Set where
488+
record Ord (a : Type) : Type where
485489
field
486490
_<_ _>_ : a a Bool
487491

488-
record Ord₁ (a : Set) : Set where
492+
record Ord₁ (a : Type) : Type where
489493
field
490494
_<_ : a a Bool
491495

492496
_>_ : a a Bool
493497
x > y = y < x
494498

495-
record Ord₂ (a : Set) : Set where
499+
record Ord₂ (a : Type) : Type where
496500
field
497501
_>_ : a a Bool
498502

@@ -530,7 +534,7 @@ used to define fields of typeclass instances, for example:
530534

531535
Agda:
532536
```agda
533-
record HasId (a : Set) : Set where
537+
record HasId (a : Type) : Type where
534538
field id : a → a
535539
{-# COMPILE AGDA2HS HasId class #-}
536540
@@ -553,7 +557,7 @@ instance HasId () where
553557
If the derived instance is not needed on the Agda side and needs to only be generated in Haskell, the deriving clause can simply be added to the compilation pragma (this also works with the `newtype` pragma):
554558

555559
```agda
556-
data Planet : Set where
560+
data Planet : Type where
557561
Mercury : Planet
558562
Venus : Planet
559563
Earth : Planet
@@ -618,7 +622,7 @@ This is also possible with more complicated instance definitions, such as in the
618622

619623
Agda:
620624
```agda
621-
data Optional (a : Set) : Set where
625+
data Optional (a : Type) : Type where
622626
Of : a Optional a
623627
Empty : Optional a
624628

@@ -645,7 +649,7 @@ postulate instance iPlanetShow : Show Planet
645649

646650
{-# COMPILE AGDA2HS iPlanetShow derive stock #-}
647651

648-
record Clazz (a : Set) : Set where
652+
record Clazz (a : Type) : Type where
649653
field
650654
foo : a Int
651655
bar : a Bool
@@ -658,7 +662,7 @@ postulate instance iPlanetClazz : Clazz Planet
658662

659663
{-# COMPILE AGDA2HS iPlanetClazz derive anyclass #-}
660664

661-
data Duo (a b : Set) : Set where
665+
data Duo (a b : Type) : Type where
662666
MkDuo : (a × b) Duo a b
663667

664668
{-# COMPILE AGDA2HS Duo newtype #-}
@@ -734,15 +738,15 @@ Agda
734738
```agda
735739
mutual
736740
737-
data Map (k : Set) (a : Set) : Set where
741+
data Map (k : Type) (a : Type) : Type where
738742
Bin : (sz : Nat) → (kx : k) → (x : a)
739743
→ (l : Map k a) → (r : Map k a)
740744
→ {{@0 szVal : sz ≡ (size l) + (size r) + 1}}
741745
→ Map k a
742746
Tip : Map k a
743747
{-# COMPILE AGDA2HS Map #-}
744748
745-
size : {k a : Set} → Map k a → Nat
749+
size : {k a : Type} → Map k a → Nat
746750
size Tip = 0
747751
size (Bin sz _ _ _ _) = sz
748752
{-# COMPILE AGDA2HS size #-}
@@ -762,7 +766,7 @@ size (Bin sz _ _ _ _) = sz
762766

763767
Agda
764768
```agda
765-
record ImplicitField (a : Set) : Set where
769+
record ImplicitField (a : Type) : Type where
766770
field
767771
aField : a
768772
@0 {anImplicitField} : a

‎docs/source/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ the following Agda program encodes well-formed binary search trees:
77
```agda
88
open import Haskell.Prelude
99
10-
_≤_ : {{Ord a}} → a → a → Set
10+
_≤_ : {{Ord a}} → a → a → Type
1111
x ≤ y = (x <= y) ≡ True
1212
13-
data BST (a : Set) {{@0 _ : Ord a}} (@0 lower upper : a) : Set where
13+
data BST (a : Type) {{@0 _ : Ord a}} (@0 lower upper : a) : Type where
1414
Leaf : (@0 pf : lower ≤ upper) → BST a lower upper
1515
Node : (x : a) (l : BST a lower x) (r : BST a x upper) → BST a lower upper
1616

‎docs/source/tutorials.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ open import Haskell.Prelude
4343
Entry = Int × List String
4444
4545
--defining a datatype
46-
data Tree (a : Set) : Set where
46+
data Tree (a : Type) : Type where
4747
Leaf : a → Tree a
4848
Branch : a → Tree a → Tree a → Tree a
4949
@@ -120,7 +120,7 @@ Let's say we want to have a data type describing a triangle. A first attempt mig
120120
```agda
121121
open import Haskell.Prelude
122122
123-
data Triangle : Set where
123+
data Triangle : Type where
124124
MkTriangle : (alpha beta gamma : Nat)
125125
→ Triangle
126126
@@ -136,7 +136,7 @@ countBiggerThan xs b = length (filter (λ x → (x >= b)) xs)
136136
137137
{-# COMPILE AGDA2HS countBiggerThan #-}
138138
139-
data Triangle : Set where
139+
data Triangle : Type where
140140
MkTriangle : (alpha beta gamma : Nat)
141141
→ ⦃ @0 h₁ : (((alpha + beta + gamma) == 180) ≡ True )⦄
142142
→ @0 ⦃ ((countBiggerThan
@@ -210,7 +210,7 @@ isAscending (x ∷ y ∷ xs) = if x <= y then isAscending
210210
This function can be compiled to Haskell without any issue, however, when you try using it in proofs you can notice that it is not the most handy definition: since the different cases are anonymous, invoking them is not straightforward and might require defining more proof cases with additional assertions about the values input data (an example of which can be found [further in the tutorial](function-example)) A better definition might be a predicate, instead:
211211

212212
```agda
213-
data IsAscending₂ {a : Set} ⦃ iOrdA : Ord a ⦄ : List a → Set where
213+
data IsAscending₂ {a : Type} ⦃ iOrdA : Ord a ⦄ : List a → Type where
214214
Empty : IsAscending₂ []
215215
OneElem : (x : a) → IsAscending₂ (x ∷ [])
216216
ManyElem : (x y : a) (xs : List a)

0 commit comments

Comments
 (0)
Please sign in to comment.