Created
January 12, 2016 22:16
-
-
Save ytomino/18ffee7b75ba98839251 to your computer and use it in GitHub Desktop.
Trying dependent types in nim
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 Cell[T] = ref object | |
car: T | |
cdr: Cell[T] | |
type List[T, N] = distinct Cell[T] | |
proc makeNil[T]: List[T, range[0..0]] = nil | |
proc makeCons[T, N](car: T; cdr: List[T, N]): auto = | |
type N1 = range[0..high(N)+1] | |
var r: Cell[T] = Cell[T](car: car, cdr: Cell[T](cdr)) | |
List[T, N1](r) | |
const theNil: List[int, range[0..0]] = makeNil[int]() | |
const theList1 = makeCons(1, theNil) | |
# % nim c dt.nim | |
# Hint: system [Processing] | |
# Hint: dt [Processing] | |
# dt.nim(5, 14) Hint: 'N' is declared but not used [XDeclaredButNotUsed] | |
# SIGSEGV: Illegal storage access. (Attempt to read from nil?) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment