Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. #nowarn "0042"
  2. let inline retype (x: 'T) : 'U = (# "" x: 'U #)
  3.  
  4. open System
  5. type Curry =
  6.  
  7. static member inline Invoke f =
  8. let inline call_2 (a: ^a, b: ^b) = ((^a or ^b) : (static member Curry: _*_ -> _) b, a)
  9. call_2 (Unchecked.defaultof<Curry>, Unchecked.defaultof<'t>) (f: 't -> 'r) : 'args
  10.  
  11. static member inline Curry (t: 't, _: Curry) = fun f t1 t2 t3 t4 t5 t6 t7 ->
  12. Curry.Invoke (fun tr ->
  13. let (t1: 't1) = if false then (^t : (member Item1 : 't1) t) else t1
  14. let (t2: 't2) = if false then (^t : (member Item2 : 't2) t) else t2
  15. let (t3: 't3) = if false then (^t : (member Item3 : 't3) t) else t3
  16. let (t4: 't4) = if false then (^t : (member Item4 : 't4) t) else t4
  17. let (t5: 't5) = if false then (^t : (member Item5 : 't5) t) else t5
  18. let (t6: 't6) = if false then (^t : (member Item6 : 't6) t) else t6
  19. let (t7: 't7) = if false then (^t : (member Item7 : 't7) t) else t7
  20. let (tr: 'tr) = if false then (^t : (member Rest : 'tr) t) else tr
  21. f (Tuple<_,_,_,_,_,_,_,_>(t1, t2, t3, t4, t5, t6, t7, tr) |> retype))
  22.  
  23. static member Curry (x: Tuple<'t1> , _: Curry) = fun f t1 -> f (Tuple<_> t1)
  24. static member Curry ((t1, t2) , _: Curry) = fun f t1 t2 -> f (t1, t2)
  25. static member Curry ((t1, t2, t3) , _: Curry) = fun f t1 t2 t3 -> f (t1, t2, t3)
  26. static member Curry ((t1, t2, t3, t4) , _: Curry) = fun f t1 t2 t3 t4 -> f (t1, t2, t3, t4)
  27. static member Curry ((t1, t2, t3, t4, t5) , _: Curry) = fun f t1 t2 t3 t4 t5 -> f (t1, t2, t3, t4, t5)
  28. static member Curry ((t1, t2, t3, t4, t5, t6) , _: Curry) = fun f t1 t2 t3 t4 t5 t6 -> f (t1, t2, t3, t4, t5, t6)
  29. static member Curry ((t1, t2, t3, t4, t5, t6, t7), _: Curry) = fun f t1 t2 t3 t4 t5 t6 t7 -> f (t1, t2, t3, t4, t5, t6, t7)
  30.  
  31. let inline curry f t = Curry.Invoke f t
  32.  
  33.  
  34. ///////////
  35. // TESTS //
  36. ///////////
  37.  
  38. let f2 (x, y) = [x + y]
  39. let f3 (x, y, z) = [x + y + z]
  40. let f7 (t1, t2, t3, t4, t5, t6, t7) = [t1+t2+t3+t4+t5+t6+t7]
  41. let f8 (t1, t2, t3, t4, t5, t6, t7: float, t8: char) = [t1+t2+t3+t4+t5+t6+ int t7 + int t8]
  42. let f9 (t1, t2, t3, t4, t5, t6, t7: float, t8: char, t9: decimal) = [t1+t2+t3+t4+t5+t6+ int t7 + int t8+ int t9]
  43. let f15 (t1, t2, t3, t4, t5, t6, t7: float, t8: char, t9: decimal, t10, t11, t12, t13, t14, t15) = [t1+t2+t3+t4+t5+t6+ int t7 + int t8+ int t9+t10+t11+t12+t13+t14+t15]
  44. let f16 (t1, t2, t3, t4, t5, t6, t7: float, t8: char, t9: decimal, t10, t11, t12, t13, t14, t15, t16) = [t1+t2+t3+t4+t5+t6+ int t7 + int t8+ int t9+t10+t11+t12+t13+t14+t15+t16]
  45. let f17 (t1, t2, t3, t4, t5, t6, t7: float, t8: char, t9: decimal, t10, t11, t12, t13, t14, t15, t16, t17) = [t1+t2+t3+t4+t5+t6+ int t7 + int t8+ int t9+t10+t11+t12+t13+t14+t15+t16+t17]
  46. let f1 (x:Tuple<_>) = [x.Item1]
  47.  
  48. let x2 = curry f2 1 2
  49. let x3 = curry f3 1 2 3
  50. let x7 = curry f7 1 2 3 4 5 6 7
  51. let x8 = curry f8 1 2 3 4 5 6 7. '8'
  52. let x9 = curry f9 1 2 3 4 5 6 7. '8' 9M
  53. let x15 = curry f15 1 2 3 4 5 6 7. '8' 9M 10 11 12 13 14 15
  54. let x16 = curry f16 1 2 3 4 5 6 7. '8' 9M 10 11 12 13 14 15 16
  55. let x17 = curry f17 1 2 3 4 5 6 7. '8' 9M 10 11 12 13 14 15 16 17
  56. let x1 = curry f1 100
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement