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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -