[Haskell-cafe] argument counts...

Zemyla zemyla at gmail.com
Mon Nov 20 18:00:17 UTC 2017


You need to turn the second case into a lambda:

revFn [] = \xs -> xs

Or more succinctly,

revFn [] = id

On Mon, Nov 20, 2017 at 11:13 AM, Gregory Guthrie <guthrie at mum.edu> wrote:
> I have a simple function:
>
>        revFn (x:xs) = (revFn xs) . (x:)
>
>
>
> Of course GHCi correctly infers the type as:   revFn :: [a] -> [a] -> c
>
>
>
> Adding the base case:
>
>     revFn [] xs = xs
>
>
>
> Now gives an error;
>
>   “Equations for ‘revF’ have different numbers of arguments”
>
>
>
> Of course this can be “fixed” by either adding the cancelled argument to the
> first clause, or converting the base case to only have one explicit
> argument, and a RHS of a lambda or identity function.
>
>
>
> But since the interpreter already correctly inferred that the first clause
> has two arguments (with only one explicit), why does it then ignore this and
> give an error when the second clause shows two explicit arguments? The types
> are all correct in either case – why require explicit arguments?
>
>
>
> Or, perhaps I am missing something simple?
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.


More information about the Haskell-Cafe mailing list