Closed shimib closed 7 years ago
Looks very interesting. However to be considered for inclusion in Typelevel Scala this PR should be targeted at https://github.com/scala/scala. If you do that we can pick it up from there ...
sure
currently everything is merged with other typelevel/scala work. openning a PR at lightbend/scala will add all previous commits. Should i fork directly from lightbend/scala and merge against it?
@shimib yes please, make this a standalone PR against LBS.
done! PR #5725
This is a proposal (POC) to provide a new keyword (cofor) for co-monadic comprehensions in Scala. The work is based over Dominic Orchard and Alan Mycroft paper: https://www.cl.cam.ac.uk/~dao29/publ/codo-notation-orchard-ifl12.pdf
If you find the implementation flawed, it is me to blame and not them!
the 'cofor' expression returns a function: (T[A] => B). The function's type MUST be stated explicitly in the call-site. e.g.: val result: Zipper[Person] => Boolean = cofor...
the syntax: cofor(inputpatten) { pattern1 <- gen1 pattern2 <- gen2 ... } yield body
the 'cofor' and generator must use types that provide: def map(A => B) def extract: A def coflatMap(T[A] => B)
implementation is much more complex than 'for' desugaring as stated in the paper.
current implementation supports full Scala patterns in the input and generator patterns. missing:
the flag to control the keyword: -Ycofor-extension if the flag is not enabled, current Scala code should not be affected.
compatibility: adding a new keyword breaks existing use of 'cofor' identifier and it should be back-quoted.
Plz let me know your thoughts on this.