Browse Source

Merge branch 'master' of github.com:aisamanra/ebb

getty 13 years ago
parent
commit
35c2babff6
5 changed files with 73 additions and 6 deletions
  1. 6 6
      doc/Control
  2. 5 0
      include/ebb_pipe.hrl
  3. 7 0
      include/ebb_prim.hrl
  4. 22 0
      src/ebb_pipe.erl
  5. 33 0
      src/ebb_prim.erl

+ 6 - 6
doc/Control

@@ -21,9 +21,9 @@ return : a -> |<a>|
 
 func : (a -> b) -> (a |->| b)
 
-apply : (a |->| b) * a -> |<b>|
+app : (a |->| b) * a -> |<b>|
 
-suspend : (a -> |<b>|) -> (a |->| b)
+dynamic : (a -> |<b>|) -> (a |->| b)
 
 ignore : |<b>| -> (a |->| b)
 
@@ -33,9 +33,9 @@ id : a |->| a
 
 
 return(x) = task(fun() -> x end)
-apply(func(f), x) = task(f, x)
-suspend(fun(X) -> return(f(x)) end) = func(f)
-ignore(x) = suspend(fun(_) -> x)
+app(func(f), x) = task(f, x)
+dynamic(fun(X) -> return(f(x)) end) = func(f)
+ignore(x) = dynamic(fun(_) -> x)
 
 nop = return('nop')
 id = func(fun(X) -> X)
@@ -66,7 +66,7 @@ bind(bind(x, f), g) = bind(x, fun(X) -> bind(f X, g) end)
 bind(x, return) = x
 bind(return(x), f) = f x
 
-feed(x, suspend(f)) = bind(x, f)
+feed(x, dynamic(f)) = bind(x, f)
 
 
 Scattering

+ 5 - 0
include/ebb_pipe.hrl

@@ -0,0 +1,5 @@
+-record(pipe, {ops}).
+
+-record(feed, {task, op}).
+
+-record(sequence, {tasks}).

+ 7 - 0
include/ebb_prim.hrl

@@ -0,0 +1,7 @@
+-record(thunk, {code}).
+
+-record(func, {code}).
+
+-record(dynamic, {code}).
+
+-record(return, {val}).

+ 22 - 0
src/ebb_pipe.erl

@@ -0,0 +1,22 @@
+-module(ebb_pipe).
+-include("../include/ebb_prim.hrl").
+-include("../include/ebb_pipe.hrl").
+-export([pipe/2, pipe/1, bind/2, feed/2, sequence/2, sequence/1]).
+
+pipe(Op1, Op2) ->
+    #pipe{ops=[Op1, Op2]}.
+
+pipe(Ops) ->
+    #pipe{ops=Ops}.
+
+bind(Task, FuncT) ->
+    feed(Task, #dynamic{code=FuncT}).
+
+feed(Task, Op) ->
+    #feed{task=Task, op=Op}.
+
+sequence(Task1, Task2) ->
+    #sequence{tasks=[Task1, Task2]}.
+
+sequence(Tasks) ->
+    #sequence{tasks=Tasks}.

+ 33 - 0
src/ebb_prim.erl

@@ -0,0 +1,33 @@
+-module(ebb_prim).
+-include("../include/ebb_prim.hrl").
+-include("../include/ebb_pipe.hrl").
+-export([task/2, task/1, return/1,
+	 func/1, app/2, dynamic/1,
+	 ignore/1, nop/0, id/0]).
+
+task(Func, Arg) ->
+    apply(func(Func), Arg).
+
+task(Thunk) ->
+    #thunk{code=Thunk}.
+
+return(Val) ->
+    #return{val=Val}.
+
+func(Func) ->
+    #func{code=Func}.
+
+app(Op, Arg) ->
+    #feed{task=return(Arg), op=Op}.
+
+dynamic(FuncT) ->
+    #dynamic{code=FuncT}.
+
+ignore(Task) ->
+    dynamic(fun(_) -> Task end).
+
+nop() ->
+    #return{val='nop'}.
+
+id() ->
+    #pipe{ops=[]}.