Created
February 6, 2016 17:55
-
-
Save leifwickland/5a1ab6efa6f822019a3a to your computer and use it in GitHub Desktop.
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 Pokemon { | |
def name: String | |
def elemental: String | |
} | |
// I want a macro like this. | |
// (The type names may need to need to be in strings.) | |
// (I'm not entirely sure that quasiquote macros can do this magic.) | |
enum[Pokemon]( | |
Bulbasaur -> ("フシギダネ", "Grass"), | |
Ivysaur -> ("フシギソウ", "Grass"), | |
Venusaur -> ("フシギバナ", "Grass"), | |
Charmeleon -> ("リザード", "Fire"), | |
Charizard -> ("リザードン", "Fire"), | |
Squirtle -> ("ゼニガメ", "Water"), | |
Charmander -> ("ヒトカゲ", "Fire") | |
) | |
// Generates the equivalent of: | |
abstract class PokemonBase(val name: String, val elemental: String) extends Pokemon | |
object Bulbasaur extends PokemonBase("フシギダネ", "Grass") | |
object Ivysaur extends PokemonBase("フシギソウ", "Grass") | |
object Venusaur extends PokemonBase("フシギバナ", "Grass") | |
object Charmeleon extends PokemonBase("リザード", "Fire") | |
object Charizard extends PokemonBase("リザードン", "Fire") | |
object Squirtle extends PokemonBase("ゼニガメ", "Water") | |
object Charmander extends PokemonBase("ヒトカゲ", "Fire") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like the idea but i'd make the macro name "ADT" instead of "enum" so as not to confuse / mislead users.