[Haskell-cafe] multiple declarations error in Haskell - should it be relaxed?

Andrew Butterfield Andrew.Butterfield at scss.tcd.ie
Fri Nov 28 11:44:16 UTC 2014

Condsider the following Haskell program (fragment):

f 0 = “zero”
g 0 = “NULL”
f n = “non-zero”
g n = “PRESENT”

This will result in two “Multiple Declaration” errors.
There is a  good motivation for this - disallowing such an interleaving
of declarations makes it easy for the compiler to capture a common
typo, namely errors of the following  form - here an attempt to define
a single function called myFun.

myFun 0 = “zero”
myfun 1 = “one”
myFun n = “too big!”

However I have use-cases where it would be nice to interleave as per
the first example above - with markedly different function names.
It invokes a large case analysis, where I have other auxiliary functions
associated with each case, but which I’d like to
(1) have at the top-level for testability
(2) keep textually local to the case with which they are associated.

I don’t think there is a language extension to disable the multiple
declaration check - but would such a feature we possible. I’d see it
as one which still performs the check, but issues a warning rather
than an error - particularly if it notices that the interleaved names
are very similar.

Is this a reasonable suggestion, or are there other reasons for not doing
this that I’ve missed?

Maybe there is a better way to satisfy (1) and (2) above?

Andrew Butterfield     Tel: +353-1-896-2517     Fax: +353-1-677-2204
Lero at TCD, Head of Foundations & Methods Research Group
School of Computer Science and Statistics,
Room G.39, O'Reilly Institute, Trinity College, University of Dublin

More information about the Haskell-Cafe mailing list