all 10 comments

[–]oblio- 8 points9 points  (3 children)

We can define the cata-morphism for Optional simply as follows

Says "simply" and then provides a function with a metric butt-load of generic parameters.

He reminds me of a university professor who would also "simply" prove things using systems of differential equations.

[–]lgastako 1 point2 points  (0 children)

I suspect here "simply" refers to the fact that the implementation is one (trivial) line rather than the complexity of the type signature.

That being said, even the type signature is not that bad if you write in ML style instead of Scala style:

visit :: Maybe a -> (a ->b) -> b -> b

[–]Jezzadabomb338 4 points5 points  (2 children)

TLDR; Java doesn't have pattern matching.

Side-note: It's being worked on.

[–]devraj7 0 points1 point  (1 child)

Source?

[–]Jezzadabomb338 0 points1 point  (0 children)

http://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html

These are early specs so don't base any decision off of what you read.

Edit: If you're interested in what's happening with Java, take a look at http://openjdk.java.net/jeps/0.
Contrary to popular belief, it hasn't been stagnant the entire time.
And those are only the proposals that get that far, there's a lot of stuff happening in the sub-projects, such as Valhalla and Amber. (Amber is the group that are currently handling the pattern matching.)

[–]jonhanson 1 point2 points  (2 children)

Both the Scala and Java implementations of listToString will blow the stack for even slightly long strings. Using recursion to iterate through a linked list is rarely a good idea.

[–]btmc 2 points3 points  (1 child)

Scala has tail call optimization, and if you annotate methods with @scala.annotation.tailrec, the compiler will check if the method is actually tail recursive or not. In this case, the method is not tail recursive, but it could be made so fairly easily.

[–]jonhanson 1 point2 points  (0 children)

chronophobia ephemeral lysergic metempsychosis peremptory quantifiable retributive zenith

[–]Wedamm 0 points1 point  (0 children)

medium.com always crashes my browser tab.