gcanti / fp-ts

Functional programming in TypeScript
https://gcanti.github.io/fp-ts/
MIT License
10.81k stars 502 forks source link

[FR] Free monad for v2 #894

Closed YBogomolov closed 5 years ago

YBogomolov commented 5 years ago

🚀 Feature request

Current Behavior

Free monad was removed from v2 release (see https://twitter.com/GiulioCanti/status/1145796238924800000)

Desired Behavior

Free monad is available in v2.

Suggested Solution

I've added a naïve classless port from v1, exposing a pipeable interface: https://github.com/YBogomolov/fp-ts/blob/feature/free/src/Free.ts Can we get it back into codebase?

Who does this impact? Who is this for?

For all users of Free monads, I guess 🤷🏻‍♂️

Describe alternatives you've considered

Free overall is considered a not-so-good approach performance-wise, so I suggest taking a look at either possibility of implementing Church-encoded Free monads, or using Oleg Kiselyov's Freer monads (http://okmij.org/ftp/Haskell/extensible/more.pdf).

Additional context

I would like to discuss design decisions for this module, so I can understand all concerns and code a better implementation of Free.

YBogomolov commented 5 years ago

Note on the port: I intentionally left behind apFirst and chainFirst methods from pipeable output, as it makes close to none sense in modifying F part in Free<F, A>.

gcanti commented 5 years ago

Thanks @YBogomolov, would you mind to move the discussion to fp-ts-contrib? It would allow to experiment with different encodings without touching the core

YBogomolov commented 5 years ago

Sure. I will move the code there and create a new issue.