Advertisement
Guest User

titsorgtfo

a guest
Oct 23rd, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.06 KB | None | 0 0
  1. //1.1
  2. type DepartmentName = string
  3. type GrossIncome = int
  4. type TotalIncome = int
  5. type Department = Dep of DepartmentName * Department List * GrossIncome
  6.  
  7. let d1 = Dep("SashaGrey", [], 100)
  8. let d2 = Dep("TorriBlack", [d1], 200)
  9. let d3 = Dep("FayeReagan", [d2], 300)
  10. let d4 = Dep("KatjaKeen", [], 100)
  11. let d5 = Dep("BellaKnox", [], 100)
  12. let d6 = Dep("JenniferLawrence",[],100)
  13. let dlist = [d4;d5;d6]
  14. let d8 = Dep("SkinDiamond",dlist, 700)
  15.  
  16. //1.2 extension type Department with GrossIncome
  17.  
  18. //1.3 -> map(DepartmentName*GrossIncome)
  19. //1.3.1
  20. //:Department -> (DepartmentName*GrossIncome) List
  21. let rec ePaG = function
  22.     |Dep(name,[],income)         -> [(name,income)]
  23.     |Dep(name,[x],income)        -> [(name,income)]@(ePaG x)
  24.     |Dep(name,dep::dList,income) -> (ePaG dep)@(ePaG (Dep(name,dList,income)))
  25.  
  26.  
  27.  
  28.  
  29. //Test 1.3.1
  30. let t131d3 = ePaG d3
  31. let t131d8 = ePaG d8
  32.  
  33. //1.3.2 (Bare fordi jeg kan)
  34. let rec extractPairsAndGross = function
  35.     |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