How to solve this math Function in Haskell?

  • A+
Category:Languages

How can I solve this math Funcion with Haskell? Can anyone help me?

Rekursive math Function

myFunc n m = myFuncRec n m if m <= n then 1                        else myFuncRec n(m - 1):[] 

Do I need two recursion? because for this problem in java needs two or three loops.

 


I would normally give a hint instead of a full solution, but since this question is mostly about syntax, and the translation is very close, almost literal, I'll just give it to you in full.

How to solve this math Function in Haskell?

p n m      | m <= n    = 1     | otherwise = sum [ p n (m - i) | i <- [1..n] ] 

The bars distinguishing the different cases by conditions are called guards, and the bracket structure in the last line is known as a list comprehension.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: