Created
May 11, 2017 02:29
-
-
Save yoshihiro503/2bf912b74b5f5a2ac49ea6022d92b677 to your computer and use it in GitHub Desktop.
すごいE本の30.6章の「選択的な節を持つ型」 (p.538) を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
// すごいE本の30.6章の「選択的な節を持つ型」 (p.538) をScalaでも | |
object AlternativeClausesType { | |
def main() = { | |
val List(_, _) = convert(('a, 'b)) | |
val (_, _) = convert(List('a, 'b)) | |
val List(_, _) = convert(List('a, 'b)) // <- 型エラーにできる | |
val (_, _) = convert(('a, 'b)) // <- 型エラーにできる | |
} | |
def convert(xy: (Symbol, Symbol)): List[Symbol] = xy match { | |
case (x, y) => List(x, y) | |
} | |
def convert(xy: List[Symbol]): (Symbol, Symbol) = xy match { | |
case List(x, y) => (x, y) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment