p.s: I wasn't sure how to name my question, fell free to let me know how I should have named it.
If not specifying the concrete type, I get this error, which is very clear and easy to solve:
Ambiguous type variable
a0
arising from a use offct
prevents the constraint(Read a0)
from being solved. Probable fix: use a type annotation to specify whata0
should be.
I just need more explanation on why it worked? How Read
will know what is the type to return:
fct :: (Show a, Read b) => a -> b
fct = read . show
main = do
-- DOES NOT WORK: -- print (fct 4)
-- WORKS: -- print (fct 4 :: Int)
fct
doing here? – Willem Van OnsemInt
, so that means thatread
must return anInt
. – Carcigenicate