简体   繁体   中英

PureScript. Argument list lengths differ in declaration

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM