Skip to content

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

Merged
merged 1 commit into from
Oct 26, 2016

Conversation

adelbertc
Copy link
Contributor

@adelbertc adelbertc commented Oct 7, 2016

Scheduled for Wednesday October 12.

cc @S11001001

}
```

This works.. to the extent that we want only to work with
Copy link
Contributor

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
Copy link
Contributor

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 …"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is the same

Copy link
Contributor

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[_]] {
Copy link
Contributor

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"
Copy link
Contributor

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].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"but discussion applies to"?

Copy link
Contributor

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] =
Copy link
Contributor

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.

@larsrh
Copy link
Contributor

larsrh commented Oct 7, 2016

I'm planning to finish #119 by Sunday, so hopefully you'll be able to contribute this as a tut document.

@larsrh larsrh changed the base branch from master to development October 9, 2016 21:04
@larsrh
Copy link
Contributor

larsrh commented Oct 9, 2016

I changed the base of this pull request to development, so you have to move your post into the posts folder. Sorry about the hassle!

@adelbertc
Copy link
Contributor Author

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[_]] {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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`
Copy link
Contributor

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]
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, Monad.

Copy link
Contributor Author

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!

@adelbertc
Copy link
Contributor Author

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.

@larsrh
Copy link
Contributor

larsrh commented Oct 25, 2016

@adelbertc Sorry I made you go through a Git hassle 😟 But the changes look good.

@adelbertc
Copy link
Contributor Author

No worries, change was worth it I think :)

@adelbertc
Copy link
Contributor Author

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.

@adelbertc adelbertc merged commit 52ee311 into typelevel:development Oct 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants