[Haskell-cafe] f(g(x), h(y)) - Correct syntax

Luke Palmer lrpalmer at gmail.com
Mon Feb 11 09:34:03 EST 2008


On Feb 11, 2008 2:27 PM, news at lyra.net <news at lyra.net> wrote:
> Hallo!
>
> I have this code:
> ----------------------------------------
> q1 :: EName -> [ApprenticeInfo]
> q1 c = [apprenticeInfo n | n <- allApprentices, member ((sq4
> c) (firstOf5(n))) == True]
>
> sq4 :: ESurname -> [IDB]
> sq4 c = (sq3 (sq1 (c)))
>
> firstOf5 :: (a,b,c,d,e) -> a
> firstOf5 (n,_,_,_,_) = n
>
> member :: [IDB] -> IDB -> Bool
> member [] y = False
> member(x:xs) y = (x==y) || member xs y
> ----------------------------------------
> sq4 works correctly and returns [IDB]
> Unfortunately member ((sq4 c) (firstOf5(n))) gives this
> error:
>
> Type error in application
> *** Expression     : sq4 c (firstOf5 n)
> *** Term           : sq4
> *** Type           : ESurname -> [IDB]
> *** Does not match : a -> b -> c
>
> As far as I see it I'm not writing the correct syntax for a
> function of 2 functions.

I assume you meant arguments.  And you're right.  In Haskell the whole
argument list is not enclosed in parentheses like it is in many other
languages.  "f (x y)"  means what C would call "f(x(y))", whereas "f x
y" means what C would call "f(x,y)" (modulo currying stuff).

Drop the set of parentheses starting just after member and you should be fine.

Luke


More information about the Haskell-Cafe mailing list