writer :: DataBase -> IO ()
writer [] = writeFile "output.txt" ""
writer xs = writeFile "output.txt" (createOutput xs)
createOutput :: DataBase -> String
createOutput [] = ""
createOutput (x:xs) = (show (get1 x)++", "++ (get2 x)++", "++(get3 x)++", "++show(get4 x) ++", "++show(get5 x)++", "++show(get6 x)++"\n") : createOutput xs
recursive call at the end of createOutput
: createOutput xs
breaks my function, it works fine without recursion, but I cannot execute it recursivly , which is whole point. What I am trying to do is to get values from a "Custom" data type which is basically a list of tuples and get1 get2 etc, fetches first second and so on element in tuple
type Id = Integer
type Song = String
type Group = String
type Year = Integer
type Length = Integer
type Rate = Rational
type Data = (Id, Song, Group, Year, Length, Rate)
type DataBase = [Data]
get1 (a1, _, _, _, _, _) = a1
get2 (_, a2, _, _, _, _) = a2
get3 (_, _, a3, _, _, _) = a3
get4 (_, _, _, a4, _, _) = a4
get5 (_, _, _, _, a5, _) = a5
get6 (_, _, _, _, _, a6) = a6
I am using show to convert non string variables to string, but everything falls apart when I am trying to make function call it self recursively, I attempted adding bunch of brackets around, or not to use show, but even then with just single get statement it breaks apart and it honestly eludes me why...
I know I can print file with writeFile "output.txt" (show xs), but it doesnt produce output I want, which is having no quotation marks and new line for each tuple
Aucun commentaire:
Enregistrer un commentaire