My question is about how to work with Haskell type signatures analytically. To make it concrete, I'm looking at the "fix" function:
fix :: (a -> a) -> a
and a little made-up function that I wrote to do Peano-ish addition:
add = \rec a b -> if a == 0 then b else rec (a-1) (b+1)
When I examine the types, I get my expected type for fix add
:
fix add :: Integer -> Integer -> Integer
And it seems to work like I'd expect:
> (fix add) 1 1
2
How can I work with the type signatures for fix
and for add
to show that fix add
has the above signature? What are the "algebraic", if that's even the right word, rules for working with type signatures? How could I "show my work"?