varying number of arguments restriction

Hal Daume hdaume@ISI.EDU
Tue, 30 Oct 2001 19:01:22 GMT

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?  Basically, as I read
it, I say, well, for a parameter s, calling foo s:

does s match [] ?  if so, return "" otherwise, try the next definition
of foo (which must match in this case).

obviously i can rewrite:

foo [] = ""
foo s  = (snd . head) s

but this is uglier.

 - hal

Hal Daume III

 "Computer science is no more about computers    |
  than astronomy is about telescopes." -Dijkstra |