Skip to content

Commit 9723b7d

Browse files
author
Alex Gryzlov
committed
tweak Maps
1 parent c28539b commit 9723b7d

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/Logic.lidr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ Idris's stdlib has a more general form of this, \idr{Iso}, in
422422
> not_true_iff_false : (Not (b = True)) <-> (b = False)
423423
> not_true_iff_false {b} = (not_true_is_false b, not_true_and_false b)
424424
> where
425-
> not_true_and_false : (b : Bool) -> (b = False) -> (b = True) -> Void
425+
> not_true_and_false : (b : Bool) -> (b = False) -> Not (b = True)
426426
> not_true_and_false False _ Refl impossible
427427
> not_true_and_false True Refl _ impossible
428428

src/Maps.lidr

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
= Maps: Total and Partial Maps
22

3+
> module Maps
4+
35
Maps (or dictionaries) are ubiquitous data structures both generally and in the
46
theory of programming languages in particular; we're going to need them in many
57
places in the coming chapters. They also make a nice case study using ideas
@@ -10,7 +12,7 @@ streamline proofs (from `IndProp`).
1012
We'll define two flavors of maps: _total_ maps, which include a "default"
1113
element to be returned when a key being looked up doesn't exist, and _partial_
1214
maps, which return a \idr{Maybe} to indicate success or failure. The latter is
13-
defined in terms of the former, using \idr{Maybe} as the default element.
15+
defined in terms of the former, using \idr{Nothing} as the default element.
1416

1517

1618
== The Idris Standard Library
@@ -19,24 +21,26 @@ defined in terms of the former, using \idr{Maybe} as the default element.
1921

2022
One small digression before we get to maps.
2123

22-
Unlike the chapters we have seen so far, this one does not Require Import the
24+
Unlike the chapters we have seen so far, this one does not `Require Import` the
2325
chapter before it (and, transitively, all the earlier chapters). Instead, in
2426
this chapter and from now, on we're going to import the definitions and theorems
2527
we need directly from Idris's standard library stuff. You should not notice much
2628
difference, though, because we've been careful to name our own definitions and
2729
theorems the same as their counterparts in the standard library, wherever they
2830
overlap.
2931

32+
```coq
3033
Require Import Idris.Arith.Arith.
3134
Require Import Idris.Bool.Bool.
3235
Require Import Idris.Strings.String.
3336
Require Import Idris.Logic.FunctionalExtensionality.
37+
```
3438

3539
Documentation for the standard library can be found at
3640
http://Idris.inria.fr/library/.
3741

38-
The Search command is a good way to look for theorems involving objects of
39-
specific types. Take a minute now to experiment with it.
42+
The \idr{:search} command is a good way to look for theorems involving objects
43+
of specific types. Take a minute now to experiment with it.
4044

4145

4246
== Identifiers
@@ -70,13 +74,15 @@ present purposes you can think of it as just a fancy \idr{Bool}.)
7074
The following useful property of \idr{beq_id} follows from an analogous lemma
7175
about strings:
7276

73-
\todo[inline]{Copypasted `<->` for now}
77+
\todo[inline]{Copied \idr{<->} for now}
7478

7579
> iff : {p,q : Type} -> Type
7680
> iff {p} {q} = (p -> q, q -> p)
7781

7882
> syntax [p] "<->" [q] = iff {p} {q}
7983

84+
\todo[inline]{Somehow this doesn't work if put under \idr{where} as usual}
85+
8086
> bto : (beq_id x y = True) -> x = y
8187
> bto {x=MkId n1} {y=MkId n2} prf with (decEq n1 n2)
8288
> bto Refl | (Yes eq) = cong {f=MkId} eq
@@ -94,9 +100,10 @@ about strings:
94100

95101
Similarly:
96102

97-
\todo[inline]{Copypasted here for now}
103+
\todo[inline]{Copied and inlined \idr{not_true_iff_false} from \idr{Logic} here
104+
for now}
98105

99-
> not_true_and_false : (b = False) -> (b = True) -> Void
106+
> not_true_and_false : (b = False) -> Not (b = True)
100107
> not_true_and_false {b=False} _ Refl impossible
101108
> not_true_and_false {b=True} Refl _ impossible
102109
> not_true_is_false : Not (b = True) -> b = False
@@ -140,6 +147,12 @@ this map always returns the default element when applied to any id.
140147
> t_empty : (v : a) -> total_map a
141148
> t_empty v = \_ => v
142149

150+
We can also write this as:
151+
152+
```idris
153+
t_empty = const
154+
```
155+
143156
More interesting is the \idr{update} function, which (as before) takes a map
144157
\idr{m}, a key \idr{x}, and a value \idr{v} and returns a new map that takes
145158
\idr{x} to \idr{v} and takes every other key to whatever \idr{m} does.
@@ -155,7 +168,7 @@ For example, we can build a map taking \idr{Id}s to \idr{Bool}s, where \idr{Id
155168
3} is mapped to \idr{True} and every other key is mapped to \idr{False}, like
156169
this:
157170

158-
\todo[inline]{Seems like an inconsistency in the book here}
171+
\todo[inline]{Seems like a wrong description in the book here}
159172

160173
> examplemap : total_map Bool
161174
> examplemap = t_update (MkId "foo") False $
@@ -208,7 +221,7 @@ $\square$
208221
==== Exercise: 2 stars, optional (t_update_neq)
209222

210223
On the other hand, if we update a map \idr{m} at a key \idr{x1} and then look up
211-
a different key \idr{x2} in the resulting map, we get the same result that
224+
a _different_ key \idr{x2} in the resulting map, we get the same result that
212225
\idr{m} would have given:
213226

214227
> t_update_neq : Not (x1 = x2) -> (t_update x1 v m) x2 = m x2
@@ -240,6 +253,8 @@ boolean function \idr{beq_id}.
240253
Use the proof of \idr{beq_natP} in chapter `IndProp` as a template to prove the
241254
following:
242255

256+
\todo[inline]{Copied \idr{Reflect} for now}
257+
243258
> data Reflect : Type -> Bool -> Type where
244259
> ReflectT : (p : Type) -> Reflect p True
245260
> ReflectF : (p : Type) -> (Not p) -> Reflect p False

0 commit comments

Comments
 (0)