multiple declarations error in Haskell - should it be relaxed?

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? Regards, Andrew -------------------------------------------------------------------- Andrew Butterfield Tel: +353-1-896-2517 Fax: +353-1-677-2204 Lero@TCD, Head of Foundations & Methods Research Group School of Computer Science and Statistics, Room G.39, O'Reilly Institute, Trinity College, University of Dublin http://www.scss.tcd.ie/Andrew.Butterfield/ --------------------------------------------------------------------

On Fri, Nov 28, 2014 at 11:44:16AM +0000, Andrew Butterfield wrote:
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.
Here's a somewhat silly answer, but it may be of help. data T = F | G fun :: T -> Int -> String fun F 0 = "zero" fun G 0 = "NULL" fun F n = "non-zero" fun G n = "PRESENT"

The problem seems to boil down to the fact that (at least in every IDE I am aware of) the order in which the compiler reads your code is the same as the order in which the code is displayed to you as you write it. A general solution would be to extend the IDE to allow hyperlinks, ignored by the compiler, from one part of the code to another. It is something one could write in Emacs Lisp, to work across multiple languages. On Fri, Nov 28, 2014 at 3:53 AM, Tom Ellis < tom-lists-haskell-cafe-2013@jaguarpaw.co.uk> wrote:
On Fri, Nov 28, 2014 at 11:44:16AM +0000, Andrew Butterfield wrote:
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.
Here's a somewhat silly answer, but it may be of help.
data T = F | G
fun :: T -> Int -> String fun F 0 = "zero" fun G 0 = "NULL" fun F n = "non-zero" fun G n = "PRESENT" _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

This seems reasonable to me. If you want this, post a feature request at https://ghc.haskell.org/trac/ghc/newticket
Richard
On Nov 28, 2014, at 6:44 AM, Andrew Butterfield
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?
Regards, Andrew -------------------------------------------------------------------- Andrew Butterfield Tel: +353-1-896-2517 Fax: +353-1-677-2204 Lero@TCD, Head of Foundations & Methods Research Group School of Computer Science and Statistics, Room G.39, O'Reilly Institute, Trinity College, University of Dublin http://www.scss.tcd.ie/Andrew.Butterfield/ --------------------------------------------------------------------
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (4)
-
Andrew Butterfield
-
Jeffrey Brown
-
Richard Eisenberg
-
Tom Ellis