Updated Common Criticisms (markdown)
This commit is contained in:
parent
17f60e1c4a
commit
57d86f1045
|
@ -12,4 +12,23 @@ var b: T = ...
|
||||||
foo(b) # also valid
|
foo(b) # also valid
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that the difference between what happens in Java and what Nim does is simply a matter of efficiency: Nim does not require our `T` to be allocated on the heap, and it certainly allows `b` to be declared with `let`, which will force an compile-time error to be thrown.
|
Note that the difference between what happens in Java and what Nim does is simply a matter of efficiency: Nim does not require our `T` to be allocated on the heap, and it certainly allows `b` to be declared with `let`, which will force an compile-time error to be thrown.
|
||||||
|
|
||||||
|
## Sum types are weird
|
||||||
|
In OCaml, sum types are denoted like this:
|
||||||
|
``` ocaml
|
||||||
|
type OptionalInt =
|
||||||
|
| Value of int
|
||||||
|
| Missing
|
||||||
|
```
|
||||||
|
while in Nim they are written like
|
||||||
|
``` nimrod
|
||||||
|
type
|
||||||
|
NodeKind = enum opValue, opAdd, opSub, opMul, opCall
|
||||||
|
Node = ref object
|
||||||
|
case k: NodeKind
|
||||||
|
of opValue: value: int
|
||||||
|
of opAdd, opSub, opMul, opCall: kids: seq[Node]
|
||||||
|
```
|
||||||
|
|
||||||
|
While the OCaml way looks better, the Nim version allows for multiple types to have the same values, without repetition. It also has the advantage that multiple variants can concisely be matched upon using sets like `{opSub, opMul}`
|
||||||
|
|
Loading…
Reference in New Issue