Re: [问题] FLOLAC op semantics 作业

楼主: yzugsr (miaout17)   2010-07-04 14:14:12
我人在外面,手边没有OCmal或作业的code
试着凭印像回答看看,有错请见谅
显然ns st1 s会回传一个config
而且依照ns的定义 他一定会回传一个Final s, 而非Inter (st, s)
所以你要对ns st1 s的回传值先做一次pattern matching
let c1 = ns st1 s
in match c1 with Final s -> ??????
(因为是作业,我就不写完了,请自行补完)
好像可以简写成(不太确定)
match (ns st s) with Final s -> ??????
这样好像也可以(不太确定)
let Final s1 = ns st s
in ??????
这样compiler都会喷一个warning:
“pattern matching不完全,如果是Inter (st, s)可能会当掉喔,啾咪^_^”
可是程式还是可以run
觉得compiler很吵可以定一个InvalidConfig的exception
match ???????
| Inter (_,_) -> throw InvalidConfig
不然还有一招,定一个 statement -> state -> state 的辅助函式
上一篇的ns差不多就是这个用途
但你可以试着把ns改个名字(exec_stmt?)
然后用试着让ns用正确的型别 (conf->conf),透过exec_stmt把逻辑串起来

Links booklink

Contact Us: admin [ a t ] ucptt.com