diff options
Diffstat (limited to 'Common')
| -rw-r--r-- | Common/DayPart.lean | 12 | ||||
| -rw-r--r-- | Common/Helpers.lean | 2 | ||||
| -rw-r--r-- | Common/Option.lean | 7 |
3 files changed, 21 insertions, 0 deletions
diff --git a/Common/DayPart.lean b/Common/DayPart.lean new file mode 100644 index 0000000..c6a4d44 --- /dev/null +++ b/Common/DayPart.lean @@ -0,0 +1,12 @@ +namespace DayPart + +abbrev Days := {d : Nat // d > 0 ∧ d <= 25} +inductive Parts +| One +| Two + +class Parse (day : Days) {ι : outParam Type} where + parse : String → Option ι + +class Part (day : Days) (part : Parts) {ι ρ : outParam Type} [Parse day (ι := ι)] [ToString ρ] where + run : ι → Option ρ -- can fail, because it deals with user input... diff --git a/Common/Helpers.lean b/Common/Helpers.lean new file mode 100644 index 0000000..f57f826 --- /dev/null +++ b/Common/Helpers.lean @@ -0,0 +1,2 @@ +def curry (g : (α × β) → γ) : α → β → γ := λ a b ↦ g (a,b) +def uncurry (f : α → β → γ) : (α × β) → γ := λ (a,b) ↦ f a b diff --git a/Common/Option.lean b/Common/Option.lean new file mode 100644 index 0000000..23ea8d6 --- /dev/null +++ b/Common/Option.lean @@ -0,0 +1,7 @@ +namespace Option + +def zip (a : Option α) (b : Option β) : Option (α×β) := a >>= λ a ↦ b >>= λ b ↦ (a,b) + +def unzip : (a : Option (α×β)) → (Option α) × (Option β) +| none => (none, none) +| some (a, b) => (some a, some b) |
