defined trait Expr defined trait Uop defined trait Bop defined class Unary defined class Binary defined class N defined object Neg defined object Plus
Thursday, October 10, 2024
What questions does your neighbor have?
Consider generic binary operator #
and $
. What does
1 # 2 # 3 $ 4
evaluate to?
\[ e \longrightarrow e' \]
Expression \(e\) can take one step of evaluation to expression \(e'\).
\(\inferrule[DoNeg]{ n' = - n_1 }{ \mathop{\texttt{-}} n_1 \longrightarrow n' }\)
\(\inferrule[SearchNeg]{ e_1 \longrightarrow e_1' }{ \mathop{\texttt{-}} e_1 \longrightarrow\mathop{\texttt{-}} e_1' }\)
defined trait Expr defined trait Uop defined trait Bop defined class Unary defined class Binary defined class N defined object Neg defined object Plus
defined function isValue
e_oneplustwoplusthreeplusfour: Binary = Binary( bop = Plus, e1 = Binary(bop = Plus, e1 = N(n = 1.0), e2 = N(n = 2.0)), e2 = Binary(bop = Plus, e1 = N(n = 3.0), e2 = N(n = 4.0)) )
defined function step
scala.NotImplementedError: an implementation is missing scala.Predef$.$qmark$qmark$qmark(Predef.scala:345) ammonite.$sess.cmd3$Helper.step(cmd3.sc:3) ammonite.$sess.cmd4$Helper.<init>(cmd4.sc:2) ammonite.$sess.cmd4$.<clinit>(cmd4.sc:7)
Calling step(e_oneplustwoplusthreeplusfour)
corresponds to a witness of the judgment
\[ (1 \mathbin{\texttt{+}} 2) \mathbin{\texttt{+}} (3 \mathbin{\texttt{+}} 4) \longrightarrow 3 \mathbin{\texttt{+}} (3 \mathbin{\texttt{+}} 4) \]
------------------------------------------------ DoPlus
Binary(Plus,N(1.0),N(2.0)) ---> N(3.0)
------------------------------------------------ SearchPlus1
Binary(Plus,Binary(Plus,N(1.0),N(2.0)),Binary(Plus,N(3.0),N(4.0))) ---> Binary(Plus,N(3.0),Binary(Plus,N(3.0),N(4.0)))
defined function step res5_1: Expr = Binary( bop = Plus, e1 = N(n = 3.0), e2 = Binary(bop = Plus, e1 = N(n = 3.0), e2 = N(n = 4.0)) )
\[ \begin{array}{rrrl} \text{values} & v& \mathrel{::=}& n\mid b \end{array} \]
defined class B
defined function isValue
e_true: B = B(b = true) e_trueplustwo: Binary = Binary(bop = Plus, e1 = B(b = true), e2 = N(n = 2.0))
\[ \begin{array}{rrrl} \text{step-results} & r& \mathrel{::=}& \mathop{\mathsf{typeerror}}e \mid e' \end{array} \]
defined class DynamicTypeError defined type Result
\[ \fbox{$e \longrightarrow r$} \]
\(\inferrule[DoNeg]{ }{ \mathop{\texttt{-}} n_1 \longrightarrow- n_1 }\)
\(\inferrule[TypeErrorNeg]{ v_1 \neq n_1 }{ \mathop{\texttt{-}} n_1 \longrightarrow \mathop{\mathsf{typeerror}}(\mathop{\texttt{-}} n_1) }\)
\(\inferrule[SearchNeg]{ e_1 \longrightarrow e_1' }{ \mathop{\texttt{-}} e_1 \longrightarrow\mathop{\texttt{-}} e_1' }\)
defined function step
\(\inferrule[SearchBinary1]{ e_1 \longrightarrow e_1' }{ e_1 \mathbin{\mathit{bop}}e_2 \longrightarrow e_1' \mathbin{\mathit{bop}}e_2 }\)
\(\inferrule[SearchBinary2]{ e_2 \longrightarrow e_2' }{ v_1 \mathbin{\mathit{bop}}e_2 \longrightarrow v_1 \mathbin{\mathit{bop}}e_2' }\)
Shadowing \[ [\underbrace{\texttt{2}}_{e_1} /\underbrace{\texttt{a}}_{x} ] \underbrace{(\texttt{const a = 1; a + b})}_{e_2} = (\texttt{const a = 1; a + b}) \]
Free-Variable Capture
\[ [\underbrace{\texttt{(a + 2)}}_{e_1} /\underbrace{\texttt{b}}_{x} ] \underbrace{(\texttt{const a = 1; a + b})}_{e_2} = (\texttt{const c = 1; c + (a + 2)}) \]