I’m working on an exercise from Haskell First Principals and not understanding the following.
I have the type
kessel :: (Ord a, Num b) => a -> b -> a; kessel = undefined
> :t kessel 1 2
kessel 1 2 :: (Ord a, Num a) => a
b is removed from the type signature and it says, as I understand it,
a must be both
Num, but the original signature seemed to say that both
b can be different types. Did it just remove
b because I passed it two params of the same type or is there something else to it?
But I can give
kessel a string and an int
:t kessel "ca" 1
kessel "ca" 1 :: [Char].
String (“ca”) has the type class Ord so it takes that, and the original signature says it returns
a, so the type of the first parameter. However, I don’t know why
kessel "ca" 1 :: [Char] has no type constraints.
I’m guessing I am unaware of some guiding generalization or rule on how types work. Was hoping someone could shed some light for me.