
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Dynamic semantics  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% The definitions in this file do *not* strictly correspond to any specific
% code in GHC. They are here to provide a reasonable operational semantic
% interpretation to the typing rules presented in the other ott files. Thus,
% your mileage may vary. In particular, there has been *no* attempt to
% write any formal proofs over these semantics.
%
% With that disclaimer disclaimed, these rules are a reasonable jumping-off
% point for an analysis of FC's operational semantics. If you don't want to
% worry about mutual recursion (and who does?), you can even drop the
% environment S.
%
% Join points are ignored here because operationally they work exactly the same
% as regular bindings. Simply read "join" as "let" and "jump" as application to
% see how a (well-typed!) program should run.

grammar

defns
OpSem :: '' ::=

defn e --> e'  ::  :: step :: 'S_' {{ com Single step semantics }}
{{ tex \begin{array}{l} [[e]] [[-->]] [[e']] \end{array} }}
by

e1 --> e1'
------------------- :: App
e1 e2 --> e1' e2

----------------------------- :: Beta
(\n.e1) e2 --> e1[n |-> e2]

g0 = sym (nth 0 g)
g1 = nth 1 g
not e2 is_a_type
not e2 is_a_coercion
----------------------------------------------- :: Push
((\n.e1) |> g) e2 --> (\n.e1 |> g1) (e2 |> g0)

---------------------------------------- :: TPush
((\n.e) |> g) t --> (\n.(e |> g n)) t

g0 = nth 1 (nth 0 g)
g1 = sym (nth 2 (nth 0 g))
g2 = nth 1 g
------------------------------- :: CPush
((\n.e) |> g) g' --> (\n.e |> g2) (g0 ; g' ; g1)

--------------------------------------- :: Trans
(e |> g1) |> g2 --> e |> (g1 ; g2)

e --> e'
------------------------ :: Cast
e |> g --> e' |> g

e --> e'
------------------------------ :: Tick
e { tick } --> e' { tick }

e --> e'
--------------------------------------- :: Case
case e as n return t of </ alti // i /> --> case e' as n return t of </ alti // i />

altj = K </ alphabb_kbb // bb /> </ xcc_tcc // cc /> -> u
e = K </ t'aa // aa /> </ sbb // bb /> </ ecc // cc />
u' = u[n |-> e] </ [alphabb_kbb |-> sbb] // bb /> </ [xcc_tcc |-> ecc] // cc />
-------------------------------------------------------------- :: MatchData
case e as n return t of </ alti // i /> --> u'

altj = lit -> u
---------------------------------------------------------------- :: MatchLit
case lit as n return t of </ alti // i /> --> u[n |-> lit]

altj = _ -> u
no other case matches
------------------------------------------------------------ :: MatchDefault
case e as n return t of </ alti // i /> --> u[n |-> e]

T </ taa // aa /> k'~#k T </ t'aa // aa /> = coercionKind g
forall </ alphaaa_kaa // aa />. forall </ betabb_k'bb // bb />. </ t1cc // cc /> $ -> T </ alphaaa_kaa // aa /> = dataConRepType K
</ e'cc = ecc |> (t1cc $ </ [alphaaa_kaa |-> nth aa g] // aa /> </ [betabb_k'bb |-> <sbb>_Nom] // bb />) // cc />
--------------------------- :: CasePush
case (K </ taa // aa /> </ sbb // bb /> </ ecc // cc />) |> g as n return t2 of </ alti // i /> --> \\ case K </ t'aa // aa /> </ sbb // bb /> </ e'cc // cc /> as n return t2 of </ alti // i />

----------------- :: LetNonRec
let n = e1 in e2 --> e2[n |-> e1]

------------------------------------ :: LetRec
let rec </ ni = ei // i /> in u --> u </ [ni |-> let rec </ ni = ei // i /> in ei ] // i />

