Created
May 16, 2019 01:18
-
-
Save jrfondren/44fb942087502336eac4c9e5471e729c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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