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

Union types + pattern matching (eventually) #72

Open
thosakwe opened this issue Apr 25, 2018 · 1 comment
Open

Union types + pattern matching (eventually) #72

thosakwe opened this issue Apr 25, 2018 · 1 comment

Comments

@thosakwe
Copy link
Contributor

thosakwe commented Apr 25, 2018

Extremely hypothetical. Might be unnecessarily complex.

type Circle { radius: Int }
type Triangle { base: Int, height: Int }
type Shape = Circle | Triangle

fn area (shape: Shape): Double =>
  match shape {
    Circle => math::Circle::PI * (math::pow(shape.radius, 2))
    Triangle => 0.5 * shape.base * base.height
  }
@thosakwe
Copy link
Contributor Author

thosakwe commented Apr 25, 2018

If you have a tuple, then maybe?

type A = (Int, Int)
type B = String
type C = A | B

fn d(c: C) =>
  match c {
    A(a, b) => a * b
    B => c.length
  }

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