Created
September 22, 2013 09:55
-
-
Save arturaz/6658516 to your computer and use it in GitHub Desktop.
Defining same ADT in C# and Scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class Kind { | |
public class Global : Kind {} | |
public class World : Kind { | |
public readonly int world; | |
public World(int world) { | |
this.world = world; | |
} | |
} | |
public class Level : Kind { | |
public readonly int world; | |
public readonly int level; | |
public readonly bool bonus; | |
public Level(int world, int level, bool bonus) { | |
this.world = world; | |
this.level = level; | |
this.bonus = bonus; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait Kind | |
object Kind { | |
case object Global extends Kind | |
case class World(world: Int) extends Kind | |
case class Level(world: Int, level: Int, bonus: Boolean) extends Kind | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't know Scala, so I might not understand well enough what exactly are you trying to achieve. However%