
foo :: Applicative f => f String foo = do x <- pure "this works" pure x ... but replace "pure x" with "pure $ x" and it doesn't typecheck: a monad instance is required! Tom

Think of the types of
pure x
And
pure $ x
--
--
Sent from an expensive device which will be obsolete in a few months! :D
Casey
On Jun 16, 2016 9:06 AM,
foo :: Applicative f => f String foo = do x <- pure "this works" pure x
... but replace "pure x" with "pure $ x" and it doesn't typecheck: a monad instance is required!
Tom _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

They're the same:
:t \x -> pure x \x -> pure x :: Applicative f => a -> f a :t \x -> pure $ x \x -> pure $ x :: Applicative f => a -> f a
Tom
El 16 jun 2016, a las 12:24, KC
escribió: Think of the types of
pure x
And
pure $ x
-- --
Sent from an expensive device which will be obsolete in a few months! :D
Casey
On Jun 16, 2016 9:06 AM,
wrote: foo :: Applicative f => f String foo = do x <- pure "this works" pure x ... but replace "pure x" with "pure $ x" and it doesn't typecheck: a monad instance is required!
Tom _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

I expect it's that the root of the expression on the last line is ($) and not pure. ApplicativeDo has restrictions on what you can do to avoid allowing blocks that have to translate in terms of join/(>>=), and likely one of them is that the last line can't be an arbitrary thing of the right type. On 6/16/2016 12:30 PM, amindfv@gmail.com wrote:
They're the same:
:t \x -> pure x \x -> pure x :: Applicative f => a -> f a :t \x -> pure $ x \x -> pure $ x :: Applicative f => a -> f a
Tom
El 16 jun 2016, a las 12:24, KC
mailto:kc1956@gmail.com> escribió: Think of the types of
pure x
And
pure $ x
-- --
Sent from an expensive device which will be obsolete in a few months! :D
Casey
On Jun 16, 2016 9:06 AM,
mailto:amindfv@gmail.com> wrote: foo :: Applicative f => f String foo = do x <- pure "this works" pure x
... but replace "pure x" with "pure $ x" and it doesn't typecheck: a monad instance is required!
Tom _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org mailto:Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Wow, that's pretty unexpected. Another repro case: p = pure bar :: Applicative f => f a bar = do x <- pure "ok" p x ... gives the same error. So ApplicativeDo statements *must* end with exactly the statement "pure"?
El 16 jun 2016, a las 12:39, Joe Quinn
escribió: I expect it's that the root of the expression on the last line is ($) and not pure. ApplicativeDo has restrictions on what you can do to avoid allowing blocks that have to translate in terms of join/(>>=), and likely one of them is that the last line can't be an arbitrary thing of the right type.
On 6/16/2016 12:30 PM, amindfv@gmail.com wrote: They're the same:
:t \x -> pure x \x -> pure x :: Applicative f => a -> f a :t \x -> pure $ x \x -> pure $ x :: Applicative f => a -> f a
Tom
El 16 jun 2016, a las 12:24, KC
escribió: Think of the types of
pure x
And
pure $ x
-- --
Sent from an expensive device which will be obsolete in a few months! :D
Casey
On Jun 16, 2016 9:06 AM,
wrote: foo :: Applicative f => f String foo = do x <- pure "this works" pure x ... but replace "pure x" with "pure $ x" and it doesn't typecheck: a monad instance is required!
Tom _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

On Thu, Jun 16, 2016 at 12:49:03PM -0400, amindfv@gmail.com wrote:
Wow, that's pretty unexpected. Another repro case:
p = pure
bar :: Applicative f => f a bar = do x <- pure "ok" p x
... gives the same error. So ApplicativeDo statements *must* end with exactly the statement "pure"?
That's pretty strange since it has a perfectly good Applicative interpretation: fmap p (pure "ok") Tom

Hello, Tom.
I think you can find this ticket relevant:
https://ghc.haskell.org/trac/ghc/ticket/11835
--
Alexander
On 16 June 2016 at 19:08,
foo :: Applicative f => f String foo = do x <- pure "this works" pure x
... but replace "pure x" with "pure $ x" and it doesn't typecheck: a monad instance is required!
Tom _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-- Alexander
participants (5)
-
Alexander V Vershilov
-
amindfv@gmail.com
-
Joe Quinn
-
KC
-
Tom Ellis