Skip to content

Instantly share code, notes, and snippets.

@yoshihiro503
Created May 11, 2017 02:29
Show Gist options
  • Save yoshihiro503/2bf912b74b5f5a2ac49ea6022d92b677 to your computer and use it in GitHub Desktop.
Save yoshihiro503/2bf912b74b5f5a2ac49ea6022d92b677 to your computer and use it in GitHub Desktop.
すごいE本の30.6章の「選択的な節を持つ型」 (p.538) をScalaでも
// すごい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