Define the function squarefact::Int -> Int that computes for any positive integer n the squared factorial (n!)^2 == (1 * ...* n)^2

pro*_*exe 6 haskell

I am trying to define a function that computes for any positive integer the square of its factorial

(I am a beginner in Haskell any tips or help is appreciated)

I have tried a couple different ways one i believe to work and one definition i don't understand why it doesn't work

Function i believe works:

 squarefact:: Int -> Int
 squarefact 0 = 1
 squarefact n = n * n * squarefact(n-1)
Run Code Online (Sandbox Code Playgroud)

Function I don't understand why it doesn't work:

squarefact:: Int -> Int
squarefact 0 = 1
squarefact n = (n * squarefact(n-1) ) * (n * squarefact(n-1) )
Run Code Online (Sandbox Code Playgroud)

An explanation and walk through of the dunctions defined would help me understand them better thanks.

chi*_*chi 4

等式

squarefact n = (n * squarefact(n-1) ) * (n * squarefact(n-1) )
Run Code Online (Sandbox Code Playgroud)

可以用数学符号重写为

(n!)^2 = n * ((n-1)!)^2 * n * ((n-1)!)^2
Run Code Online (Sandbox Code Playgroud)

但这个身份是不正确的。右侧包含1,2,....,n-1 四次因子,而不是左侧的仅两次。

通过对比,

squarefact n = n * n * squarefact(n-1)
Run Code Online (Sandbox Code Playgroud)

是正确的,因为双方的所有因素都恰好出现两次。