Skip to content

Instantly share code, notes, and snippets.

@stevenheidel
Last active July 2, 2020 18:03
Show Gist options
  • Save stevenheidel/4b8c2b291575e758bb8aeab42ecfd60b to your computer and use it in GitHub Desktop.
Save stevenheidel/4b8c2b291575e758bb8aeab42ecfd60b to your computer and use it in GitHub Desktop.
Language How to Load Reference
Elixir Pin operator (^) in front of variable 1
F# Enum (with type) or tag variable with [<Literal>] 2
OCaml Constant, enum type, or manual if guard (eg. a when a = var_to_load)* 3
Rust Marked as enum, struct, or constant. Can also use fully qualified name (ie with module) to force. 4
Scala Capitalize or surround with backticks 5

(* nearly all the languages above support manual loads with if guards)

Note: The Ecmascript proposal includes pinning as a followup rather than part of their main proposal.

  • Imagine you have let y = 1
  • Current proposed JS syntax with no followup: when x if (x === y)
  • Idea 1: use pin operator like Elixir
  • Idea 2: wrap constants a custom matcher class like ByVal (* this is also supported in nearly all the languages above but not really used since they have special syntax)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment