I often use monads in TypeScript and define them from scratch, and have always missed HKTs so I can define generic functions that apply to all monads such as a generic map
or some sort of Haskell-like do notation.
I was about to start digging into fp-ts but I just found out it’s being merged with effect-ts, which looks like a pretty neat package and as far as I understand, it uses a better way to encode HKTs.
It looks to me like Effect
is a combination of several monads into one, and I wonder if there’s a way to plug my own monads there. For instance, I want to be able to use the array monad such that I can construct an Effect<number, ...>
from an array of numbers that get flattened out when I call Effect.flatMap
. If I’m not mistaken, as long as there’s a way to use Effect as a continuation monad, I should be able to emulate every other monad, but that doesn’t seem to be the case since I can’t find any way to this. I don’t have much information about the Effect.runCallback
but it seems to me like the callback is called only once when the evaluation completes, while a real continuation would require a way to receive a callback multiple times.
So I wonder if I’m missing something or perhaps I should be using fp-ts instead since I’m interested mostly in using my own monads, and not so much about the myriad of utility functions provided by Effect.