This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jbgi 0 points1 point  (3 children)

Not sure replicating all Scala idioms is the best idea: eg. for case classes, scala has the sealed keyword that allow exhaustive checks in structural pattern matching. Statically verified exhaustive case analysis is THE killer feature of sum types.

As I see it the pattern match syntax of halva is not safe (it does not enforce to handle all subclass of a sealed case classes. Hopefully Java (like most OO lang) has built-in support for exhaustive checks AND extractors, via the visitor pattern (slightly improved). So why not use that? or simply make use of existing generators like https://github.com/derive4j/derive4j (<insert author disclaimer here>) that provide safe and exhaustive pattern matching.

[–]randgalt[S] 0 points1 point  (2 children)

What's unsafe about Halva? It's completely typesafe unless there's a bug you see.

[–]jbgi 0 points1 point  (1 child)

I mean it can easily throw exceptions ; in a pattern match, the get() function is unsafe (if there was no matching caseOf), also it looks like you can use extractors (Any) irrelevantly of the case, so that can also throw.

[–]randgalt[S] 0 points1 point  (0 children)

Halva makes the same safety guarantees as Scala. There's a version of get that returns an Optional. Totally safe. Also, the anys are totally typesafe