What is the relationship between pattern matching and type system?

In scala and some other languages ​​(Haskell, SML) we can use pattern matching, for example:

val user: Option[User] = findUser(123)
user match {
    case Some(u) => ...
    case _ => ...
}

I have some questions about the relationship between pattern matching and type system:

  • Is a "static type system" required to support pattern matching?
  • Is there any “dynamic type system” language that supports pattern matching?

Update:

Thanks @Eran answer.

I know that many languages ​​do not support pattern matching, for example c / C ++ / java / python / ruby ​​/ javascript / lisp (can I add "bash" to this list?)

If we want to add “pattern matching” to them, which languages ​​can add it in theory? And which languages ​​can't do it anyway?

+4
1

, . ( ) .

- "". - , , . , , .

, :

  • C/++/Java - , .
  • Haskell/ Scala , .
  • - , .
  • JavaScript - , .

, , . , , .

+6

Source: https://habr.com/ru/post/1545546/


All Articles