3 ms·
and you would use it ... how?
by zabzonk 4y ago
and you would use it ... how?
- deleted 4y ago[deleted]
- dcow 4y agoIt's not exactly Java, but: Cons(1, Cons(2, Cons(3, Nil)))
- kaba0 4y agoActually, Java does have sum types nowadays, and you can write a recursive list implementation like “new Cons(2, new Cons(3, Nil.nil()))”. Here is a definition for a Maybe type, converting it to a List is left as an exercise to the reader :) : https://news.ycombinator.com/item?id=35133670 https://news.ycombinator.com/item?id=35133670
- dcow 4y agoI just meant because I was eliding the `new`s.
- the-smug-one 4y agoI've showed you an alternative encoding, maybe get to work and learn something yourself?