Skip to content

Instantly share code, notes, and snippets.

@wbbradley
Last active December 4, 2017 14:58
Show Gist options
  • Save wbbradley/6dc1ab1e12ce4312c83cd33012eb721b to your computer and use it in GitHub Desktop.
Save wbbradley/6dc1ab1e12ce4312c83cd33012eb721b to your computer and use it in GitHub Desktop.
Zion: Refining Types in Short-circuited Logical Expressions
module _
def gimme_bool() bool
return true
def main()
static_print(7)
static_print("hello")
static_print(gimme_bool())
static_print(gimme_bool() ? "foo" : 4.5)
static_print(gimme_bool() and 9)
static_print(gimme_bool() and 9 or 200)
static_print(true and 100)
static_print(false and 100)
static_print(true or 100)
static_print(false or 100)
$ zion compile condition_refinement.zion
condition_refinement.zion|8 col 15| info: 7 : int
condition_refinement.zion|9 col 15| info: "hello" : str
condition_refinement.zion|10 col 25| info: gimme_bool() : bool
condition_refinement.zion|11 col 25| info: gimme_bool() ? "foo" : 4.5 : (or str float)
condition_refinement.zion|12 col 28| info: (gimme_bool() and 9) : (or int false)
condition_refinement.zion|13 col 41| info: ((gimme_bool() and 9) or 200) : int
condition_refinement.zion|14 col 20| info: (true and 100) : int
condition_refinement.zion|15 col 21| info: (false and 100) : false
condition_refinement.zion|16 col 20| info: (true or 100) : true
condition_refinement.zion|17 col 21| info: (false or 100) : int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment