Ticket #3136 (closed feature request: invalid)

Opened 4 years ago

Last modified 4 years ago

monad syntax extension

Reported by: neodymion Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.10.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

allow this:

print (readInt [<getLine>] + readInt [<getLine>])

(or some other kind of funky brackets) to translate into

getLine>>=\x->getLine>>=\y->print (readInt x + readInt y)

Change History

Changed 4 years ago by NeilMitchell

This is the kind of thing that should be discussed, and refined, perhaps on a wiki, before raising a bug for it.

I've seen Simon PJ talk about the syntax:

print (readInt (<- getLine) + readInt (<- getLine))

There was a whole discussion on it, which raised things like which do block are these floated to, and now do x /= x by a very long way.

Changed 4 years ago by claus

And if you believe the advocates of Control.Applicative, this becomes:

>let readInt a = read a::Int
>:m +Control.Applicative
>print =<< ((+) <$> (readInt <$> getLine) <*> (readInt <$> getLine))
1
2
3

or even

>:set -XNoMonomorphismRestriction
>let (+) = liftA2 (Prelude.+)
>print =<< ((readInt <$> getLine) + (readInt <$> getLine))
2
3
5

Changed 4 years ago by igloo

  • status changed from new to closed
  • difficulty set to Unknown
  • resolution set to invalid

I agree with Neil; I think a design needs to be worked out in another forum before it is useful to have a ticket for this.

Note: See TracTickets for help on using tickets.