[Haskell-cafe] Patterns overlapped?
Brandon S. Allbery KF8NH
allbery at ece.cmu.edu
Sun Jan 13 14:02:31 EST 2008
On Jan 13, 2008, at 13:59 , Fernando Rodriguez wrote:
> When I compile this code, ghc complains about some overlapped
> patterns in function depth. What on Earth is ghc talking about? O:-)
> emptyBT = EmptyTree
> depth emptyBT = 0
> depth (NodeBT _ left right) = max (1 + depth left) (1 + depth right)
If you use a variable in a pattern match, it creates a new binding
which irrefutably matches the corresponding argument. In other
words, you get a new local variable "emptyBT", ignoring your global.
You must use the actual constructor instead.
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university KF8NH
More information about the Haskell-Cafe