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 t2collectArgs _ = []isInt :: Type -> BoolisInt Int = TrueisInt _ = FalseisIntEndo :: Type -> BoolisIntEndo (Arrow Int Int) = TrueisIntEndo _ = False
Is it possible to do this kind of pattern match simplification in OCaml?