Haskell function

filterGr :: QuestStat -> QuestStat filterGr ((q,s,d):xs) = fgHlp s ((q,s,d):xs) where fgHlp maxS = filter (\(q,s,d) -> s == maxS) 

I have a question: is it necessary to write fgHlp s ((q,s,d):xs) or you can fgHlp s . What does an entry with ((q,s,d):xs) give?

And another question arose: the filter function gets a predicate and a list, and in the above function only the predicate?! Or am I wrong?

PS If QuestStat is a list: [( String, Integer, Integer)] .

    1 answer 1

    In Haskell it is possible to write functions in the so-called pointfree style:

     sum :: (Num a) => [a] -> a sum = foldl (+) 0 

    At the same time, we do not specify the function argument (the point of its application, hence the term “pointless”), but must do it both on the right and on the left of the = sign in the function definition. In this example, the standard library omitted a summary list, the "full" definition would look like this

     sum :: (Num a) => [a] -> a sum xs = foldl (+) 0 xs 

    In your example, the auxiliary function fgHlp defined as fgHlp , you could define it and

     fgHlp maxS ys = filter (\(q,s,d) -> s == maxS) ys 

    Here, the filter accepts the "correct" number of arguments — the predicate and the list; however, in Haskell, applying a function to a smaller number of arguments than is supposed to be valid as well.

    As for the first question, it would be technically filterGr to filterGr expression fgHlp s in the definition of filterGr , if we did not need to extract s from the head of the list in the left part of this definition. That is, writing without a point:

     filterGr = fgHlp s 

    we would have a problem: what is s here?