Skip to content

Instantly share code, notes, and snippets.

@baroquebobcat
Last active December 17, 2015 16:18
Show Gist options
  • Select an option

  • Save baroquebobcat/5637447 to your computer and use it in GitHub Desktop.

Select an option

Save baroquebobcat/5637447 to your computer and use it in GitHub Desktop.
Mirah Assignment corner cases

Multiple Assignment general cases

The fundamental question is whether the return type of an assignment is rhs's type or lhs's.

#  B = C => ?
   b = c

should a = b = c => a = c; b = c or b = c; a = b?

middle type narrower

a = b = c

where

  • a is uninferred,
  • b & c have been inferred
  • b's type is narrower than c's

should a's type be b's or c's?

middle type wider

a = b = c

where

  • a is uninferred,
  • b & c have been inferred
  • b's type is wider than c's

should a's type be b's or c's?

assignment & return cases

middle type narrower

def a
  b = c
end

where

  • a's return type is uninferred,
  • b & c have been inferred
  • b's type is narrower than c's

should a's return type be b's or c's?

middle type wider

def a
  b = c
end

where

  • a's return type is uninferred,
  • b & c have been inferred
  • b's type is wider than c's

should a's return type be b's or c's?

a's return type is wider than b & c

B < ... A C < ... < B ... < A

def a : A
  b = c
end

where

  • a's return type is wider than b & cs,
  • a & b & c have been inferred
  • b's type is wider than c's

fine

a's return type is wider than c, but narrower than b

C < A < B

def a : A
  b = c
end

where

  • a's return type is wider than c's,
  • a's return type is narrower than c's,
  • a & b & c have been inferred
  • b's type is wider than c's

should this be an inference error? Or should we assume a returns c?

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