I am a bit confused by your response Mieszko. What I am looking to do is have a function say called ConvertString :: IO String -> String or something like that. Not sure if your examples achieve this. I want to take the IO String and be able to use it as a String somehow. My problem is I have a function for instance getWord :: String -> String getWord [] = [] getWord (x:xs) | elem x whitespace = [] | otherwise = x : getWord xs If I change the header to getWord :: IO String -> IO String I get errors of types not matching. Sorry if these are stupid questions but I am very confused by the difference of IO String and String, and want to know how you can use the IO String like a String. Thank you. Rob
Perhaps the following code will fit your purpose: main :: IO () main = do file <- readFile "c:/myfile.txt" word <- getWordIO file getWordIO :: String -> IO String getWordIO word = return (getWord word) Where getWord is the same you defined. You can also try: main :: IO () main = readFile "c:/myfile.txt" >>= \file -> getWordIO file Notice that ConvertString wouldn't work because functions must not start with capital letters :) Andre ----- Original Message ----- From: <MikeKn22@aol.com> To: <haskell@haskell.org> Sent: Monday, April 02, 2001 10:41 PM Subject: Follow up question
I am a bit confused by your response Mieszko. What I am looking to do is have a function say called
ConvertString :: IO String -> String
or something like that. Not sure if your examples achieve this. I want to take the IO String and be able to use it as a String somehow. My problem is I have a function for instance
getWord :: String -> String getWord [] = [] getWord (x:xs) | elem x whitespace = [] | otherwise = x : getWord xs
If I change the header to
getWord :: IO String -> IO String
I get errors of types not matching. Sorry if these are stupid questions but I am very confused by the difference of IO String and String, and want to know how you can use the IO String like a String. Thank you.
Rob
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
Andre W B Furtado schrieb folgendes am Tue, Apr 03, 2001 at 12:35:05AM -0300:
Perhaps the following code will fit your purpose:
main :: IO () main = do file <- readFile "c:/myfile.txt" word <- getWordIO file
getWordIO :: String -> IO String getWordIO word = return (getWord word)
You may five the follwing a try. main :: IO () main = do file <- readFile "c:/myfile.txt" let word = getWord file -- do some calculations with word -- return result
Where getWord is the same you defined. You can also try: ----- Original Message ----- From: <MikeKn22@aol.com> To: <haskell@haskell.org> Sent: Monday, April 02, 2001 10:41 PM Subject: Follow up question
I am a bit confused by your response Mieszko. What I am looking to do is have a function say called
ConvertString :: IO String -> String
or something like that. Not sure if your examples achieve this. I want to take the IO String and be able to use it as a String somehow. My problem is I have a function for instance
getWord :: String -> String getWord [] = [] getWord (x:xs) | elem x whitespace = [] | otherwise = x : getWord xs
If I change the header to
getWord :: IO String -> IO String
I get errors of types not matching. Sorry if these are stupid questions but I am very confused by the difference of IO String and String, and want to know how you can use the IO String like a String. Thank you.
Rob
-- Stefan Karrmann
participants (3)
-
Andre W B Furtado -
MikeKn22@aol.com -
Stefan Karrmann