Skip to content

Commit

Permalink
simplify dependent Message code slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
sullyj3 committed Jul 29, 2024
1 parent a520477 commit c2fdbea
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/Sand/Message.lean
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,22 @@ inductive ResumeTimerResponse
| alreadyRunning
deriving Repr, ToJson, FromJson

def ResponseFor : Command → Type
abbrev ResponseFor : Command → Type
| .addTimer _ => AddTimerResponse
| .list => ListResponse
| .cancelTimer _ => CancelTimerResponse
| .pauseTimer _ => PauseTimerResponse
| .resumeTimer _ => ResumeTimerResponse

def toJsonResponse {cmd : Command} (resp : ResponseFor cmd) : Lean.Json := by
cases cmd <;> (
simp only [ResponseFor] at resp
exact toJson resp
)
cases cmd <;> exact toJson resp

def serializeResponse {cmd : Command} (resp : ResponseFor cmd) : ByteArray :=
String.toUTF8 <| toString <| toJsonResponse resp

def fromJsonResponse? {cmd : Command}
(resp : Json) : Except String (ResponseFor cmd) := by
cases cmd <;> (
simp only [ResponseFor]
exact fromJson? resp
)
cases cmd <;> exact fromJson? resp


end Sand

0 comments on commit c2fdbea

Please sign in to comment.