effectful icon indicating copy to clipboard operation
effectful copied to clipboard

Use superclasses of Monad where applicable

Open ritschwumm opened this issue 11 years ago • 6 comments

quite often, you don't need the full power of a monad and the corresponding applicative functor is sufficient. these cases could be detected by the macro.

additionally, there are at least some monads where there is a "better" (more performant, less blocking...) way to implement the <*> operation than the default using bind.

would it be possible to exploit this fact to generate code that directly calls <*> instead of bind?

ritschwumm avatar Apr 28 '13 20:04 ritschwumm

:+1: Great idea! It makes sense that monad syntax should basically boil down to a kind of idiom brackets when you're only using the power of Applicatives. And it's quite doable I think.

pelotom avatar Apr 28 '13 21:04 pelotom

While we're at it, might as well also only require Functor when we only need to use map.

pelotom avatar May 03 '13 19:05 pelotom

might be inspirational: http://ghc.haskell.org/trac/ghc/wiki/ApplicativeDo

ritschwumm avatar Oct 09 '13 18:10 ritschwumm

I saw that, very cool.

On somewhat tangential note I'd love to see Haskell's do-notation enhanced with inline unwrapping of effects; it'd be awesome if within a do block you could use a kind of unwrapping syntax like <expr> to extract a pure value from an expr: m a, e.g.

do { putStrLn "Enter a number:"; putStrLn "Your number plus one: " ++ show (<readLn> + 1) }

pelotom avatar Oct 09 '13 18:10 pelotom

:+1:

aryairani avatar Jul 01 '15 00:07 aryairani

:thumbsup:

Just tried using this on ValidationNel and found that out: effectfully( foo(a!, b!) ) gives me: value ! is not a member of scalaz.ValidationNel[String,String]

LeifW avatar Dec 28 '15 10:12 LeifW