dex-lang icon indicating copy to clipboard operation
dex-lang copied to clipboard

Use < > brackets for effects

Open duvenaud opened this issue 2 years ago • 5 comments

With the introduction of using {} in type signatures to implicitly quantify over variables, there are now 3 distinct uses of curly braces that all show up in type signatures:

  1. implicit quantification
  2. records
  3. effects

The effect syntax also uses vertical bars |, which make their syntax confusingly close to that of variants. For example, here are two different type signatures in the prelude:

One to do with effects:

def liftState {a b c h eff} (ref: Ref h c) (f:a -> {|eff} b) (x:a) : {State h|eff} b =

One to do with variants:

Iso {foo: a | ...b} (a | {|...b}))

So I suggest we use angle brackets < > for effects. They aren't used at all in the current syntax. They would also give a more explicit nod to Koka for developing some of these ideas.

duvenaud avatar Mar 10 '22 18:03 duvenaud

I'd be in favor of that. I think the reason I went with {} rather than <> initially was that <> looks strange when you write a function's type, because it conflicts with the -> arrow a bit: a -> <eff> b. But I don't think it's a major problem, and we almost exclusively use def syntax these days anyway.

dougalm avatar Mar 10 '22 18:03 dougalm

Oh yeah, I forgot about the angle bracket in ->.

duvenaud avatar Mar 10 '22 19:03 duvenaud

For reference,

Unison uses curly braces as well, https://www.unison-lang.org/learn/language-reference/ability-declaration/. Koka uses nothing or <> when necessary, https://koka-lang.github.io/koka/doc/book.html#sec-effect-types. Eff uses =>, https://www.eff-lang.org/handlers-tutorial.pdf, I think (unclear due to absence of docs). Frank uses [], https://github.com/frank-lang/frank/blob/master/examples/exception.fk.

You may want to add Dex to the list here: https://en.wikipedia.org/wiki/Effect_system :D

tscholak avatar Mar 14 '22 21:03 tscholak

Oh, I guess I need to look at real Koka code, I was basing my assertion on the old 2016 Koka paper

duvenaud avatar Mar 15 '22 01:03 duvenaud

I think we can't do what Koka does today, because that's too similar to function application. Koka uses parens, which makes their current syntax unambiguous. But I've been wanting to switch us to angle brackets for a while, so let's do it!

apaszke avatar Mar 15 '22 09:03 apaszke