Last active
December 29, 2015 01:18
-
-
Save mflamer/7591727 to your computer and use it in GitHub Desktop.
Enum as tagged pointer in nimrod
This file contains hidden or 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 | |
TPnt = tuple[x,y: float] | |
TMaybe {.enumSumTyp.} = enum | |
None, | |
Just = TPnt | |
var | |
x = (x: 45.96, y: 25.25) | |
test = Just(x) | |
proc `$`(m: TMaybe): string = | |
if m == None: | |
result = "None" | |
elif m == Just: | |
result = "Just " & $m[] | |
else: | |
result = "something went wrong!" | |
echo(test) #Using `$` above | |
echo(test[]) #Deref | |
echo(test.y) #Field Access |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The next hurdle is to skip the step of creating x first. If the user were to create a Just((x: 45.96, y: 25.25)) directly, I need to create a heap copy.