3 ms·
The thing is, it takes a bit of experience to appreciate why HKT are important, and typically you can only get this experience using Haskell. There’s a couple
by moomin 3y ago
The thing is, it takes a bit of experience to appreciate why HKT are important, and typically you can only get this experience using Haskell.
There’s a couple of ways to think about it: it gives you a way to talk about List rather than List of T, it enables you to write partial types like partially-applied functions, or it makes it possible to define Monads.
But as I say, none of these things will sound immediately useful unless you have experience of using those concepts already.
- evolveyourmind 3y agoOther than Monads, HKT can be used to easily write type-level functional programs [1]. This can for example help writing type-level parsers for other lanugages. A real world use-case could be parsing GraphQL raw string queries and automatically infer the returned types based on a common schema, without using special code-generators. For instance you can come up with some magic function `gql_parsed` like: doc = gql_parsed`query GetUser { user { name }}` where doc is inferred as something like Doc<Query<{GetUser:{user:{name:string}}}>> [1] https://desislav.dev/blog/tsfp/ https://desislav.dev/blog/tsfp/
- gizmo 3y agoI think there is a certain kind of programmer who enjoys the aesthetics of higher-kinded types, and after having made the investment to truly grok them, wants these HKTs to also be useful in practice. I don’t think the benefit ever materializes and highly abstract code is just indulgence. Much like the people who endlessly tinker with their IDE/emacs/desktop environment/shell in the name of productivity.
- foderking 3y agotrue
- moomin 3y agoHonestly, they are useful in practice, as long as you’re using a language that supports them properly (I’m not convinced TS is that language). Even without, they constitute a pattern that is very simple to implement which is very powerful. People believed (and some still do believe) the same thing about generics.
- hocuspocus 3y ago> The thing is, it takes a bit of experience to appreciate why HKT are important, and typically you can only get this experience using Haskell. They're fairly common in Scala too, and I believe in OCaml through modules.
- gpderetta 3y agoAnd C++ if you squint hard enough.
- FrustratedMonky 3y agoand F# with computations Seems common with functional programming, that it takes a mind-set change before seeing the need.