Hi, I am from functional programming language background( Standard ML), but work in a java company now. I really miss the Algrebaric data type.
data List a = Nil | Cons a (List a)
It create a base type ‘List’, and two subtype ‘Nil’ and ‘Cons’.
I think sealed class is a kind of Algebraic Data type. Below is what I try in Kotlin
sealed class List<T> class Nil<T> : List<T>() data class Cons<T>(val a : T, val b : List<T>) : List<T>()
Does the Nil type must have generic in definition? Is there any better way?