If you create a file with only the ask function (without the main problem) and upload it to ghci, you can see what the request type is
ask :: (Read a) => String -> IO a
means that it is polymorphic in the return type.
The problem is that when you do
a <- ask "What is your name"
the compiler needs to know what type a , so it can use the correct deserialization function for the line you are reading from inpout. But a not used anywhere and there are no type signatures, since type inference cannot infer type a . The compiler refuses and gives you a message like "ambiguos types".
There are two main ways to fix this:
Make the ask function always return the same type. You can do this by adding a specific signature
ask :: String -> IO String
Or by changing readLn to something like getLine .
Add type signatures in which you use polymorphic functions. You can either add a type signature to the request request itself:
a <- ask "What is your name" :: IO String
or you can add it directly to the variable
(a :: String) <- ask "What is your name"
however, this second parameter is not enabled by default in Haskell syntax. you need to enable the ScopedTypeVariables extension by adding the following comment as the first line in your file
{-
source share