-
Notifications
You must be signed in to change notification settings - Fork 106
New blog post: EDSLs as functions #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
} | ||
``` | ||
|
||
This works.. to the extent that we want only to work with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two dots?
``` | ||
|
||
We've parameterized our language with a [higher-kinded type][hkt] which | ||
represents the context of our set. We can then write mini-programs which talks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a native speaker, but shouldn't this read "mini-programs that talk …"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @larsrh, it should be talk and not talks.
set (think `Set[Int] => A` or `Set[Int] => Future[A]`). | ||
|
||
```scala | ||
trait SetLang[F[_]] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO this additional abstraction step could use some more thorough explanation. The two examples are good, but why not implement the trait
for one of them?
Or maybe emphasize that you're now talking about the effects of performing operations on something set-like, instead of dealing with the set-like things themselves.
and si2712fix-plugin 1.2.0 using [tut][tut].* | ||
|
||
[cats]: https://github.com/typelevel/cats "Typelevel Cats" | ||
[hkt]: http://typelevel.org/blog/2016/08/21/hkts-moving-forward.html "Higher-kinded types: the difference between giving up, and moving forward" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use post_url
here too
Fortunately we are now in a position to leverage a powerful tool: | ||
[monads][monads]. By extending our set language with monadic powers, | ||
we recover composition in an elegant way. The [Cats][cats] library is used | ||
for demonstration purposes, but discussion applies equally to [Scalaz][scalaz]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"but discussion applies to"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be "...but the discussion..."
// Instance | ||
|
||
type SetState[A] = State[Set[Int], A] | ||
implicit val stateInstance: MonadSet[SetState] with MonadCalc[SetState] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, you have successfully modularised and composed programs, but not the underlying implementations. It could be worth mentioning that you can also split up this instance into two.
I'm planning to finish #119 by Sunday, so hopefully you'll be able to contribute this as a |
I changed the base of this pull request to |
Probably not happening today, got a talk I got to prepare for on Monday and lots of stuff happening at $JOB. Put please still leave comments! *nudges @S11001001 * ;) |
all traces of `Set`. | ||
|
||
```scala | ||
trait SetLang[F[_]] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such a type parameter would be *-kinded in a sensible refinement of this algebra in a direction other than the one you're about to take. 😊 You're paving the way for the monadic variant, but as a foundation, this one's a little shaky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm could you expand on your comment a bit? I'm definitely biasing the post towards the monadic variant, but would be interested in hearing more about a different direction/guidance on how I can better present this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah wait I think I know what you mean now, sounds good. Will adjust wording, thanks!
Interpretation of our language is straightforward, by implementing `SetLang` and | ||
passing in the corresponding implementation to `program`. | ||
|
||
Our language is still limited. `F` is arbitrarily designated to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that the language is too powerful, not that it's limited. The capabilities it provides are so strong as to prevent you from writing the kinds of interpreters you are interested in writing, but there is no “better than” rule here—your redesign admits those interpreters only by forbidding many programs that formerly could be written in SetLang
.
``` | ||
|
||
Our new encoding introduces a new but very important problem: how do we | ||
compose? In the previous encoding we could add and then remove by threading |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“combine the results of multiple calls to SetLang
methods?”, perhaps? I have a peeve about the mention of composition without specifying what kind of composition is meant.
|
||
While `App1` and `App2` are both valid compositions, the | ||
semantics of the compositions differ. `App1` describes a program where | ||
the computation of a *value* at each transition may fail whereas `App2` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…may fail—but any changes in state are preserved—whereas…
def monad: Monad[F] | ||
|
||
def raiseError[A](e: E): F[A] | ||
def handleErrorWith[A](fa: F[A])(f: E => F[A]): F[A] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A simpler encoding of handleErrorWith
may be
[A](fa: F[A]): F[Either[E, A]]
Assuming Functor[F]
, it's equally powerful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Er, Monad
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah interesting, I'll play around and see which one ends up being easier to talk about. Thanks!
Feedback incorporated. Ran into a weird state with the new development branch so I reset --hard to upstream/development and redid the patch :/ Assuming everything looks OK let's schedule this for Wednesday Oct 26. |
@adelbertc Sorry I made you go through a Git hassle 😟 But the changes look good. |
No worries, change was worth it I think :) |
Thanks everyone for the review and feedback, really helpful, I really appreciate it! Probably the main reason I write for this blog, to get peer review, fact checking, and very useful comments. Going to merge this now. |
Scheduled for Wednesday October 12.
cc @S11001001