import Prelude
data Line = Front | Middle | Back
derive instance eqLine :: Eq Line
instance ordLine :: Ord Line where
compare a b | a == b = EQ
compare Front _ = LT
compare Back _ = GT
compare = flip compare
Why does this give me the error 'Argument list lengths differ in declaration compare'. But if I change the last line to
compare a b = flip compare a b
then it compiles.
I thought flip compare
returns a function of 2 args hence matches signature of compare
, but apparently it doesn't.
Repl:
> :type flip compare
forall (t4 :: Type). Ord t4 => t4 -> t4 -> Ordering
It's just a syntax requirement. If you provide several equations for a function, they all have to have the same number of arguments. Syntactically, not logically.
This is required as a confusion-reducing measure. Just so that whoever is reading your program months later can see what's going on clearer.