【发布时间】:2020-02-26 05:45:39
【问题描述】:
这是 Coursera ProgLang 课程的作业,但截止日期已过,我只是在审核。这是一个非常便宜的问题,但看起来我无法在 SML 中做到这一点。
给定一个日期 3 元组 int 和一个 int 的列表,返回该 int 与元组的 #2 匹配的频率(月份)。
起初我有很多 [tycon mismatch],然后玩弄了函数头。我不知道如何表示一个元组列表,就这么简单。
fun number_in_month (date : [int*int*int], month : int) : int =
if hd date = []
then 0
else
if #2 hd date = month
then
1 + number_in_month tl date
else
0 + number_in_month tl date
不确定逻辑和 if then else if 构造。 AS到底是什么?
- use "hw1.sml";
[opening hw1.sml]
hw1.sml:13.26 Error: syntax error: replacing COLON with AS
val it = () : unit
13:26 是标题的第一个冒号。也许我也太麻木了,谷歌也没有找到任何有用的东西。
【问题讨论】:
标签: sml