News for hackers. Stuff that matters.
Re:Does C++ still deserve a bad rap? by eru on Saturday October 17, 2020 @09:34AM (#24809861)
Haskell solves this reasonably well.

If your data type implements the Num typeclass, you can use literals like 4. (A typeclass in Haskell is similar to what they call an interface in Java.)

There's no automatic conversion happening at all. It's done via overloading literals at compile time. (You can do the same for strings.)

Re:Does C++ still deserve a bad rap? by srg0 on Saturday October 17, 2020 @02:35PM (#24812103)
C++20 introduced concepts, and now it's possible to specify type constraints, like integral, in a way similar to Haskell typeclasses.

What it doesn't solve that by default the compiler tries to find an appropriate implicit conversion. Sometimes it's convenient, sometimes it's harder to see what the code actually does.

Re:Does C++ still deserve a bad rap? by eru on Sunday October 18, 2020 @06:38AM (#24816844)
Yes, concepts help a bit, but I'm not sure whether they would be necessary here.

Yes, the implicit conversion for all values is part of the problem. The Haskell approach only gives you magic for literals.