News for hackers. Stuff that matters.
Re:How JavaScript works: 3 types of polymorphism by pr0crastin8 on Sunday May 09, 2021 @09:20PM (#27101647)
As someone quite in love with functional programming (background in Haskell and Scala), one thing that seems quite obviously missing here and in my Javascript experience so far is the use of typeclasses as a form of ad-hoc polymorphism.

Is there a nice (i.e. not too much boilerplate) way of using them in the land of Javascript/Typescript?

Re:How JavaScript works: 3 types of polymorphism by chrischen on Sunday May 09, 2021 @10:51PM (#27102200)
See https://github.com/gcanti/fp-ts. Heavily haskell-inspired and includes a TS implementation of higher-kinded types.
Re:How JavaScript works: 3 types of polymorphism by samhh on Monday May 10, 2021 @04:44AM (#27103930)
This is definitely the best option in the TS ecosystem but it's not meaningfully implementing typeclasses from the perspective of the end user. There's no single `fmap` for example, instead you'll be using dedicated `Array.map`, `Option.map`, etc.
Re:How JavaScript works: 3 types of polymorphism by shirogane86x on Monday May 10, 2021 @10:27AM (#27106307)
As far as i remember there's functions that take explicit typeclass dictionaries (that you can compose via contramap). So I guess they sort of do typeclasses, but without implicits, which is pretty painful IME. Example: https://gcanti.github.io/fp-ts/modules/Functor.ts.html#map