By Alvin Alexander. Last updated: October 29, 2014
URL
The link is an article that discusses how to implement algebraic data types in Scala. In short, Haskell defines ADTs like this:
data Bool = False | True
In Scala you implement ADTs like this:
sealed abstract class Bool case object True extends Bool case object False extends Bool
which lets you do things like this:
val not : Bool => Bool = ( b : Bool ) => if( b eq True ) False else True val and : ( Bool, Bool ) => Bool = ( a :Bool, b: Bool ) => if( a eq False ) False else b val or : ( Bool, Bool ) => Bool = ( a :Bool, b: Bool ) => if( a eq True ) True else b println( and( or( True, not( True ) ), not( False ) ) )
The article shows another example based on seasons of the year.