varying number of arguments restriction
Wed, 31 Oct 2001 21:28:54 +1100
On 30-Oct-2001, Hal Daume <hdaume@ISI.EDU> wrote:
> I'm curious why the following code is invalid (from a language design
> point of view):
> > foo :: [(Int, String)] -> String
> > foo  = ""
> > foo = snd . head
> ghc complains:
> Varying number of arguments for function `foo'
> I don't understand why this should be invalid?
While it would be possible to define a semantics for such code,
I suspect that this sort of thing commonly arises as a result
of accidental errors in Haskell programs.
Allowing such programs would therefore (a) let some unintended errors
slip past the compiler and (b) result in much more obscure error messages
(from the type checker) for some other unintended errors.
Since it's easy for the user to write function definitions so that all
clauses have the same number of arguments, and since requiring this helps
the compiler give better error messages and/or catch errors earlier,
I think it makes good sense to do so.
Fergus Henderson <email@example.com> | "... it seems to me that 15 years of
The University of Melbourne | email is plenty for one lifetime."
WWW: <http://www.cs.mu.oz.au/~fjh> | -- Prof. Donald E. Knuth