这次回顾HW0,主要是环境配置和熟悉提交作业的流程。

课程主页:

https://www.coursera.org/learn/programming-languages/home

B站搬运:

https://www.bilibili.com/video/BV1dL411j7L7

Homework 0

这次作业比较简单,只要将加法修改为乘法即可:

(* Dan Grossman, Coursera PL, HW0 Provided Code *)

(* The line below is wrong -- replacing the addition, +, with
multiplication, *, will fix it *)
fun f(x,y) = x * y

(* Do not change these: They should be correct after fixing the code above *)

fun double x = f(x,2)

fun triple x = f(3,x)

比较重要的是测试文件的使用方式:需要在test.sml文件开头增加use "homeworkname.sml";部分:

(* Homework0 Simple Test *)

(* These are basic test cases. Passing these tests does not guarantee that your code will pass the actual homework grader *)
(* To run the test, add a new line to the top of this file: use "homeworkname.sml"; *)
(* All the tests should evaluate to true. For example, the REPL should say: val test1 = true : bool *)
use "01_homework-0-auto-grader_hw0provided.sml";

val test1 = double 17 = 34

val test2 = double 0 = 0

val test3 = triple ~4 = ~12

val test4 = triple 0 = 0

val test5 = f(12,27) = 324

(* You can add more tests here, for example you can uncomment the line below
by deleting the first two character and last two characters on the line *)

(* val test6 = triple ~1 = ~3 *)

测试方式:

λ sml 01_homework-0-auto-grader_hw0test.sml                                                                     

REM sml.bat

REM

REM Copyright 2020 The Fellowship of SML/NJ (http://www.smlnj.org)

REM All rights reserved.

REM

REM The standard driver for SML/NJ under the new runtime system

REM
Standard ML of New Jersey (32-bit) v110.99.2 [built: Tue Sep 28 13:04:14 2021]
[opening 01_homework-0-auto-grader_hw0test.sml]
[opening 01_homework-0-auto-grader_hw0provided.sml]
val f = fn : int * int -> int
val double = fn : int -> int
val triple = fn : int -> int
val it = () : unit
val test1 = true : bool
val test2 = true : bool
val test3 = true : bool
val test4 = true : bool
val test5 = true : bool

可以看到test均为true,说明测试通过。