0
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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.