0

my code is the following :

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 ([],[],[],[],[])

I can't seem to find out my error on that line. Basically with splitter: I want to take an employee list and return a tuple with Gradelevel lists...So I could see all my developers and PM seperately using this function.

Anything you see wrong? Thank you

  • I suspect the indentation level of the call to `splitter` is wrong. Make sure it is at the same level as the definition of `splitter`. – Lee Nov 09 '14 at 18:06
  • Check whitespaces - maybe you misaligned 'let rec...' and call of 'splitter' – Petr Nov 09 '14 at 18:07
  • 1
    Unable to reproduce; the only error I get when pasting this is that `Arch` is undefined. I can't help but notice that your use of whitespace is very inconsistent. Only the offsets of the `GradeLevel` cases and the `match x.gradeLevel` scope follow standard F# formatting. As Lee and Petr said, this is likely to be a problem with indentation. – Vandroiy Nov 09 '14 at 18:20

1 Answers1

0

This code compiles for me:

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 ([],[],[],[],[])

I replaced Arch in the original code with a.

Gus
  • 25,839
  • 2
  • 51
  • 76