I am trying to figure out the way Haskell determines type of a function. I wrote a sample code:
compareAndIncrease a b = if a > b then a+1:b:[] else a:b:[] which constructs a list basing on the a > b comparison. Then i checked its type with :t command:
compareAndIncrease :: (Ord a, Num a) => a -> a -> [a] OK, so I need a typeclass Ord for comparison, Num for numerical computations (like a+1). Then I take parameters a and b and get a list in return (a->a->[a]). Everything seems fine. But then I found somewhere a function to replicate the number:
replicate' a b | a ==0 = [] | a>0 = b:replicate(a-1) b Note that normal, library replicate function is used inside, not the replicate' one. It should be similar to compareAndIncrease, because it uses comparison, numerical operations and returns a list, so I thought it would work like this:
replicate' :: (Ord a, Num a) => a -> a -> [a] However, when I checked with :t, I got this result:
replicate' :: Int -> t -> [t] I continued fiddling with this function and changed it's name to repval, so now it is:
Could anyone explain to me what is happening?