-
-
Save kubukoz/de038ab7eb94c6179a5726ce1b911cf2 to your computer and use it in GitHub Desktop.
gadthelp
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 Scenario[A, B] | |
| object Scenario { | |
| // later pattern matching let's me do GADT stuff in pattern matches fine | |
| case object A extends Scenario[AA, AA1] | |
| case object B extends Scenario[BB, BB1] | |
| // but how to get into this domain from the outside is the problem...(this doesn't compile obviously) | |
| def from[A, B](s: String): Scenario[A, B] = s match { | |
| case "a" => A | |
| case "b" => B | |
| } | |
| // I can use an existential type here and return Scenario[_,_] later | |
| // but then I lose the fact it's AA, AA1 or BB, BB1 later | |
| // and a bunch of implicit lookups fail because it can't find implicits for | |
| // _$1, and _$2 | |
| } | |
| // later usage using the GADT in a pattern match | |
| def from[A, B](scenario: Scenario[A, B]): Box[A, B] = scenario match { | |
| case A => constantA // returns some Box[AA, AA1] | |
| case B => constantB // returns some Box[BB, BB1] | |
| } | |
| // later later usage | |
| // relies on the answer of Box[A, B] to lookup implicits for A, B. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment