enum Post
case Text(msg:String)() // Extra () = No dependence on other Posts.
case Image(img:JPEG)()
case Repost(msg:String)(previous:Post)
case Compare(msg:String)(left:Post, right:Post)empty array to empty array
text("Hi!")
text("Hi!")
Recursion
Base Case
(\(\mathbb{P}\)-elimination)
empty array to empty array
text("Hi!")
text("Hi!")
Hi!
{ "text": "Hi!" }
Yes "Hi!" is variable but it is of type String, not \(\mathbb{P}\) nor \(\mathbb{JSON}\) so consider it constant for these semantics.
empty array to empty array
text("Hi!")
text("Hi!")
encode
(\(\mathbb{P}\)-elimination)
empty array to empty array
text("Hi!")
text("Hi!")
Hi!
{ "text": "Hi!" }
def encode( p : Post) :JSON =
p match {
case Text(msg)() =>
return "{\"text\": " + msg + " }"
}\[\frac{\Gamma\vdash \text{text(msg)}}{\text{encode}(text(msg)) := \text{\{``text'': msg\}}}\]
encode(p)
repost("Wow!")
repost("Wow!")
Recursion
Inductive Hypothesis
(\(\mathbb{P}\)-elimination)
encode(p)
repost("Wow!")
repost("Wow!")
Wow!
{"repost": {
"text": "Wow!",
"post": {...}}}
Text
def encode( p : Post) :JSON =
p match {
case Text(msg)() =>
return "{\"text\": " + msg + " }"
case Repost(msg)(prev:Post) =>
return "{\"repost: {\n\t \"text\":"
+ msg +",\n\t\"post\":"
+ encode(p) + "}\n}"
}\[\frac{\Gamma\vdash msg:\text{String}, p:\mathbb{P}}{\text{encode}(repost(msg)(p)) := \text{\{``repost'': {...\}}}}\]
encode(p)
repost(msg)
repost(msg)
encode
(\(\mathbb{P}\)-elimination)
encode(p)
repost(msg)
repost(msg)
msg
p
p