Answer the question
In order to leave comments, you need to log in
How does where px =... work in Haskell?
I have a larg function, it finds the first number from the list that is a multiple of 3829, but I don’t quite understand " where p x = mod x 3829 == 0
". That is, x is a number, but how is x squeezed out of the list, if we didn’t even explicitly indicate the "head" of the list or this is what head does???
larg :: [Integer]->Integer
larg x= head (filter p x)
where p x = mod x 3829==0
Answer the question
In order to leave comments, you need to log in
"Squeezing" out of the list is handled by `filter`, applying the `p` function to each element in the input.
If it returns True (that is, when the remainder of the division is zero), then the element is included in the output list.
`head` here takes the first element from the already filtered list. Or it crashes with a message like "head: empty list" and it would be better to replace it with `case`.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question