Classic Haskell は、一般化されたパターン マッチングを提供しません。標準のパターン マッチングとガードの両方を提供します。したがって、次のようなものを書くことができます
foo :: [Int] -> ...
foo [1,2,3] = <some expression>
foo [1,2,x] = <some expression that can use x>
foo (x:xs) = <some expression where x is the first element, and xs is the rest>
foo (x:x':xs) = <some expression where x is the first element, x' the second, and xs is the rest>
bar :: (Int,String) -> ...
bar (1,"hello") =
bar (someInt,someString) =
bar (someInt,_) =
bar _ =
交互に:
bar :: (Int, String) -> ...
bar x = case x of
(1,"hello") -> ...
_ -> ...
交互に:
bar :: (Int, String) -> ...
bar (someInt,someString)
| someInt == 1 && someString == "hello" = ...
| someInt == 2 && someString == "hello" = ...
| otherwise = ...
GHC は、ガードとパターン マッチングをよりシームレスに統合するための拡張機能も提供します。「View Patterns」と「Pattern Guards」のセクションを参照してください: http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html