Advertisement
Guest User

F# example

a guest
Sep 24th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.09 KB | None | 0 0
  1. type MyUnion =
  2. | First of int
  3. | Second of double
  4.  
  5. type MyRecord = {
  6.     A: int
  7.     B: double
  8.     C: MyUnion
  9. }
  10.  
  11. let test (a: MyRecord) (b: int) =
  12.   let c: double = 1.0
  13.   ()
  14.  
  15. let test a = async {
  16.     return a;
  17. }
  18. let test a = foobar {
  19.     return a;
  20. }
  21.  
  22. // Mass, grams.
  23. [<Measure>] type g
  24. // Mass, kilograms.
  25. [<Measure>] type kg
  26.  
  27. [<DllImport("kernel32", SetLastError=true)>]
  28.  
  29.  
  30. let func : HttpFunc = handler (Some >> Task.FromResult)
  31.  
  32. type Base1() =
  33.     abstract member F : unit -> unit
  34.     default u.F() =
  35.         printfn "F Base1"
  36.  
  37. type Derived1() =
  38.     inherit Base1()
  39.     override u.F() =
  40.         printfn "F Derived1"
  41.  
  42. let d1 : Derived1 = Derived1()
  43.  
  44. let base1 = d1 :> Base1
  45. let derived1 = base1 :?> Derived1
  46.  
  47. type PersonName =
  48.     | FirstOnly of string
  49.     | LastOnly of string
  50.     | FirstLast of string * string
  51.  
  52. type Shape =
  53.     | Rectangle of height : float * width : float
  54.     | Circle of radius : float
  55.  
  56. type MyInterface =
  57.    abstract member Add: int -> int -> int
  58.    abstract member Pi : float
  59.  
  60. exception Error1 of string
  61. exception Error2 of string * int
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement