I'm new to Haskell and reading Haskell from first principles.
BTW this question is general not related to this book, I have taken following question as example
In Chapter 10, Section 10.5, Q 5, part f
Question:
The following are simple folds very similar to what you’ve already seen, but each has at least one error. Please fix them and test in your REPL
f) foldr const 'a' [1..5]
and its giving this following Error
No instance for (Num Char) arising from the literal `1'

simply means that 1 can not be used as Char here
but I read in this chapter that folds are Like Text Rewriter, replace cons(:) with the function and replace empty list with Accumulator so the result is (I have shorten the list)
foldr const 'a' [1..2]
to
(1 `const` (2 `const` 'a'))
and its working no complier error
So what could went wrong ? why first one is not working and its rewritten is working ?
but I'm seeing in rewritten form const has two forms
Int -> Int -> Int
and
Int -> Char -> Int
maybe this is bcs of it so I Fix the type of const like this
cont :: Int -> Int -> Int
cont = const
and now When I stated using it
(1 `cont` (2 `cont` 'a'))
Couldn't match expected type `Int' with actual type `Char'
Seems like When We are using Polymorphic functions Haskell fix it type, and we can not use it in other form
maybe it should be list folds description should be like this
folds are Like Text Rewriter, replace cons(:) with the function, fix the type of function and replace empty list with Accumulator
Please share your thought about it.
not only Haskell but other typed languages has same behavior ?
or maybe I'm totally wrong ?
I think, it's simpler, and the function const just doesn't fit the signature expected by the foldr:
So haskell tries to generalize both of
aandb(to find out, both of them have sufficient set of typeclasses), and, finally, figures out that1is a number, but 'c' doesn't implement this typeclass.