Skip to content

Instantly share code, notes, and snippets.

@jrfondren
Created May 16, 2019 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrfondren/44fb942087502336eac4c9e5471e729c to your computer and use it in GitHub Desktop.
Save jrfondren/44fb942087502336eac4c9e5471e729c to your computer and use it in GitHub Desktop.
type
AnyTypeTypes = enum
ATString, ATInt, ATBool
AnyType = object
case kind: AnyTypeTypes
of ATString: str: string
of ATInt: n: int
of ATBool: b: bool
proc wrap(str: string): AnyType = result.kind = ATString; result.str = str
proc wrap(n: int): AnyType = result.kind = ATInt; result.n = n
proc wrap(b: bool): AnyType = result.kind = ATBool; result.b = b
proc whatis(x: AnyType) =
case x.kind
of ATString: echo "it's a string: " & x.str
of ATInt: echo "it's a string: " & $x.n
of ATBool: echo "it's a string: " & $x.b
whatis 42.wrap
whatis "hello".wrap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment