Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 518

Can I define pattern synonyms in OCaml?

$
0
0

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?


Viewing all articles
Browse latest Browse all 518

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>