-
Notifications
You must be signed in to change notification settings - Fork 73
pmod_pt added for parameterized module support #12
Conversation
I tried with "R16B" this fix. However, I was not able to compile the following error out. Are you able to compile correctly in your environment? It is good if the only bad my environment.
|
I tried the patch with "R16B" and got same errors that @voluntas had. But I noticed that if I comment out I compared the results of Erlang R16B (erts-5.10.1) [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V5.10.1 (abort with ^G)
1> St = state_t:new(identity).
{state_t,identity}
2> error_t:module_info().
[{exports,[{'>>=',3},
{return,2},
{fail,2},
{run,2},
{lift,2},
{new,1},
{instance,1},
{module_info,0},
{module_info,1}]},
...
3> state_t:module_info().
[{exports,[{'>>=',3},
{return,2},
{fail,2},
{get,1},
{put,2},
{eval,3},
{exec,3},
{run,3},
{modify,2},
{modify_and_return,2},
{lift,2},
{new,1},
{instance,1},
{module_info,0},
{module_info,1}]},
...
For example, this is the original function definition in state_t.erl: -export(['>>='/2, return/1, fail/1]).
'>>='(X, Fun) -> fun (S) -> do([InnerMonad || {A, S1} <- X(S),
(Fun(A))(S1)]) end. and this is what [{exports,[{'>>=',3}, The last parameter should be for receiving the module tuple, so I think the function is transformed into: -record(?MODULE, {mod :: module()}).
'>>='(X, Fun, #?MODULE{mod=InnerMonad}) ->
fun (S) -> do([InnerMonad || {A, S1} <- X(S),
(Fun(A))(S1)]) end. I think |
Guys - I'll take a look at this ASAP. We're no longer using erlando in RabbitMQ, so it's taken a while a to get around to. |
@hyperthunk - thank you for looking after this issue. Please let me know if you need anything from me. |
Sure, will do. |
I went and update the code to just work with 'stateful modules' -- the code for 'state_t' is included below. 'error_t' is simpler and can be easily update from the 'state_t' example. Running the test code under R16B also exposed an issue with the 'test.erl' code; and I have included the change. The updated code will now run on R16B and earlier versions. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% The contents of this file are subject to the Mozilla Public License %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %* -module(state_t, [InnerMonad]). -module(state_t). -export([new/1]). -ifdef(use_specs). %* Create a define for simplification -- may be multiple parameters. %* Add the 'new' fun. '>>='(X, Fun, ?PMOD_FIX) -> fun (S) -> do([InnerMonad || {A, S1} <- X(S), return(A, ?PMOD_FIX) -> fun (S) -> InnerMonad:return({A, S}) end. get(?PMOD_FIX) -> fun (S) -> InnerMonad:return({S, S}) end. put(S, ?PMOD_FIX) -> fun (_) -> InnerMonad:return({ok, S}) end. eval(Monad, S, ?PMOD_FIX) -> do([InnerMonad || {A, _S1} <- Monad(S), exec(Monad, S, ?PMOD_FIX) -> do([InnerMonad || {_A, S1} <- Monad(S), %* Had to hand fix this because we nolonger have the monad behaviour; was causing 'unused' error. modify(Fun, ?PMOD_FIX) -> fun (S) -> InnerMonad:return({ok, Fun(S)}) end. modify_and_return(Fun, ?PMOD_FIX) -> fun (S) -> InnerMonad:return(Fun(S)) end. lift(X, ?PMOD_FIX) -> fun (S) -> do([InnerMonad || A <- X, return({A, S})]) end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% test_funs(ErrorT, [{Module, FunName}|Funs]) |
I've only added monad_t behaviour with different arities on top of pmod_pt and everything worked well: BartAdv@ebd1de6, however, it doesn't work when transformer calls 'normal' function... |
Better and cleaner version of pull #11