Hacker News new | past | comments | ask | show | jobs | submit login

Does Kotlin have algebraic types? Possibly via sealed traits or the like, similar to Scala?



Kotlin has sealed classes. It also has built in generic Pair and Triple containers. But no it doesn't really have algebraic types as you see in Haskell. For example, you can't build a linked list by `cons`ing Ints and Strings and then take the dot product with another Int-String list. It still relies on generics in that regard although it does make improvements with reified types (generics that are retained at runtime for use in type checking `is`--kotlin `instanceof`) and variance indicators.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: