Live data from Hacker News

Free-types: Higher kinded types in TypeScript

github.com

31–40 of 51 posts

Re: Free-types: Higher kinded types in TypeScript

#31
post #22
post #17

Earlier quoted context omitted.

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 u…

I 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.

true

Re: Free-types: Higher kinded types in TypeScript

#32
post #22
post #17

Earlier quoted context omitted.

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 u…

I 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.

Honestly, 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.

Re: Free-types: Higher kinded types in TypeScript

#33
post #25

Earlier quoted context omitted.

> No. Typescript cannot access runtime values (I assume you mean types that depend on runtime values). That's not the meaning of dependent types, and dependent type checkers don't require runtime information.

"a dependent function may depend on the value (not just type) of one of its arguments" from wikipedia https://en.wikipedia.org/wiki/Dependent_type The value does not exist during compilation. AFAIKT dependent type are used mostly during executable proof checkers to verify claims on the value-dependent types. So maybe using the term runtime is a bit to specific, but you do not have values (except literals) during type…

> The value does not exist during compilation.

    type Z = []["length"]
    type One = [0]["length"]
    type Two = [0,0]["length"]

Re: Free-types: Higher kinded types in TypeScript

#34
post #17

I'm reasonably proficient in Typescript although I wouldn't call myself an expert in type systems. But I'm not a beginner either. However, I read though the readme and I have no idea what the usefulness of this is. Can anyone explain, in simple terms, some practical use cases for this?

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 u…

> 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.

Re: Free-types: Higher kinded types in TypeScript

#35
post #5

Looking forward to a proper monad lib in Typescript! However, I can only assume that molding/abusing types like this might have a big - if not huge - impact on compilation times... I've created a template-like generic type that allows you compose multiple kinds and replace any property of an object with a function returning the same type as the property, and vscode has such a hard time inferring types that intellisen…

I'm using fp-ts https://gcanti.github.io/fp-ts/

Great tip; thank you!

Re: Free-types: Higher kinded types in TypeScript

#36
post #25

Earlier quoted context omitted.

> No. Typescript cannot access runtime values (I assume you mean types that depend on runtime values). That's not the meaning of dependent types, and dependent type checkers don't require runtime information.

"a dependent function may depend on the value (not just type) of one of its arguments" from wikipedia https://en.wikipedia.org/wiki/Dependent_type The value does not exist during compilation. AFAIKT dependent type are used mostly during executable proof checkers to verify claims on the value-dependent types. So maybe using the term runtime is a bit to specific, but you do not have values (except literals) during type…

The "value" in this case is symbolic, sort of like defining an array with variable length arr[x] and having the compiler verify that arr[x+5] is always out of bounds before knowing the actual value of x. If the type system is not powerful to prove correctness of some expression, you will need to insert a runtime check that lets the compiler to trust the value at compile time.

Re: Free-types: Higher kinded types in TypeScript

#37
post #17

Earlier quoted context omitted.

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 u…

> 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.

And C++ if you squint hard enough.

Re: Free-types: Higher kinded types in TypeScript

#38
post #13

Why

A simple example I could recall from the other day is something like this: export type LinkedWorksheetsRecord = Record >; export type LinkedWorksheetsMap = Map >; What I would rather have written instead is however something like this: export type LinkedWorksheets = T >; ... const myMap: LinkedWorksheets = ...; This is however not possible, because `Map` is a type constructor which expects two more type arguments `K,…

Thank you for the explanation, seeing a simple concrete example really helps.

Re: Free-types: Higher kinded types in TypeScript

#40
post #5

Looking forward to a proper monad lib in Typescript! However, I can only assume that molding/abusing types like this might have a big - if not huge - impact on compilation times... I've created a template-like generic type that allows you compose multiple kinds and replace any property of an object with a function returning the same type as the property, and vscode has such a hard time inferring types that intellisen…

I'm using fp-ts https://gcanti.github.io/fp-ts/

fp-ts is great and still has active development but it has also been folded into effect-ts (https://github.com/Effect-TS/) which is based on Scala ZIO. I think long-term it will have a larger ecosystem, more active development and a better DX. The docs are far from complete, but give a good intro (https://effect.website/docs/getting-started).

I'm not associated with effect-ts at all.

Post reply on HN