Do-notation in Erlang.
see examples/example.erl as a sample code.
under construction.
some features are already available. but not all of erlang syntax is traversed yet. if inside some syntaxes, e.g. if syntax, these features do not work and your codes are appeared as just an erlang code.
small Makefile is contained, just type make.
$ make
$ make check
$ make install
DESTDIR also works.
wrap do-notation with ?do/1.
but there is erlang restriction, Exprs
of ?do(Exprs)
must be
valid single erlang expression.
then, introduce collection syntax. there is following syntax candidates.
-
use list syntax.
?do([ X = {value, 10}, % ?return(10). Y = {value, 20}, %?return(X + Y), {value, 100}, {value, {X, Y}} ]).
-
begin .. end block version of (1).
?do(begin .. end).
-
tuple.
?do({ .. }).
-
list comprehension.
?do([ _ || X <- doyer_state:return(1), Y <- doyer_state:state(fun(_Seed) -> io:format(".. seed=~p~n",[_Seed]), {2,xx} end), doyer_state:return({X,Y}) ]).
-
record (not implemeted)
?do(#do{ 'X' = {value, 10}, % ?return(10). _ = ?return(20), _ = {value, X} }).
-
anonymous function (not implemeted)
?do(fun() -> X = {value, 10}, % ?return(10). ?return(20), {value, X} end).
currently, monad is selected by left hand value of bind. and it is occured at each invocation of bind. but these are not well as monadic behavior. this will be changed.
you can specify monad module as ?do(mod, [..])
.
(ja) 現在のmonad選択基準::
bindの左辺値が先に確定するので, その値をMod:can_bind/1に渡し, trueが返ってきたらそのモジュールのbindを呼んでいる. つまり実行時に動的に決定されている.
returnはそれが要求されるコンテキストが必要になるため実装未定.
コンパイル時に一意に定めるように変更予定. monadmod からインスタンス構造を示すようにして, 値がそれを満たすかを静的に検証? 判定しきれないことの方がおおそうなので?do_runtime()とかににげるかも.. 確定できなければかならず1つを指定にしてそれを使うにする? 実行するまで動くかはわからないけどそこはやっぱりhaskellじゃないし..? 1つに確定することができればreturnを使うことは可能に.