Proposal: syntactic sugar for proxies

I’m not sure if this has been proposed already, but after writing PS for ~7 months now, I find that the bit of syntactic sugar I find myself wanting most is a shorter way to write.

a = Proxy :: Proxy Int

I’m not sure if this has been proposed already, nor do I know what would be the best solution. Some candidates:

  • @Int
  • !Int
  • ^Int
  • :muscle:Int
  • :arrow_down:Int

With perhaps the same operatoin at the type level.

I think this would make code that makes heavy use of proxies easier to write and read.

z = @Int

foo :: forall z x. (@z -> x) -> x
foo i = i @z

Compared to:

z = Proxy :: Proxy Int

foo :: forall z x. ((Proxy :: Proxy z) -> x) -> x
foo i = i (Proxy :: Proxy z)

Thoughts? If this seems reasonable, I can take a crack at a PR (it’d be my first to purescript/purescript … gulp …).

I think there’s multiple mentions of proxy syntax in purescripts issue tracker, including https://github.com/purescript/purescript/issues/3137

You can make it slightly more terse already by using wildcards: p = (Proxy :: _ Int). Indeed you could also alias Proxy to get it even smaller

I think that purs was once already there (with @Int syntax) but the feature was somewhat problematic and didn’t land in the official compiler release.

It was problematic because the kind checker was broken. With PolyKinds it wouldn’t be an issue, but I think visible type applications is what we really want anyway.

4 Likes

Thanks. I didn’t know about the wildcard syntax. P :: _ Int is indeed more terse than Proxy :: Proxy Int, although I’d have to write it out several times to get a sense if it is more readable. I agree with Nate that visible type applications would be better as that’s a superset of what I’m talking about. Is there a GH issue and/or PR for that yet?

I’m pretty sure the @TypeName wasn’t added in v0.14.0 because we were first deprecating the @ symbol so that it wasn’t allowed anywhere except in pattern matching:

case _ of
  foo@(Tuple a b) -> ...

It was my understanding that it would be added in v0.15.0, but I’m not sure. I also haven’t read through the above linked issue.

1 Like