[Haskell-beginners] Using IO values for computations

Magnus Therning magnus at therning.org
Mon May 25 12:29:12 UTC 2015


On 25 May 2015 at 08:44, Dananji Liyanage <dan9131 at gmail.com> wrote:
> Hi All,
>
> I'm writing a code, where the input is read from a text file using:
> readValues = readFile "Input.txt"
>
> Since the type of this is 'IO String', I can't use this in the consequent
> functions.
>
> For an example: I want to split this as follows within another function
>
> extractInput url method template
>   | isURI url == True = getList values components
>   | otherwise = []
>   where components = splitTemplate readValues
>         values = getURL (splitURL url) method
>
> This gives the following error:
>
>  Couldn't match type ‘IO String’ with ‘[Char]’
>     Expected type: String
>       Actual type: IO String
>
> How can I solve this?

Start with reading some basic Haskell book/tutorial.  That should tell
you how to e.g. use 'do' notation, or `liftM`, to achieve what you
want.

/M

-- 
Magnus Therning                      OpenPGP: 0xAB4DFBA4
email: magnus at therning.org   jabber: magnus at therning.org
twitter: magthe               http://therning.org/magnus


More information about the Beginners mailing list