[erlang-questions] Some functions must return values other may do so...

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Sun Aug 16 12:42:26 CEST 2015


On Sat, Aug 15, 2015 at 4:56 PM, Joe Armstrong <erlang@REDACTED> wrote:

> Rule1: Functions which return {ok,X} | {error,W} are called may_<name>
>
> Rule2: Functions which return a value or raise an exception are called
> must_<name>
>

Essentially, this is what the Janes St. Core library for OCaml does as well:

val zip : 'a t * 'b t -> ('a * 'b) t option
val zip_exn : 'a t * 'b t -> ('a * 'b) t

Where the exception is raised, or None returned, if the t's are of
different length.

I think it is a good idea. Knowing off-hand if a function has effects is
always a good thing. And the caller knows immediately when reading the code
that this may fail in unexpected ways if the invariants are broken.


-- 
J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150816/30a3846f/attachment.htm>


More information about the erlang-questions mailing list