Skip to content

Instantly share code, notes, and snippets.

@thanthese
Created July 28, 2012 22:33
Show Gist options
  • Save thanthese/3195027 to your computer and use it in GitHub Desktop.
Save thanthese/3195027 to your computer and use it in GitHub Desktop.
convert [IO String] to IO [String]
-- I'm attempting to create a function that converts [IO String] to IO
-- [String]. I wasn't able to find one in the standard libraries, but then I'm
-- a noob.
convert :: [IO String] -> IO [String]
convert badWords = convert' badWords []
where
convert' [] good = return good
convert' bad good = bad >>= (\w -> convert' (tail bad) (w : good))
-- This attempt throws this error. Ideas?
--
-- Couldn't match expected type `IO [String]'
-- against inferred type `[[IO String]]'
-- In the expression: convert' badWords []
-- In the definition of `convert':
-- convert badWords
-- = convert' badWords []
-- where
-- convert' [] good = return good
-- convert' bad good = bad >>= (\ w -> convert' (tail bad) (w : good))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment