Haskell has PatternSynonyms
which enables to simplify a complex pattern matching. An example is shown in that extension description page. That is, for Type
below,
data Type = App String [Type]
with these pattern synonyms
pattern Arrow t1 t2 = App "->" [t1, t2]
pattern Int = App "Int" []
pattern Maybe t = App "Maybe" [t]
we can simplify the pattern matches as follows
collectArgs :: Type -> [Type]
collectArgs (Arrow t1 t2) = t1 : collectArgs t2
collectArgs _ = []
isInt :: Type -> Bool
isInt Int = True
isInt _ = False
isIntEndo :: Type -> Bool
isIntEndo (Arrow Int Int) = True
isIntEndo _ = False
Is it possible to do this kind of pattern match simplification in OCaml?
No, patterns synonyms are not available in OCaml (at the time of writing this answer).