Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1.1
- type DepartmentName = string
- type GrossIncome = int
- type TotalIncome = int
- type Department = Dep of DepartmentName * Department List * GrossIncome
- let d1 = Dep("SashaGrey", [], 100)
- let d2 = Dep("TorriBlack", [d1], 200)
- let d3 = Dep("FayeReagan", [d2], 300)
- let d4 = Dep("KatjaKeen", [], 100)
- let d5 = Dep("BellaKnox", [], 100)
- let d6 = Dep("JenniferLawrence",[],100)
- let dlist = [d4;d5;d6]
- let d8 = Dep("SkinDiamond",dlist, 700)
- //1.2 extension type Department with GrossIncome
- //1.3 -> map(DepartmentName*GrossIncome)
- //1.3.1
- //:Department -> (DepartmentName*GrossIncome) List
- let rec ePaG = function
- |Dep(name,[],income) -> [(name,income)]
- |Dep(name,[x],income) -> [(name,income)]@(ePaG x)
- |Dep(name,dep::dList,income) -> (ePaG dep)@(ePaG (Dep(name,dList,income)))
- //Test 1.3.1
- let t131d3 = ePaG d3
- let t131d8 = ePaG d8
- //1.3.2 (Bare fordi jeg kan)
- let rec extractPairsAndGross = function
- |Dep(name,dList,income) -> (name,income)::(List.foldBack(fun x list -> extractPairsAndGross(x)@list) dList [])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement