我的代码如下:
type appointment=
|Probationary of int
|Fixed
type GradeLevel =
| Junior_Dev of appointment
| Dev
| Senior_Dev
| PM
| Architect of int
type person = {gradeLevel: GradeLevel ; title: string; salary: float; name: string}
let John_C = {gradeLevel=Dev; title="Hamster..."; salary= 3500000.0; name= "John Connor"}
let James_J = {gradeLevel=Junior_Dev (Probationary 3); title="Gofer"; salary= 3500000.0; name= "James Joyce"}
let splitter (EmpList: person list) =
let rec splitter remaining (j,d,s,p,a) = //HERE IS THE LINE OF THE ERROR
match remaining with
| [] -> (j,d,s,p,a)
| x::xs ->
match x.gradeLevel with
| Junior_Dev w -> splitter xs (x::j, d, s, p, a)
| Dev -> splitter xs (j, x::d, s, p, Arch)
| Senior_Dev -> splitter xs (j, d, x::s, p, a)
| PM -> splitter xs (j, d, s, x::p, a)
| Architect w -> splitter xs (j, d, s, p, x::a)
splitter EmpList ([],[],[],[],[])
我似乎无法在那条线上发现我的错误。 基本上是分配器:我想拿一个员工列表并返回一个带有Gradelevel列表的元组......所以我可以看到我所有的开发人员和PM分别使用这个功能。
你看错了什么?谢谢
答案 0 :(得分:0)
此代码为我编译:
type appointment=
| Probationary of int
| Fixed
type GradeLevel =
| Junior_Dev of appointment
| Dev
| Senior_Dev
| PM
| Architect of int
type person = {gradeLevel: GradeLevel ; title: string; salary: float; name: string}
let John_C = {gradeLevel=Dev; title="Hamster..."; salary= 3500000.0; name= "John Connor"}
let James_J = {gradeLevel=Junior_Dev (Probationary 3); title="Gofer"; salary= 3500000.0; name= "James Joyce"}
let splitter (EmpList: person list) =
let rec splitter remaining (j,d,s,p,a) =
match remaining with
| [] -> (j,d,s,p,a)
| x::xs ->
match x.gradeLevel with
| Junior_Dev w -> splitter xs (x::j, d, s, p, a)
| Dev -> splitter xs (j, x::d, s, p, a)
| Senior_Dev -> splitter xs (j, d, x::s, p, a)
| PM -> splitter xs (j, d, s, x::p, a)
| Architect w -> splitter xs (j, d, s, p, x::a)
splitter EmpList ([],[],[],[],[])
我用Arch
替换了原始代码中的a
。