Re:Type-safe GraphQL with OCaml
by StreamBright on Thursday November 30, 2017 @03:39PM
(#15819302)
I think the exact opposite. Finally a language where floats and integers cannot be mixed together accidentally.
[ Parent
| on HN ]
Haskell does not allow accidentally mixing floats and integers together. In fact it doesn't even allow mixing finite and infinite-precision integers together, despite using the same operator for all number additions:
Prelude> (3::Int) + (4::Integer)
<interactive>:2:13:
Couldn't match expected type ‘Int’ with actual type ‘Integer’
In the second argument of ‘(+)’, namely ‘(4 :: Integer)’
In the expression: (3 :: Int) + (4 :: Integer)
In an equation for ‘it’: it = (3 :: Int) + (4 :: Integer)
It's not by any means the only language with that property either.Off topic: why on earth does ghci print out that last “In an equation for ‘it’: it = […]” statement? Seems like something internal to ghci, and not something that’s relevant to the user.
You'd have to check ghci's source itself, but I expect it just hands the bits over to GHC for evaluation and the relevant GHC API (sensibly) requires a name, for which ghci provides "it".
The type checker is capable of disallowing `float + int` while still allowing `int + int` and `float + float`, which is what I want.