Control 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. Types
  2. -----
  3. |<a>| = a task that, when run, produces a value of type 'a
  4. a |->| b = an operation that, when run with a value of type 'a, produces a value
  5. of type 'b
  6. a |->| b ~ a -> |<b>|
  7. 0 |->| a ~ |<a>|
  8. Primitives
  9. ----------
  10. task : (a -> b) * a -> |<b>|
  11. task : (0 -> a) -> |<a>|
  12. return : a -> |<a>|
  13. func : (a -> b) -> (a |->| b)
  14. app : (a |->| b) * a -> |<b>|
  15. dynamic : (a -> |<b>|) -> (a |->| b)
  16. ignore : |<b>| -> (a |->| b)
  17. nop : |<'nop'>|
  18. id : a |->| a
  19. return(x) = task(fun() -> x end)
  20. app(func(f), x) = task(f, x)
  21. dynamic(fun(X) -> return(f(x)) end) = func(f)
  22. ignore(x) = dynamic(fun(_) -> x)
  23. nop = return('nop')
  24. id = func(fun(X) -> X)
  25. cannot construct an element of type 0 |->| a.
  26. Pipelines
  27. ---------
  28. pipe : (a |->| b) * (b |->| c) -> (a |->| c)
  29. pipe : [ a_1 |->| a_2, a_2 |-> a_3, ..., a_n-1 |->| a_n ] -> (a_1 |->| a_n)
  30. bind : |<a>| * (a -> |<b>|) -> |<b>|
  31. feed : |<a>| * (a |->| b) -> |<b>|
  32. sequence : |<a>| * |<b>| -> |< [a, b] >|
  33. sequence : [ |<a_1>|, |<a_2>|, ..., |<a_n>| ] -> |< [a_1, a_2, ..., a_n] >|
  34. pipe(f_1, pipe(f_2, ...f_n...)) = pipe([f_1, f_2, ..., f_n])
  35. pipe(pipe(f, g), h) = pipe(f, pipe(g, h))
  36. pipe(id, f) = f
  37. pipe(f, id) = f
  38. bind(bind(x, f), g) = bind(x, fun(X) -> bind(f X, g) end)
  39. bind(x, return) = x
  40. bind(return(x), f) = f x
  41. feed(x, dynamic(f)) = bind(x, f)
  42. Scattering
  43. ----------
  44. scatter : |<a>| * |<b>| -> |< [a, b] >|
  45. scatter : [ |<a_1>|, |<a_2>|, ..., |<a_n>| ] -> |< [a_1, a_2, ..., a_n] >|
  46. parallel : (a |->| a') * (b |->| b') -> ([a, b] |-> [a', b'])
  47. parallel : [ a_1 |->| a_1', a_2 |->| a_2', ..., a_n |->| a_n' ]
  48. -> ([a_1, a_2, ..., a_n] |->| [a_1', a_2', ..., a_n'])
  49. fanout : (a |->| b) * (a |->| c) -> (a |->| [b, c])
  50. fanout : [ a |->| b_1, a |->| b_2, ..., a |->| b_n ]
  51. -> (a |->| [b_1, b_2, ..., b_n])
  52. pointwise : ([a_1, a_2, ..., a_n] |->| [b_1, b_2, ..., b_n])
  53. * ([b_1, b_2, ..., b_n] |->| [c_1, c_2, ..., c_n])
  54. -> ([a_1, a_2, ..., a_n] |->| [c_1, c_2, ..., c_n])
  55. pointwise : [ [a_11, a_12, ..., a_1n] |->| [a_21, a_22, ..., a_2n],
  56. [a_21, a_22, ..., a_2n] |->| [a_31, a_32, ..., a_3n],
  57. ...,
  58. [a_m-11, a_m-12, ..., a_m-1n] |->| [a_m1, a_m2, ..., a_mn] ]
  59. -> ([a_11, a_12, ..., a_1n] |->| [a_m1, a_m2, ..., a_mn])
  60. map : (a |->| b) * |< [a] >| -> |< [b] >|
  61. reduce : ([a] |->| b) * ([b] |->| b) * |< [a] >| -> |< [c] >|
  62. Choice
  63. ------
  64. tag : t * |<a>| -> |< {t, a} >|
  65. tagging : t * (a |->| b) -> (a |->| {t, b})
  66. cases : (a |->| a') * (b |->| b') -> (a+b |->| a'+b')
  67. cases : [ a_1 |->| b_1, a_2 |->| b_2, ..., a_n |->| b_n ]
  68. -> (a_1+a_2+...+a_n |->| b_1+b_2+...+b_n)
  69. cases nondeterministically picks any non-'nop' output, or is 'nop' if there is
  70. none. use tags to force determinism.
  71. fanin : (a |->| c) * (b |->| c) -> (a+b |->| c)
  72. fanin : [ a_1 |->| b, a_2, |->| b, ..., a_n |->| b ]
  73. -> (a_1+a_2+...+a_n |->| b)
  74. fanin = cases, since '+' is simple union.
  75. fastest : |<a>| * |<b>| -> |< a+b >|
  76. fastest : [ |<a_1>|, |<a_2>|, ..., |<a_n>| ] -> |< a_1+a_2+...+a_n >|
  77. slowest : |<a>| * |<b>| -> |< a+b >|
  78. slowest : [ |<a_1>|, |<a_2>|, ..., |<a_n>| ] -> |< a_1+a_2+...+a_n >|
  79. Loops
  80. -----
  81. loopback : (a |->| {'stop', b}+{'loop', a}) -> (a |->| b)
  82. loopback terminates when the operation returns 'stop'.
  83. Interpretation
  84. --------------
  85. simpl : |<a>| -> |<a>|
  86. simpl : (a |->| b) -> (a |->| b)
  87. simpl simplifies and optimizes a task or operation.
  88. linearize : |<a>| -> (0 -> a)
  89. linearize : (a |->| b) -> (a -> b)
  90. linearize interprets a task or operation to run sequentially on a single node.
  91. localize : |<a>| -> (0 -> a)
  92. localize : (a |->| b) -> (a -> b)
  93. localize interprets a task or operation to run in parallel on a single node.
  94. distribute : |<a>| -> (ResourceInfo -> a)
  95. distribute : (a |->| b) -> (ResourceInfo * a -> b)
  96. distribute interprets a task or operation to run in parallel distributed among
  97. several nodes.
  98. run_linear : |<a>| -> a
  99. run_linear : (a |->| b) * a -> b
  100. run_linear(x) = linearize(x)()
  101. run_linear(x, y) = linearize(x)(y)
  102. run_local : |<a>| -> a
  103. run_local : (a |->| b) * a -> b
  104. run_local(x) = localize(x)()
  105. run_local(x, y) = localize(x)(y)
  106. run : ResourceInfo * |<a>| -> a
  107. run : ResourceInfo * (a |->| b) * a -> b
  108. run(Info, x) = distribute(x)(Info)
  109. run(Info, x, y) = distribute(x)(Info, y)