Joel Reymont wrote:
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?
data NumOrBool = JNum | JBool deriving (Eq)
numorbool Minus = JNum
numorbool Plus = JNum
numorbool Mul = JNum
numorbool LT = JBool
numorbool GT = JBool
f o | numorbool o == JNum = TyNum (...)
| numorbool o == JBool = TyBool (...)
...so you have to define one function rather verbosely (numorbool) but
once you've done it once you can use it in a guard to define others more
quickly.
You could use pattern guards instead of == and forget about deriving Eq
if you prefer.
Jules
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe