3 ms·
I guess I'm in a minority here, but I wish more non-functional languages would feature pattern matching, of the sort seen in Haskell and OCaml. [0] This langua
by MaxBarraclough 8y ago
I guess I'm in a minority here, but I wish more non-functional languages would feature pattern matching, of the sort seen in Haskell and OCaml. [0]
This language-design question is essentially a solved problem, but few new languages (outside the pure-ish functional ones) make the effort.
Trivial example in OCaml:
let imply v = match v with
(true,x) -> x
| (false,x) -> true;;
[0] https://caml.inria.fr/pub/docs/oreilly-book/html/book-ora016.html https://caml.inria.fr/pub/docs/oreilly-book/html/book-ora016...
- rbavocadotree 8y agoIt's becoming more popular. Kotlin, Swift and now C# 8.0 have pattern matching (well, close enough at least). I sure hope other languages take note, because you are right about it essentially being a solved problem.
- commandlinefan 8y agoScala, too.
- sk5t 8y agoYep! Scala's pattern matching is so far ahead of Kotlin's, vis a vis destructuring, that it strains the conscience to say Kotlin has pattern matching at all. FWIW I find both to be enjoyable languages in which to work.