Given syntax and typeclasses for Scala > 3.3 LTS

I stumbled across these pages:

New given syntax:

Experimental typeclass stuff circa 3.5.0:

Experimental typeclass stuff circa 3.7.2:

Now, I’ve been peripherally aware that given syntax was changing post 3.3 LTS - not sure if this is to accommodate some other grammar change or has its own reasons.

What surprised me was that there is an explicit reference to what seems to be yet another syntax in the second link; it’s no longer called out explicitly in the third link, but is still present in the examples.

Now, I may simply have not fully understood all the syntax changes from the first link, but it looks like there are three forms of given syntax in play here. Have I got that right?

I appreciate the second two links come from the experimental section, so these may be just blue-sky thinking; also the documentation itself may be WIP and thus shouldn’t be taken literally.

I’m quite happy sticking with 3.3 LTS for now, but I’d like to get an idea of which version to move to post that. If things are still in flux, I’ll wait for a definitive version.

1 Like

I think you’re asking whether named givens will get as syntax?

I see is but not as syntax in the test.

They are diligent about maintaining the syntax summary, of which there are internal and external versions.

2 Likes

Thanks @som-snytt.

Playing detective based on your hot lead, I have commit 39f65b1 from July 25th 2024 that introduced both the ‘old’ new syntax that is documented in the first link, plus the ‘new’ new syntax that has the is stuff referred to in the second link, as well as the as.

Commit 0c721dc from September 30th 2024 documents the old new syntax, but not the new new syntax.

I went and had another scan of the second link, and realised that this ‘is keyword isn’t - rather it is a type constructor. Well, I think it is. So I presume this isn’t really a syntax change after all, it’s just a creative use of the old new syntax?

I’m in the dark about the as part, but would I be correct in surmising that the old new syntax is here to stay?

As an aside, the urge to say something witty about the documentation is strong. I should just desist and ask.:speak_no_evil_monkey:

1 Like

“Join the desistance!”

OK, I think I understand now.

That commit 39f65b1 also removed the syntax for as, which as far as I can tell is not documented as part of the old syntax for givens.

I guess it should be called old old syntax then, rather than new new. :sad_but_relieved_face:

So it seems we have just one new syntax for givens after all, with a nifty type constructor augmentation. Phew.

@som-snytt Your call to arms is noble, but my response must be (cue Northern England accent):

“I can’t be asked.”.

1 Like