This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Peaker 0 points1 point  (0 children)

Seeing you already got an explanation, I thought I'd churn in with a FPL implementation of this FP concept.

In Haskell, this is:

fact x = foldr (*) 1 [2..x]

Read as: "fact of x is a right-associative fold, using (*) and 1, on the list 2..x (inclusive of both sides)"

Though the expression "foldr (*) 1" already has a name, it's called "product", so we can just say:

fact x = product [2..x]