forked from nicolas-van/bootstrap-4-github-pages
-
Notifications
You must be signed in to change notification settings - Fork 5
/
exercises.gr
44 lines (29 loc) · 1.26 KB
/
exercises.gr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
-- # Exercises
-- ## Ex 1 Make the following functions typecheck by addition of
-- graded modalities at the type level only where needed and the
-- relevant unboxing pattern matches at the value level. Give the most
-- precise type.
-- const : forall {a c : Type} . a -> (c -> a)
-- const x y = x
-- ap : forall {a b c : Type}. (c -> a -> b) -> (c -> a) -> (c -> b)
-- ap f x ctx = f ctx (x ctx)
-- Consider which particular graded modality to use. Hint: try a
-- Nat-graded modality first. Advanced: Can you make it polymorphic
-- in the coeffect grade?
-- ## Ex 2
-- Consider the following definition:
import Bool
copyBool : Bool -> (Bool, Bool)
copyBool False = (False, False);
copyBool True = (True, True)
-- Why does `copyBool` not violate linearity?
-- ## Ex 3
-- Write a well-typed short-circuiting version of `and` on `Bool`
-- i.e., where `and False x` need not inspect the value of `x`.
-- ## Ex 4 Inductive families and grading
-- Define an indexed data type 'ABList' that has two cons cells for
-- 'a' elements and 'b' elements, i.e., with the header:
-- data ABList (a : Type) (b : Type) : Nat -> Nat -> Type where
-- Define the `map` function for ABList which takes two function
-- parameters for the `a` and `b` elements, with precise usage on
-- each.