Skip to content

[Feature] If-statement #86

Description

@cympfh

To implement (type-safe) If-statement, the followings may need.

  • Type inferred functions.
    • Functions have types of arguments, but don't know the type of output.
    • To investigate the type without concrete argument values, type-infer needs instead of eval.
      • Since latest cumin doesn't have loop or recursion, this is trivial.
fn f(x: Int) = [x]; // inferred as `Int -> Array<Int>`

// OK
fn g(x: Int) = { // inferred as `Int -> Array<Int>`
  if x == 0 {
    []
  } else {
    f(x)
  }
};

// NG
fn h(x: Int) = {
  if x == 0 {
    0
  } else {
    f(x) // this doesn't match to `0`.
  }
};

// NG
fn i(x: Int) = {
  if true {
    0
  } else {
    [x]
  }  // this is always (0: Int), but this is invalid.
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions