desugaring Scala for comprehensions

167 views
Skip to first unread message

Philip Durbin

unread,
Jun 9, 2014, 8:29:11 AM6/9/14
to java...@googlegroups.com
At around 24:45 at http://javaposse.com/java-posse-452 Dick said he's been thinking of doing a blog post about desugaring Scala for comprehensions. Any news on this? Thanks.

clay

unread,
Jun 19, 2014, 2:35:10 PM6/19/14
to java...@googlegroups.com
I can't answer your direction on Dick Wall's post, but to briefly comment on Scala for comprehensions:

- They desugar into map/flatMap and filter if you use the for filter.
- Martin Odersky himself explains for comprehensions including the desugar process in his part of the Reactive programming course on Coursera. You can watch the video lectures online for free and I believe still do the programming exercises and get automated scoring. They are quite fun.
- Scala's for comprehensions are extremely similar and almost surely inherited from Haskell's do notation. Haskell's "do" notation simply expands into flatMap aka bind aka "(>>=)" calls in Haskell for Monad types.

clay

unread,
Jun 19, 2014, 2:36:14 PM6/19/14
to java...@googlegroups.com
edit: I can't answer your "direct question"...

I wish this forum had edit functionality.

Eric Pederson

unread,
Jun 20, 2014, 3:08:48 PM6/20/14
to java...@googlegroups.com
The desugaring is also explained in detail in Odersky's book "Programming in Scala" here: http://www.artima.com/pins1ed/for-expressions-revisited.html#23.4
Reply all
Reply to author
Forward
0 new messages