haskell - compare contents of Either type -
is there way use pattern wildcards type constructors make ugly code shorter:
eithercompare (left a) (left b) = compare b eithercompare (left a) (right b) = compare b eithercompare (right a) (left b) = compare b eithercompare (right a) (right b) = compare b
something (which won't compile)
eithercompare :: ord => either a -> either a -> ordering eithercompare (_ a) (_ b) = compare b
or other method?
you can't pattern matching, can still simplify code using helper function:
eithercompare x y = compare (fromeither x) (fromeither y) fromeither (left a) = fromeither (right a) =
Comments
Post a Comment