【发布时间】:2015-03-20 06:23:03
【问题描述】:
我有一个列表,例如
let stdCourseList = [(10,[100;101;102]); (11,[101]); (14,[]); (12,[100;101])];;
这是一个包含学生 ID 和课程 ID 的列表
我想实现一个能够计算学生所学课程数量的函数。 比如我这样做
numbOfCourse(stdCourseList,10)
我会得到 3,因为 id 为 10 的学生参加了 3 门课程
到目前为止,我有这个代码:
let rec numbOfCourse = function
|(([], id)) -> 0
|(((id2:int,(y:int)::ys)::xs),id) ->
if id=id2 then 1 //should a code to count the list of the course
else numbOfCourse(xs,id);;
但是当我运行它时,我得到了这个错误
let rec numbOfCourse = function
------------------------^^^^^^^^
stdin(1471,25): warning FS0025: Incomplete pattern matches on this
expression. For example, the value '([(_,[])],_)' may indicate a case not
covered by the pattern(s).
我真的不明白为什么会出现此错误以及错误的含义。有人可以帮我解释一下吗?处理嵌套列表的最佳方法是什么?
这部分错了吗?
(((id2:int,(y:int)::ys)::xs),id)
谢谢。
【问题讨论】: