Created
May 12, 2014 20:38
-
-
Save fowlmouth/6fce784b3ea3e7a967d3 to your computer and use it in GitHub Desktop.
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 | |
| Indexable* [T] = generic X | |
| high(X) is int | |
| #T is int | |
| X is seq[int] | |
| #X[0] is T # causes failure.. | |
| template echoCode (expression): stmt = | |
| echo astToStr(expression), ": ", expression | |
| template tc_test (ty, tyclass; body:stmt): stmt = | |
| when ty is tyclass: | |
| body | |
| else: | |
| echo astToSTr(ty), " not match ", astToStr(tyclass) | |
| proc last* [T] (some: Indexable[T]): T = some[high(some)] | |
| echocode seq[int] is indexable[int] | |
| when true: | |
| tc_test(seq[int], indexable[int]): | |
| var s = @[1,2,3] | |
| echo s.last | |
| type | |
| # cant get this to work at all | |
| Arrlike[T] = generic x | |
| true#T is int | |
| #x is array[4,T] | |
| #x[0] is T | |
| echoCode array[4,int] is ArrLike | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment