4 ms·
That’s common to all typed languages and is the motivation behind generics/templates which allow you to write once and provide specialisation where necessary. I
by rpep 4y ago
That’s common to all typed languages and is the motivation behind generics/templates which allow you to write once and provide specialisation where necessary. In older C and Fortran libraries it wasn’t unusual to have to compile a library multiple times to support different input types - FFTW does this for example. Often there’s some macro magic with a variable injected at build time to determine the type.
- msla 4y ago> That’s common to all typed languages It isn't. Haskell, for example, has a type system expressive enough to encode concepts such as "a function which takes an array of elements of any type (fixed at compile time) and another function which operates on elements of the type that array is composed of and returns an array of elements of that unnamed type" and it has a type system with fewer holes than any Algol-derived language's (Ada, C, Pascal) type system has.
- User23 4y agoAlgol 60’s type system has fewer holes than most Algol-derived languages.
- msla 4y ago> Algol 60’s type system has fewer holes than most Algol-derived languages. And this can be a mixed blessing. If an inexpressive type system has few or no holes, it becomes a straitjacket where you can't write the kinds of perfectly well-defined functions you need because the type system can't express them. The classic pathological example is how Standard Pascal couldn't express the concept of a function which took an arbitrary-size array, but the example so common it's typically overlooked is how it's impossible in many Algol-derived languages to write one function to compare two numbers instead of having to write four or five such functions, especially if you're unwilling to let the type system hole of automatic integral and floating-point size promotion potentially introduce odd bugs. Haskell's type system is strong and fairly expressive, with language extensions to make it more expressive. (This does not change the fact type systems typically express the wrong things, but this post is long enough already.)
- Volt 4y agoYou should literally continue reading the rest of the sentence.
- msla 4y agoHaskell doesn't have generics or templates, it has an expressive type system.
- tpoacher 4y ago"Expressive Type System" without context is just a buzzword. In this particular context, it simply means that Haskell allows for types to be parameterised, which is a different way of saying it allows for generic types.