Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better interface for type instance pattern match #3

Closed
slepher opened this issue Nov 15, 2017 · 3 comments
Closed

better interface for type instance pattern match #3

slepher opened this issue Nov 15, 2017 · 3 comments

Comments

@slepher
Copy link
Owner

slepher commented Nov 15, 2017

current type pattern match interface is

-erlando_type({error_m, [{ok, '_'}, {error, '_'}]}). 

will be convert to such pattern match in typeclass module

type({ok, _}) ->
  error_m; 
type({error, _}) ->
  error_m;

so these features are not supported

  • record used in pattern match
  • function guard test used in pattern match

there should have a better interface for type instance pattern match

@slepher
Copy link
Owner Author

slepher commented Nov 17, 2017

erlando_type error_m

-erlando_type(error_m, [error_m/2]).
-export_type([error_m/2, ok/1, error/1]).
-type error_m(E, A) :: ok(A) | error(E).
-type ok(A) :: ok | {ok, A}.
-type error(E) :: {error, E}.

convert to erl_types

{c,union,
       [{c,atom,[ok],unknown},
        none,none,none,none,none,
        {c,tuple_set,
           [{2,
             [{c,tuple,
                 [{c,atom,[error],unknown},any],
                 {2,{c,atom,[error],unknown}}},
              {c,tuple,
                 [{c,atom,[ok],unknown},any],
                 {2,{c,atom,[ok],unknown}}}]}],
           unknown},
        none,none,none],
       unknown}

generates pattern

type({ok, _}) ->
  error_m; 
type({error, _}) ->
  error_m;
type(ok) ->
  error_m

erlando_type state_t

-erlando_type({state_t, [state_t/3]}).
-export_type([state_t/3]).
-type state_t(S, M, A) :: {state_t, inner_t(S, M, A)}.
-type inner_t(S, M, A) :: fun((S) -> monad:m(M, {A, S})).

converted to erl_types

{c,tuple,
       [{c,atom,[state_t],unknown},
        {c,function,
           [{c,product,[{c,var,'S',unknown}],unknown},any],
           unknown}],
       {2,{c,atom,[state_t],unknown}}}

generates pattern

type({state_t, Args1}) when is_function(Args1) ->
  state_t

@slepher slepher closed this as completed Nov 17, 2017
@slepher
Copy link
Owner Author

slepher commented Nov 17, 2017

move to branch type_by_erlang
request erlang R20 or higher

@slepher
Copy link
Owner Author

slepher commented Nov 17, 2017

support R19 by moving dialyzer_utils.erl and erl_types.erl to this project from erlang otp R20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant