1 / 12

hw3作业分析

hw3作业分析. 郁翔 5110379091. 主要内容. 作业大致情况 题目回顾与答案分享. 作业大致情况. 共21人提交了作业,1人没提交test,以后记得提交test 有5名同学完成了Challenge. 题目回顾与答案分享. all_answers: 根据题意一种一种情况分析返回即可。 fun all_answers(f) (ls) = case ls of [] => SOME [] | xs :: tls => case f(xs) of NONE => NONE

xena
Download Presentation

hw3作业分析

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. hw3作业分析 郁翔 5110379091

  2. 主要内容 • 作业大致情况 • 题目回顾与答案分享

  3. 作业大致情况 • 共21人提交了作业,1人没提交test,以后记得提交test • 有5名同学完成了Challenge

  4. 题目回顾与答案分享 all_answers: 根据题意一种一种情况分析返回即可。 fun all_answers(f) (ls) = case ls of [] => SOME [] | xs :: tls => case f(xs) of NONE => NONE | SOME xls => case all_answers(f) (tls) of NONE => NONE | SOME yls => SOME (xls @ yls)

  5. 题目回顾与答案分享 • challenge没什么人做。 • 题目读不懂?

  6. Challenge题意分析1 • 这道题可以想像成你在开发一个type inference系统,那么当你碰到 • case x of • p1 => e1 • | p2 => e2 • … • | pn => en • 这样的case语句的时候,你需要从p1,p2,…,pn这个pattern list中推导出x的类型。这个pattern list就是第二个参数。

  7. Challenge题意分析2 假设有这么一段代码: case pt of x => ... (*Pattern为Variable "x"*) | _ => ... (*Pattern为Wildcard*)

  8. Challenge题意分析3 • pdf原文: For example, given patterns TupleP[Variable("x"),Variable("y")] and TupleP[Wildcard,Wildcard], return TupleT[Anything,Anything] • 简化版运行情况: - typecheck_patterns([],[Variable "x",Wildcard]); val it = SOME Anything : typ option

  9. Challenge题意分析4 case pt of (_,_) => ... (*Pattern为TupleP[Wildcard,Wildcard]*) | (_,(_,_)) => ... (*Pattern为TupleP[Wildcard,TupleP[Wildcard,Wildcard]]*) Challenge Return:TupleT[Anything,TupleT[Anything,Anything]] (*虽然实际上不能这么写,如果这么写会出现stdIn:16.1-17.16 Error: match redundant*)

  10. Challenge题意分析5 ((string*string*typ)list)*(pattern list)->typ option ??? (string*string*typ) list ??? [("wild","blue",IntT),("plain","blue",UnitT)] datatype blue = wild of int | plain of unit; case pt of wild 4 => ... (*ConstructorP ("wild", ConstP 4)*) | plain unit => ... (*ConstructorP("plain", UnitP)*)

  11. Challenge • 大家都理解题目了吗? • 有兴趣的同学回去可以再做做看。

  12. 谢谢大家

More Related