fsprojects / FSharpPlus

Extensions for F#
https://fsprojects.github.io/FSharpPlus
Apache License 2.0
844 stars 94 forks source link

Free monad with trampoline #437

Open padzikm opened 3 years ago

padzikm commented 3 years ago

Hi, are there any plans to add trampoline to this library? free monad with trampoline would be great to use in safe stack manner - currently free monad is not stack safe

gusty commented 3 years ago

There are no concrete plans, but we're open, if you can add more details and draft a concrete proposals we can consider it.

padzikm commented 3 years ago

I'll play around with that and maybe be able to help. Scala's cats looks like a nice source of inspiration - https://github.com/typelevel/cats/blob/main/free/src/main/scala/cats/free/Free.scala Furhermore it would be greate to be able to easily combine coproducts without manually getting into details like in https://underscore.io/blog/posts/2017/03/29/free-inject.html. Btw why free monads are so marginal in f#? I've seen couple mentions of 'do not use them in .net' and 'they are close to be considered as antipattern'. Honestly with help from f#+ library it looks quite easy and I think we should encourage other developers to learn free and let them see if it can help and not scaring them away at the start

voronoipotato commented 2 years ago

I think it's that free monads are powerful enough that people will reach for the pattern when some functions and DU will do. I've seen the same critique of free monad use even within haskell blogs. You can write nearly anything in terms of a Free monad, but you probably shouldn't as they will be slower and more complex. Being said I think F#+ is the exact space where support the free monad could be valuable. I'm less worried about people using it as a "golden hammer" as the terser syntax in F#+ operators implies that users have a degree of comfort with FP patterns and it will be easier for people to use where it makes sense.