How to copy the result of the Identifier template into a template to make a tuple?
My question is confusing, so I created an example, I want to print information about a person who is either a teacher or a student:
type Person =
| Teacher of name: string * age: int * classIds: int list
| Student of name: string
let printTeacher (name, age, classIds) =
printfn "Teacher: %s; Age: %d; Classes: %A" name age classIds
let print = function
| Teacher (name, age, classIds) -> printTeacher (name, age, classIds)
| Student name -> printfn "Student: %s" name
The corresponding pattern is long and repeating:
| Teacher (name, age, classIds) -> printTeacher (name, age, classIds)
So, I tried to shorten it with a template as
, but failed:
| Teacher ((_, _, _) as teacher) -> printTeacher teacher
Because the above teacher
is of type Person
, not string*int*int list
. What to do to have a shorter template without changing the printTeacher
type signature string*int*int list -> unit
?
source
share