Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. type LineItem = {Cost: decimal option; Price: decimal option; Qty: decimal option}
  2.  
  3. let discount = 0.25M
  4.  
  5. let createItem (c, p, q) =
  6. {Cost = c; Price = p; Qty = q}
  7.  
  8. let items =
  9. [
  10. (Some 1M , None , Some 1M)
  11. (Some 3M , Some 2.0M , None)
  12. (Some 5M , Some 3.0M , Some 5M)
  13. (None , Some 1.0M , Some 2M)
  14. (Some 11M , Some 2.0M , None)
  15. ]
  16. |> List.map createItem
  17.  
  18. items
  19. |> Seq.map (fun line -> line.Price
  20. |> Option.map (fun x -> discount * x))
  21.  
  22. val it : seq<decimal option> =
  23. seq [null; Some 0.500M; Some 0.750M; Some 0.250M; ...]
  24.  
  25. items
  26. |> Seq.map (fun line -> line.Price
  27. |> Option.map (fun x -> discount * x)
  28. |> Option.map (fun x -> x - (line.Cost
  29. |> Option.map (fun x -> x)))
  30. |> Option.map (fun x -> x * (line.Qty
  31. |> Option.map (fun x -> x))))
  32.  
  33. error FS0001: Type constraint mismatch. The type
  34. 'a option
  35. is not compatible with type
  36. decimal
  37. The type ''a option' is not compatible with the type 'decimal'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement