Comments on: Abstracting with Applicatives http://comonad.com/reader/2012/abstracting-with-applicatives/ types, (co)monads, substructural logic Sat, 29 Dec 2012 15:18:06 -0800 http://wordpress.org/?v=2.8.4 hourly 1 By: Edward Z. Yang http://comonad.com/reader/2012/abstracting-with-applicatives/comment-page-1/#comment-107149 Edward Z. Yang Sat, 29 Dec 2012 15:18:06 +0000 http://comonad.com/reader/?p=756#comment-107149 Cool post, reminds me about a similar observation I made about the writer monad (http://blog.ezyang.com/2012/10/generalizing-the-programmable-semicolon/); namely, that the tracing behaviour of writer is independent of the computational component. Cool post, reminds me about a similar observation I made about the writer monad (http://blog.ezyang.com/2012/10/generalizing-the-programmable-semicolon/); namely, that the tracing behaviour of writer is independent of the computational component.

]]>
By: Gershom Bazerman http://comonad.com/reader/2012/abstracting-with-applicatives/comment-page-1/#comment-107130 Gershom Bazerman Thu, 27 Dec 2012 17:45:23 +0000 http://comonad.com/reader/?p=756#comment-107130 Thanks for the comments -- I've fixed the post appropriately. I came across "Sum" on my own, and I wasn't familiar with the "Lift" specialization of it in transformers. Not surprised that Conor and Ross beat me to it! As the edited post notes, we can't actually add that Identity instance for Natural without overlapping too often with the Const instance. The poor typechecker can't decide if it should send everything to Const, or Identity to anything. Thanks for the comments — I’ve fixed the post appropriately. I came across “Sum” on my own, and I wasn’t familiar with the “Lift” specialization of it in transformers. Not surprised that Conor and Ross beat me to it!

As the edited post notes, we can’t actually add that Identity instance for Natural without overlapping too often with the Const instance. The poor typechecker can’t decide if it should send everything to Const, or Identity to anything.

]]>
By: Oliver Charles http://comonad.com/reader/2012/abstracting-with-applicatives/comment-page-1/#comment-107128 Oliver Charles Thu, 27 Dec 2012 16:53:09 +0000 http://comonad.com/reader/?p=756#comment-107128 In the example of the FailingWriter, you write 'runFailingWriter $ ...', but don't provide a definition of it. From the actual output, I don't think you actually meant to write it, as the current output makes it seem that the definition would just be `id`. Or perhaps you meant to provide a definition that would yield a different output, perhaps (monoid, Maybe a), stripping away the newtype noise? In the example of the FailingWriter, you write ‘runFailingWriter $ …’, but don’t provide a definition of it. From the actual output, I don’t think you actually meant to write it, as the current output makes it seem that the definition would just be `id`. Or perhaps you meant to provide a definition that would yield a different output, perhaps (monoid, Maybe a), stripping away the newtype noise?

]]>
By: Sjoerd Visscher http://comonad.com/reader/2012/abstracting-with-applicatives/comment-page-1/#comment-107123 Sjoerd Visscher Thu, 27 Dec 2012 10:05:29 +0000 http://comonad.com/reader/?p=756#comment-107123 Great article! I came across the Sum applicative for the first time just two days ago in this comment on Stack Overflow by Conor McBride [1]. There he notes Identity is the initial Applicative functor, so you can replace that last Natural instance with: instance Applicative g => Natural Identity g where eta (Identity x) = pure x [1] http://stackoverflow.com/questions/14022791/what-is-control-applicative-lift-useful-for/14022871#comment19369023_14022871 Great article!

I came across the Sum applicative for the first time just two days ago in this comment on Stack Overflow by Conor McBride [1]. There he notes Identity is the initial Applicative functor, so you can replace that last Natural instance with:

instance Applicative g => Natural Identity g where
eta (Identity x) = pure x

[1] http://stackoverflow.com/questions/14022791/what-is-control-applicative-lift-useful-for/14022871#comment19369023_14022871

]]>
By: Edward Kmett http://comonad.com/reader/2012/abstracting-with-applicatives/comment-page-1/#comment-107120 Edward Kmett Thu, 27 Dec 2012 01:52:27 +0000 http://comonad.com/reader/?p=756#comment-107120 Const c >>= f doesn't work return a >>= f = f a is a Monad law. Consider: return a >>= \ _ -> Const "hello" But from that definition return a >>= \ _ -> Const "hello" = Const "" but (\ _ -> Const "hello") a = Const "hello" Your proposal only works when mempty is the only value of your monoid. It works for Const (), but nothing else really. Const c >>= f doesn’t work

return a >>= f = f a is a Monad law.

Consider:

return a >>= \ _ -> Const “hello”

But from that definition

return a >>= \ _ -> Const “hello” = Const “”

but

(\ _ -> Const “hello”) a = Const “hello”

Your proposal only works when mempty is the only value of your monoid. It works for Const (), but nothing else really.

]]>
By: Luke Palmer http://comonad.com/reader/2012/abstracting-with-applicatives/comment-page-1/#comment-107119 Luke Palmer Thu, 27 Dec 2012 01:46:22 +0000 http://comonad.com/reader/?p=756#comment-107119 Oh, I see. You couldn't define bind in a way that is consistent with the Applicative instance (and we had Monoid c anyway so return wouldn't have been a problem). Sloppy reading :-/ Oh, I see. You couldn’t define bind in a way that is consistent with the Applicative instance (and we had Monoid c anyway so return wouldn’t have been a problem). Sloppy reading :-/

]]>
By: Luke Palmer http://comonad.com/reader/2012/abstracting-with-applicatives/comment-page-1/#comment-107118 Luke Palmer Thu, 27 Dec 2012 01:43:23 +0000 http://comonad.com/reader/?p=756#comment-107118 It seems to me that the reason that Const c is not a monad is because of return, not bind. Const c >>= f = Const c should do the trick. It seems to me that the reason that Const c is not a monad is because of return, not bind. Const c >>= f = Const c should do the trick.

]]>