Comment

Comment by frankpf

I've been writing an interpreter with Nim and overall the language is really good.

One feature that I'm excited for is DrNim[1]. It's not distributed with the stable version just yet (you have to compile it yourself, but that's very straightforward), but it's supposed to bring refinement types to Nim. These allow you to write things like:

    proc safeDivide(a: int, b: int): float {.requires b > 0.} =
        a / b
and DrNim will check at compile-time that all code paths lead to `b` being greater than 0, e.g.:

    var x = stdin.readLine.parseInt
    safeDivide(1, x) # DrNim will error at compile-time 
    var y = stdin.readLine.parseInt
    if y > 20:
       # no error since DrNim (using Z3) can
       # prove that y is always greater than 0 here
       safeDivide(1, y)
[1]: https://nim-lang.org/docs/drnim.html
parent frankpf 6 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton