Hacker News new | ask | show | jobs
by feduzi 3406 days ago
It is more an expression of confusion rather than type system quality evaluation, but why does JSON parser's implementation returns its own types like JsonNode? Why doesn't it just return core types like:

* JSON String -> NIM String

* JSON Object -> NIM Hash

* and so on...

I've also had the same question when looking at https://crystal-lang.org.

PS: I do not claim Nim's type system to be bad as I do not have an exact counterexample of a "better" type system.

1 comments

Because the type of a JSON object's fields is not known at compile-time.

    let s = parseJson("{'A': 'foo'}")
    s["A"] # What type is this? We don't know until we parse the JSON.