dbrattli / Expression

Pragmatic functional programming for Python inspired by F#
https://expression.readthedocs.io
MIT License
421 stars 30 forks source link

Generic monad algorithm #100

Open denghz opened 1 year ago

denghz commented 1 year ago

Is it possible to define a function that can handle multiple types of effects depends on the object that yields the effect? Like in Haskell

join :: Monad m => m (m a) -> m a
join xss = 
    do xs <- xss
       xs                            

which would work for all monads including, list, maybe, io, stm, etc... I can help about it if needed.

dbrattli commented 1 year ago

No, I don't think it's possible e.g an iterable join is very different from an observable join so each world will need a specific implementation. It will not be possible for the specific implementation to be registered as an auto-dispatch / overload. But if you have a suggestion then please feel free to explain what idea you have in mind.