Slightly off topic but... erlando and list_m...

17 views
Skip to first unread message

Emacs the Viking

unread,
Jan 12, 2015, 6:48:13 PM1/12/15
to chica...@googlegroups.com
I am a (not for a while but...) Haskeller but not used to Monads in Erlang... I have already made use of the maybe_m monad implementation for validating an API JSON request, that's fine, but for some reason my sign-in form validation code just meets with a compile error and I can't see why. It's late. I should stop!!

Here is the full set of code, then the error...

-module(smsengine_web_controller, [Req]).
-compile({parse_transform, do}).
-compile(export_all).

%% @doc The public web controller does not need any authorisation checks.
before_filters(DefaultFilters, _RequestContext) -> 
    utils:no_auth(DefaultFilters).

%% @doc Home page redirect to the template.
index('GET', []) -> ok.

signin('POST', []) ->
U = Req:post_param("u"),
P = Req:post_param("p"),

do([list_m ||
validate_email(U),
validate_password(P)
]),

{render_other,
[{controller, "web"}, {action, "index"}],
[]}. %% TODO: session start etc


validate_email([]) ->
list_m:return(100);
% list_m:return({email_text, "Please supply a valid email address"});

validate_email(_) ->
list_m:fail([]). %% other validation checks will go here


validate_password([]) ->
list_m:return({password_text, "Please enter your password"});

validate_password(_) ->
list_m:fail([]). %% other validation checks here

And the error:

[error] Error in controller error undef [{list_m,return,"d",[]},{smsengine_web_controller,'-signin/3-fun-1-',3,[{file,"/Users/seancharles/Documents/bitbucket/smsengine/src/controller/smsengine_web_controller.erl"},{line,33}]},{smsengine_web_controller,signin,3,[{file,"/Users/seancharles/Documents/bitbucket/smsengine/src/controller/smsengine_web_controller.erl"},{line,32}]},{boss_web_controller,call_controller_action,3,[{file,"src/boss/boss_web_controller.erl"},{line,363}]},{boss_web_controller,apply_action,4,[{file,"src/boss/boss_web_controller.erl"},{line,355}]},{boss_web_controller,execute_action_inner,9,[{file,"src/boss/boss_web_controller.erl"},{line,334}]},{boss_web_controller_handle_request,process_dynamic_request,4,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,242}]},{boss_web_controller_handle_request,process_request,4,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,228}]}]

My intent was to run the list monad over all of the various validation and credentials checking functions such that, if all is well I have an empty list i.e. the user can redirect to the landing page for their account or, if there is at least one error in the list, that I re-display the sign-in page and the template shows the errors as and where needed.

It seems to be telling me that the function list_m:return is not defined or have I got it wrong??

Thanks and goodnight for now.
:)
Sean

Spencer Thompson

unread,
Feb 1, 2015, 6:44:49 AM2/1/15
to chica...@googlegroups.com
You're right.  It appears your code can't find the list_m module.  Try putting it in your lib directory.
Reply all
Reply to author
Forward
0 new messages