google-research / dex-lang

Research language for array processing in the Haskell/ML family
BSD 3-Clause "New" or "Revised" License
1.56k stars 106 forks source link

Use < > brackets for effects #787

Open duvenaud opened 2 years ago

duvenaud commented 2 years ago

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.

dougalm commented 2 years ago

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.

duvenaud commented 2 years ago

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

tscholak commented 2 years ago

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

duvenaud commented 2 years ago

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

apaszke commented 2 years ago

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!