I have the following Haskell definitions in a source file
nNotes=7
pitchLimit k = k < 0 || k > 20
pitcherror = error "Invalid Pitch"
getOctave k
| pitchLimit k = pitcherror
| otherwise = k `div` nNotes
I do not declare the type of getOctave
. Now here is my issue regarding types. Later on in the same source file, I used getOctave
with an Int
. I load the source file into GHCI and Haskell infers that the type of getOctave
is Int->Int
. Now I comment out the code that uses getOctave
as an Int
. I reload the source file and now Haskell infers getOctave
to be of type Integer->Integer
. Seems to me now that the default of div
is Integer->Integer
. Now I uncomment that code and specify the type of getOctave
to be (Integral a) => a ->a
. And Haskell reports an error. What's wrong with using (Integral a) => a -> a
.