[erlang-questions] [ANN] sheriff 0.2: parse transform for type-based data validation

Loïc Hoguin essen@REDACTED
Thu Feb 16 15:45:07 CET 2012


Hello,

I have just pushed a couple changes, including this important one. You 
can now check types directly using an inline notation by including the 
type to be checked against in a string:

   sheriff:check(Var, "list({atom(), integer()})")

Works with built-in, local and remote types.

Should make using sheriff a lot easier than before.

On 02/13/2012 11:52 AM, Loïc Hoguin wrote:
> Hello!
>
> We just released the first beta version of the sheriff parse transform.
> It allows you to validate data against types defined through the Erlang
> type system.
>
> Sheriff allows you to write this:
>
> -type colors() :: blue | red | green | yellow.
>
> paint(Color, Object) ->
> case sheriff:check(Color, colors) of
> true ->
> do_paint(Color, Object);
> false ->
> {error, badarg}
> end.
>
> In this example, sheriff:check/2 will check that Color is of type
> colors(), meaning it is one of 'blue', 'red', 'green' or 'yellow'.
>
> This allows you to quickly and efficiently write validation code for
> unsafe external data without having to repeat yourself too much.
>
> Sheriff can be found here along with extended usage instructions:
> https://github.com/extend/sheriff
>
> It's still in beta and has not been used in production yet, so feel free
> to open tickets on github if you find bugs or don't understand something.
>
> Finally, I want to thank my students from last summer William Dang and
> Hamza Mahmood for doing the awesome initial work and research that led
> to this release. Thanks!
>


-- 
Loïc Hoguin
Erlang Cowboy
Nine Nines



More information about the erlang-questions mailing list