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