Type-level vs. Value-level Programming

First of all a foreword about my background: I’m not a Computer Scientist, nor a Programmer, but, by trade, a Commercial Pilot. I took interest in programming 37 years ago, when I had to develop very basic CFD programs in Pascal, so, when it comes to programming, I’m a layman. This is to say: please bear with me, if my question is a little “dumb”.
My understanding is that Type-level programming, Category concepts, Generics as in Shapeless, and so on are a more efficient way of writing programs, as compared to classical value-level programming.
Now are these paradigms also more, or equally, or, finally, less efficacious (i.e., faster, equally, or less fast) than a classical way of programming, especially when it comes to maths? Which, at the end, amounts to asking: should I invest time and resources in learning all this stuff, or I’d better stick to the “old” way and just avail of the promises of GraalVM and its polyglot capability, apparently allowing me to access libraries such as FeniCS, considering that my main goal in programming is “to crunch numbers”?
Y’all have a lovely day.

1 Like

It is more efficient in the sense, that you can write more generic, i.e. more reusable code. Also it helps with having the compiler check more of the correctness of the program. It doesn’t directly have any relation to performance, as type level programming runs mostly during compile time. Of course using abstractions can have a runtime impact, but that depends on the concrete case.

If your main interest is in performance for number crunching, then I’d say type-level programming isn’t really relevant. Depending on what kind of number crunching you want to do, there are also Scala libraries which wrap native code, e.g. Breeze, a linear algebra library that can use various calculation libraries under the hood. I have no experience with GraalVM, but if it allows the use of native libraries, it’s probably also a good bet.

3 Likes

I’m not a computer scientist either, although I did play one on TV once (in my dreams). But seriously, I doubt that type-level programming is appropriate for many real-world problems. I’ve never done it myself, but I have tried to understand an example of it. I think you will find that it is very awkward and non-intuitive, requiring a fundamentally new mindset. If it were good for most problems, we wouldn’t need “value-level” programming.

1 Like

Expanding slightly on what @crater2150 says: the benefits of all the typeful stuff are a bit second-order. The bigger the problem – the longer-lived the code, the bigger the codebase, the more people who have to work on it – the more benefit you get from very strong types and reusable abstractions. But where the balance point lies depends on your situation…

3 Likes

Thank you all for the replies.
So, to sum it up, Type-level Programming, Category Theory and consimilia represent a plus if someone is designing libraries in a “collaborative” environment, but if someone, like me, programs fairly simple applications, he can be satisfied with the contents of “Scala Programming” by Prof. Odersky et al., possibly beefed up by “Functional Programming in Scala” and “Functional Programming, Simplified”. That’s why Scala stands for scalable: it affords its user to use those aspects that best fit his needs.

As per the run-time-performance aspect, the advantage of the abstractions can be debatable, and probably wouldn’t warrant the required intellectual investments.

1 Like