4 ms·
Haskell has multiple concepts that are so compelling that I do not understand why most of the new languages make no use of them. Very handwavy, here are a coupl
by quchen 13y ago
Haskell has multiple concepts that are so compelling that I do not understand why most of the new languages make no use of them. Very handwavy, here are a couple of them.
- Type inference: strong typing at the convenience of weak typing. (Some languages are moving towards this. C++ stapled on `auto` keywords, Rust is designed using it)
- Type classes: unifying things that "can do X", allowing the programmer to write functions that do similar things but work on many different types. A "sort" function can then be written for all things that "are containers of elements that can be compared". (Again, Rust adopts this.)
- Allowing separation of pure and impure functions. Imagine having a "pure" keyword that guarantees that a function doesn't have side effects. The benefit of this cannot be overstated in a multithreaded environment.
- cmircea 13y agoC# has had type inference for a long while. It's a pain using Java, which doesn't. C# also sort of implements type classes. For your example, there's IComparable in C#; implement it and a List<SomeObject> can be directly sorted. For pure functions, there's the [Pure] attribute, but it isn't enforced by the compiler, it's just a contract, a promise.
- quchen 13y agoYes, there are languages that also have these features, the puzzling part is why not all of them do (except those that may have good design reasons not to).
- ufo 13y agoIts hard to implement type inference and type classes unless you carefully design the language to accommodate it from day 1. For example, return-type polymorphism (functions like `read` or `return`) is particularly tricky, specially in the more dynamic languages.
- frankzinger 13y ago"- Type classes: unifying things that "can do X", allowing the programmer to write functions that do similar things but work on many different types. A "sort" function can then be written for all things that "are containers of elements that can be compared". (Again, Rust adopts this.)" This is what templates do in C++.