Skip to content
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

Implicits #68

Closed
wants to merge 19 commits into from
Closed

Implicits #68

wants to merge 19 commits into from

Conversation

b-studios
Copy link
Member

@b-studios b-studios commented Jun 9, 2018

First draft of implementing implicits in terms of effect handlers

This PR is just for discussion and not meant to be merged

@b-studios
Copy link
Member Author

b-studios commented Jun 9, 2018

The current design allows users to write programs like (I'll keep this updated)

implicit ^x : int
implicit ^y : int
implicit ^foo<a> : (a, a)

fun test() : ^x int {
  ^x + ^x
}

fun test2() {
  val ^x = { "hello".print; ^x + 4 }
  test()
}

fun res() {
  val ^x = 3
  test2()
}

val manual = handle(test) { ^x() -> resume(4) }

fun test3() {
  ^x + ^y
}

fun test4() : < ^foo<int> > int {
  ^foo.fst + ^foo.snd
}

if operations look like implicit parameters, we can use the sugar on them

effect manualImplicit {
  fun ^man() : int
}

fun test5() {
  ^man + ^x
}

fun test5handled() {
  val ^man = 42
  val ^x = 2
  test5()
}

@b-studios
Copy link
Member Author

b-studios commented Jun 11, 2018

I now turned implicits into legal identifiers. Using the ? prefix however conflicted with generated names. As a workaround I just picked the ^ prefix for now. I updated the above code example accordingly.

Of course the syntax can only be temporary as it also conflicts with exponentials.

@b-studios
Copy link
Member Author

I added with-expression syntax since the implicit val bindings get quite clunky very fast:

with (^x = 4, ^y = ^x+2) test3()

for

{
val ^x = 4
val ^y = ^x + 2
test3()
}

@b-studios
Copy link
Member Author

Ok, I switched back to ?x syntax. To avoid names that include -? I changed makeHiddenName to replace the ? by implicit- so operation name look like .op-implicit-x. Of course, there still can be name clashes if users define operations implicit-x.

@b-studios b-studios changed the base branch from master to dev June 12, 2018 04:29
@b-studios b-studios mentioned this pull request Jun 12, 2018
@b-studios b-studios closed this Jun 12, 2018
@b-studios b-studios mentioned this pull request Jun 14, 2018
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.

None yet

1 participant