Live data from Hacker News

Scala 3.0

github.com

51–60 of 292 posts

Re: Scala 3.0

#52
post #15

Earlier quoted context omitted.

Interesting, and I presume it works for singletons of any type, correct? val x: 1 = 1 val y: 2.718281828 = 2.718281828 That's kind of cute. I presume its main purpose is for overrides in order to get something similar to template specialization. C++ templates can be specialized by types and by values, but Scala method overrides are only by type, and literal types allow you to present a value as a type, so if the valu…

In TypeScript perhaps the most important use case for literal types is the ability to to create discriminated unions, or algebraic datatypes (ADTs). Many modern languages have a separate feature for this (such as enums in Rust), but in TypeScript they can be constructed using literal and union types. Here's an example: interface ProductOffer { kind: 'productOffer' eans: Ean[] discountPercentage: number } interface Gr…

I think it is important to emphasize that there is actually an important difference.

Union types don't allow to model GADTs, so they are less powerful than what some other languages offer. But on the other side, they allow for much easier composition. E.g.:

type Citrus = "Orange" | "Lemon" type Prunus = "Plum" | "Apricot"

Now in typescript you can just do:

type Fruit = Citrus | Prunus

But in many other languages it's not so easy and you have to jump through hoops and e.g. either redefine the types and/or refactor the code (if you can even do that - if the code is from 3rd party libraries you are out of luck).

Re: Scala 3.0

#53

Earlier quoted context omitted.

I think apart from streams it was Kotlin that did the trick.

How so? Kotlin doesn't even have proper pattern matching.

newb here -- please expand more on this.

Are there stuff that kotlin's pattern-matching can't do?

Re: Scala 3.0

#54
post #17
post #4

I get paid to write TypeScript, it has come a long way to a relatively enjoyable experience compared to how expressive i feel with Scala. Looking forward to giving Scala 3 a spin to learn whats new

As someone who has spent a lot of time diving deep into Scala (I worked on compiler related semantic tooling for scalameta, worked on a experimental parallelizable Scala compiler, and even have a single commit in this release from almost four years ago LOL), and who more recently has been working with TypeScript, I find this really interesting and agree in some ways. Scala 2.x already had path-dependent types, which…

TS is great but lack of pattern matching cripples the language somewhat

Re: Scala 3.0

#55

Earlier quoted context omitted.

> Scala is not perfect but it’s very good. I like to refer to it as Haskell with an extra chromosome: slow, hard to comprehend, and incredibly strong. I'm lucky enough to write it in my day job and I feel like I'm living life on easy mode because of it. It'd take a lot of money to lure me back to garbage like Python/JS at this point.

It has one advantage compared to Haskell though: as a Java/Kotlin (or even Python or javascript) developer, you can start with it an be productive immediately. You can then slowly absorb new concepts until you are pretty much ready to write full-fledged Haskell. That's why some call it Haskellator. :) This also means that many codebases have different styles though, whereas in Haskell you have one style (FP).

More importantly, you can use the mature ecosystem around Java (tools, libraries and so on).

Re: Scala 3.0

#56

Always wanted to look into Scala but it seemed very intimidating. Is there a good intermediate 'How to' for Scala 3 anyone can recommend?

I think the Scala 3 book [1] might be what you're looking for!

There's also an ongoing video series called "Let's talk about Scala 3" by the Scala Center and 47 Degrees [2], which are more in-depth on certain topics, but still quite beginner-friendly. Especially the video on setting up a development environment, and the video on Scala 3's data structures might be good introductions.

[1]: https://docs.scala-lang.org/scala3/book/introduction.html [2]: https://www.youtube.com/watch?v=j-H6LSv2z_8&list=PLTx-VKTe8y...

Re: Scala 3.0

#57

Earlier quoted context omitted.

How so? Kotlin doesn't even have proper pattern matching.

newb here -- please expand more on this. Are there stuff that kotlin's pattern-matching can't do?

You can find some discussion and good examples here: https://discuss.kotlinlang.org/t/destructuring-in-when/2391/...

Re: Scala 3.0

#59
post #50
post #44

Earlier quoted context omitted.

Java has not picked up a single feature from Kotlin yet (maybe nullability types someday?), and, in fact, opted for very different ones (e.g. contrast records vs. data classes, virtual threads vs. syntactic couroutines), although I guess Scala has provided some inspiration for some features, as Java's are closer to Scala's than to Kotlin's. ML is probably the biggest influence, with some Haskell flavour. But I find i…

Text blocks?

Hmm, I think Kotlin's are similar to Python's, but Java's are different (whitespace handling).
Post reply on HN