number_in_month 练习(从元组列表构建整数列表的 SML 函数错误) [英] number_in_month exercise (Error in SML function to build a list of integers from a list of tuples)
本文介绍了number_in_month 练习(从元组列表构建整数列表的 SML 函数错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
val test1 = [(1,5,3),(3,5,2),(3,4,5)]
fun number_in_month dates_and_month =
case dates_and_month of
(x,y,z)::xs' => y :: number_in_month xs'
当我使用 test1 在 REPL 中运行时,此代码会产生以下错误:
This code produces the following error when I run in the REPL with test1:
未捕获的异常匹配[非穷举性匹配失败]提出于:hw1pm.sml:28.49
uncaught exception Match [nonexhaustive match failure] raised at: hw1pm.sml:28.49
知道为什么吗?
推荐答案
当列表为空时不知道做什么.
It did not know what do when the list was empty.
工作代码:
fun number_in_month dates_and_month =
case dates_and_month of
[] => []
| (x,y,z)::xs' => y :: number_in_month xs'
这篇关于number_in_month 练习(从元组列表构建整数列表的 SML 函数错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文