Skip to content

Instantly share code, notes, and snippets.

@Deco
Last active August 29, 2015 14:15
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 Deco/5a58b5721bec07c4b09a to your computer and use it in GitHub Desktop.
Save Deco/5a58b5721bec07c4b09a to your computer and use it in GitHub Desktop.
{.experimental.}
type TArray {.borrow: `[]`.} = distinct array[0..3, int]
var a = TArray([1, 2, 3, 4])
echo "yay", a[1] # Error: type mismatch: got (TArray, int literal(1))
@gmpreussner
Copy link

proc `[]`(a: TArray; idx: int): int = array[0..3, int](a)[idx]

@Deco
Copy link
Author

Deco commented Feb 13, 2015

    proc `[]`(a: TArray; idx: int): int {.borrow.}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment