i designed some basic functions, , mainly String -> [String], or similar with types, plus some more complex datatypes. Up to now; i was testing them on a basic database I was creating in the core main, "by hand". Then i added a basic parser with happy; and bingo; my test database is now loaded from a file... as IO String..; huh! after a second though; this makes sense, except that i have to change all the type of my functions; now IO String.. plus a few that just dont compile; and i cant understand why... my question: I had to change most of my type of the functions.as is propagated through the code. (i.e. f need g; that need h; etc...) to add IO. is that kind of propagation normal, or can i Stop it somewhere ? how? is that because my functions just uses string as type ? and not data (ie type relation =string; instead data Relation String) can i design a function that will do IO String-> String, or IO String -> Data X, that will stop that IO propagation , through my code ? how can i handle function when my database is not IO, then ? i suppose im not the first to ask. any link ? thread ? faq example would be welcomed...
On Sun, 13 May 2001, luc wrote:
i designed some basic functions, , mainly String -> [String], or similar with types, plus some more complex datatypes.
Up to now; i was testing them on a basic database I was creating in the core main, "by hand". Then i added a basic parser with happy; and bingo; my test database is now loaded from a file... as IO String..; huh!
after a second though; this makes sense, except that i have to change all the type of my functions; now IO String..
plus a few that just dont compile; and i cant understand why...
my question: I had to change most of my type of the functions.as is propagated through the code. (i.e. f need g; that need h; etc...) to add IO. is that kind of propagation normal, or can i Stop it somewhere ? how?
You can stop it at the very beginning: f :: String -> String g :: [A] -> [B] -- etc, any functions without IO parse :: [String] -> [ A ] main = do h <- openFile "sampleFile" ReadMode contents <- hGetContents h -- and now you have file contents binded to contents and you can apply your --functions any way you want, i. e. let result = g (parse contents) putStrLn (show result) Wojciech Moczydlowski, Jr
participants (2)
-
luc -
Wojciech Moczydlowski, Jr