[Haskell-cafe] Re: Writing guards shorthand

Jón Fairbairn jon.fairbairn at cl.cam.ac.uk
Thu Apr 19 11:10:41 EDT 2007

Joel Reymont <joelr1 at gmail.com> writes:

> Support I want to infer the type given an Op that looks like
> this  (incomplete):
> data Op
>      = Minus
>      | Plus
>      | Mul
>      | LT
>      | GT
> Is there a shorthand way of bunching Minus, Plus and Mul in
> a  function guard since they all result in TyNum whereas the
> rest in  TyBool?
> I really don't want several function clauses and neither do
> I want  separate guards for every constructor.

Is there some reason why you don't want

   data Op = Aop Aop | Bop Bop
   data Aop = Minus | Plus | Mul
   data Bop = LT | GT

or similar?  I would agree that it's a shame one cannot just write

   data Op = Aop (Minus | Plus | Mul) | Bop (LT | GT)

or even, given a somewhat different type system,

   data Op = Aop | Bop
             where Aop = Minus | Plus | Mul
                   Bop = LT | GT

but it would seem reasonable to reflect the different types
of the Ops in different types in their representations.

Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk

More information about the Haskell-Cafe mailing list