I have recently started learning Haskell in lectures, but when I try to find further explanations to understand how it works online, I have found the code looks completely different. Note: I have only learnt C before and am used to most code following similar formats, and looking similar.
For example, a function for the factorial of a number in my lectures looks like this:
{-**********-}
fac :: Int -> Int
fac n
| n==0 = 1
| n>0 = n * fac (n-1)
{-**********-}
but when I look online it looks completely different, and far more simple. For example:
factorial 1 = 1
factorial k = k * factorial (k-1)
Can anybody explain why the code I am being taught is more effective, in particular where it says
fac:: Int->Int
and why that matters?