[erlang-questions] Lack of warning for overlapping clauses with

Richard O'Keefe <>
Tue Jul 20 23:53:37 CEST 2010

On Jul 20, 2010, at 8:12 PM, Torben Hoffmann wrote:

> I have not tried this out in Haskel (or any other FP language) since  
> I am
> trying to keep my computer clean, ie, only Erlang and what that  
> entails ;-)
> But I suspect that Haskel is capable of detecting this.

There are several Haskell compilers.

Let's construct two little Haskell functions.

    transparent 1 = False
    transparent 2 = False
    transparent 1 = True

    opaque n | n == 1 || n == 2 = False
    opaque 1                    = True

    main = print (transparent 1, transparent 2, opaque 1, opaque 2)

and see what Haskell makes of them.
	f% ghci		# This is version 6.6.1
	Prelude> :load test.hs
	[1 of 1] Compiling Main             ( test.hs, interpreted )

	    Warning: Pattern match(es) are overlapped
	             In the definition of `transparent': transparent 1 = ...
	Ok, modules loaded: Main.

	f% nhc98 test.hs
	f% a.out

So nhc98 was completely silent, and ghc 6.6.1 did notice the
explicit pattern duplication but did *NOT* notice the duplication
of a pattern in a guard, any more than Erlang did.

I can't construct an SML analogue, because SML has no guards.

This is expecting far more cleverness from the Erlang system than
I would expect people to expect.

More information about the erlang-questions mailing list