rho x = map (((flip mod) x).(\a -> a^2-1)) (rho x)
This function will generate an infinite list. And I tested in GHCi, the function type is
*Main> :t rho
rho :: Integral b => b -> [b]
If I define a function like this
fun x = ((flip mod) x).(\a -> a^2-1)
The type is
*Main> :t fun
fun :: Integral c => c -> c -> c
My question is, how can Haskell deduce the function type to b -> [b]? We don’t have any [] type data in this function. Thanks!
maphas the following type:So, we can deduce the types of the arguments to
map:But the result of
mapis also the result ofrho x, so:Which implies that
aandbare the same type, so:If we examine the mapping function, and make
xfree, we find the type:The
Integral b => bgives us the type ofx, and the(b -> b)unifies with the type of the function composition, so we know that thisbis the same as the previous one.