haskell - Matching multiple data type constructors at once -


We say that we have such a declaration:

  data da = A.A. B.A. C.A. D one | E.A. F A  

and want to define a function that divides the data constructor into 2 sets. It would be nice to type something like this:

  g x | X``` [A, B, C] = 1 | Instead of matching separately to each manufacturer, X`` [D, E, F] = 2  

Is there any way to achieve this? I looked at a similarity but there was no way to do it.

If you need to match frequently, for the same set of constructors, an assist function is the simplest solution It is possible. For example:

  getAbc :: DA - & gt; It may be that an AAABC (AV) = bus VAABBC (BV) = bus VAABC (CV) = just wins ABC == nothing  

this kind of With an auxiliary work, the definition of g can be simplified in such a way:

  gx = g_ (getAbc x) where g_ (bus v) = 1 G_no = 2  

Or, using the function:

  g = probably 2 (\ v -> 1). GetABC  

Comments