Con product
1 |
fattoriale n = product [1..n] |
Con la ricorsione
1 2 |
fattoriale 0 = 1 fattoriale n = n*fattoriale (n-1) |
Con if … then … else …
1 2 3 4 5 6 7 8 9 10 11 12 13 |
fattoriale n = if n == 0 then 1 else n*fattoriale (n-1) fattoriale n = if n == 0 then 1 else n*fattoriale (n-1) fattoriale n = if n == 0 then 1 else n*fattoriale (n-1) fattoriale n = if n == 0 then 1 else n*fattoriale (n-1) |
Con la griglia
1 2 3 |
fattoriale n | n == 0 = 1 | otherwise = n*fattoriale (n-1) |