Re:Haskell Problems for a New Decade
by StefanKarpinski on Friday January 24, 2020 @01:28PM
(#22141044)
Mostly spot on, although it's very rare for local variables to require type annotation—type inference can easily figure it out for locals. Unless, of course, they are assigned from an untyped external source the compiler couldn't possibly know. You could, for example read something from a JSON source knowing that it should be an number, annotate it with `json["field"]::Float64` and then the compiler will emit code to check the type and throw an error unless the type is actually a Float64.
[ Parent
| on HN ]
Thanks for the reply - I wasn’t sure what Julia did in terms of type inference.
So, if not on local variables, where are explicit types necessary (other than function parameters)?
Re:Haskell Problems for a New Decade
by ChrisRackauckas on Friday January 24, 2020 @06:45PM
(#22143443)
You actually don't need explicit types in function parameters unless you're trying to control dispatching. Otherwise the compiler will auto-specialize on call. This blog post might be a better explanation on when it's necessary: https://www.stochasticlifestyle.com/type-dispatch-design-pos...