Higher-Kinded Types (HKT) #1276
Replies: 2 comments 1 reply
-
Hello, thanks for your thorough proposal. One thing I am interesting in when considering extension to the language is the impact it will have on the ergonomics of the language. Having HKTs in Gleam would open the door to more sophisticated polymorphism but it is not clear what practical problems this would solve for Gleam programmers. HKTs would add some amount of complexity to the language which is in tension with Gleam's goal of being simple and easy to learn, so we want a clear reason to accept that complexity. I would like to collect practical examples of Gleam code which could be improved with HKTs, and we can then compare it to alternative designs and features to see which would be the best improvement for the lowest cost. |
Beta Was this translation helpful? Give feedback.
-
TL;DR:
That would be nice to have before we run into the need of it. And this is not a thing that sticks in front of the language and "you shall not pass"-es people 'till they learn it. I don't ask to rewriting the stdlib, it would stay unchanged. Most users will not even notice that this is a thing - and since it generalizes current behaviour, 99.9% of the code will continue to work. I'm leaving 0.1% for those who use name The lack of HKT is a limitation that will prevent some clever stuff from helping people - like functors and applicatives (parsers and validators made using appicatives are very good). P.S.: The current limitation looks almost artifical. |
Beta Was this translation helpful? Give feedback.
-
Problem
At the moment, Gleam only supports type variables which are simple types, not generics themselves. Therefore, you cannot abstract over a generic.
Proposition
It is possible to introduce HKT into the language without changing existing userspace code. I'd like to fork and try adding HKTs into the language.
The PROs of the change are:
map
,foldr
and other operations that abstract over container type.The CONs are:
Syntax changes
Type
;Here is a piece of code demonstrating all changes:
Implementation
Currently, the "kind-check" is implemented as comparison of formal argument count and real argument supplied. I plan to add a proper kind-check.
There are 2 ways to do it that I know, which I need your help to select:
Add a separate notion of kind
This way we can say that each value has a type
value: type
and each type has kindtype : kind
.I propose two syntactic forms in this case:
Type
or*
- a kind of types, that can have a value, likeInt
,String
,List(Int)
and so on;k1 -> k2
- a kind of type functions, wherek1
andk2
are kinds, likeList : Type -> Type
.PROs:
CONs:
Type : Type
In this case, we say that types have types, not kinds, and add
Type
, a type of all types.CONs:
pub fn id (a : Type, x : a)
;PROs:
id(@Int, 1)
, we just enable them back.Conclusion
I'd like any feedback about those methods, the syntactic changes and the HKT itself.
Beta Was this translation helpful? Give feedback.
All reactions