Pattern matching identical values

This is called a nonlinear pattern. There have been several threads on the haskell-cafe mailing list about this, not long ago. Here are two:

http://www.mail-archive.com/haskell-cafe@haskell.org/msg59617.html

http://www.mail-archive.com/haskell-cafe@haskell.org/msg62491.html

Bottom line: it’s not impossible to implement, but was decided against for sake of simplicity.

By the way, you do not need if or case to work around this; the (slightly) cleaner way is to use a guard:

a `plus` b
  | a == b = 2*a
  | otherwise = a+b

Leave a Comment