Discriminated unions with record types

  • Thread starter Thread starter CrazyVibe
  • Start date Start date
C

CrazyVibe

Guest
Hello!

I am currently new in f# and I am struggling with a problem in regards to the matching pattern which concerns some record types.Basically I have a department and a program.Each student must be assign a department considering the program where they have the biggest rate of success.I declared the union types and the record type along with creating some students to test it out.

type Department = | DEPX | depy | depz | depa| depb | depc
let departments = [DEPX; depy; depz; depa; depb; depc]


type Program={Programming:int;Innovative:int;Social:int;Devoted:int;Kind:int}
//create type NongrupedStudent as a record with values
type NonGroupedStudent={Name:string;Age:int;Epoint:int;P:Program}



My only problem is that I have tried to match the students with the appropriate program and then assign them into a department like this:

let matchStudent(student:NonGroupedStudent) =
match student with

|Department.depa when student.P.Programming


let matchProgram (program:Department) =
match program with
|Department.depx->NonGroupedStudent.P.Programming


I simply don't understand the logic...I have looked over there examples to clarify my problem but the examples online are not quite what I am looking for.

Parallax Scrolling, Java Cryptography, YAML, Python Data Science, Java i18n, GitLab, TestRail, VersionOne, DBUtils, Common CLI, Seaborn, Ansible, LOLCODE, Current Affairs 2018, Apache Commons Collections

fsharp-cheatsheet

F# Pattern Matching – Part 1 – Introduction

A data model exercise in two languages, part 2: F#

Can someone please help me in figuring out how should i start with the matching pattern for the nongroupedstudent and what should i take into consideration?Any help will be appreciated!

Best regards,

Maria

Continue reading...
 
Back
Top