Type the Q3 product-of-list predicate (Prolog)
Type the Q3 product-of-list predicate (Prolog)
Answer
product([], 1). product([H|T], P) :- product(T, PT), P is H * PT.
Base value is 1 (multiplicative identity). The recursive clause splits [H|T], solves the tail, then multiplies the head back in — the standard list-fold shape.