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

Advanced support for union type + pattern match #12

Open
gyson opened this issue Oct 14, 2019 · 0 comments
Open

Advanced support for union type + pattern match #12

gyson opened this issue Oct 14, 2019 · 0 comments

Comments

@gyson
Copy link
Owner

gyson commented Oct 14, 2019

from #8 and #9, we have basic support for union type and pattern match, like following:

@spec example({:a, t1} | {:b, t2} | {:c, t3}) :: any

def example({:a, x}) do
  # ex type should be able to know that `x` is t1 type
end

def example({:b, x}) do
  # ex type should be able to know that `x` is t2 type
end

def example({:c, x}) do
  # ex type should be able to know that `x` is t3 type
end

it could be nice if we can have more advanced support like following:

@spec example({:a, t1} | {:b, t2} | {:c, t3}) :: any

def example({:a, x}) do
  # ex type should be able to know that `x` is t1 type
end

def example({:b, x}) do
  # ex type should be able to know that `x` is t2 type
end

def example(y) do
  # ex type should be able to know that `y` is `{:c, t3}` type
end

also, similarly, for case special form:

# when x is type `{:ok, integer} | {:error, String.t()} | :error`
case x do
  {:ok, y} -> 
    # ex type should be able to figure out that `y` is `integer` type

  e ->
    # ex type should be able to figure out that `e` is `{:error, String.t()} | :error` type
end

This advanced support should cover

  • multi clauses functions
  • case special form
  • anonymous function
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