I thought it would be neat to allow arbitrary matching in Haskell, so that you could perform simple range checks, for example:
x <= y < z
And more complicated things like
x /= y < z == a
If the above two are semantically equivalent
x <= y && y < z x /= y && y < z && z == a
Just see if I can make the syntax work.
So, I got most of the way using a couple of type classes:
{-
Which compiles fine, but not exactly like chaining due to a problem of intermediate types.
checkRange1 and checkRange2 work fine, because both of them set a limit on the intermediate type (either as a result of the first comparison or as an argument of the second).
When I try to let the compiler infer an intermediate type, however, it barks at me.
ChainedOrd.hs:64:30: Ambiguous type variable `a0' in the constraints: (ChainedOrd a0 a) arising from a use of `<=' at ChainedOrd.hs:64:30-31 (Booly a a0) arising from a use of `<=' at ChainedOrd.hs:64:24-25 Probable fix: add a type signature that fixes these type variable(s) In the expression: (x <= y) <= z In an equation for `checkRange3': checkRange3 xyz = (x <= y) <= z
Is there any way to convince the compiler that he should use Maybe a as an intermediate type a0 satisifying Booly a a0, ChainedOrd a0 a , since this is the only instance he knows about?
Otherwise, is there any other way I can make an arbitrary comparison chain?
rampion
source share