Reputation: 77
so I'm creating a program that will pick one of two libraries (audio.lhs or video.lhs) and will return a pdf with a list ordered and filtered by a given category:
mymain = do {putStrLn "What do you wanna search, Video or Audio?";
tipo <- getLine;
if tipo == "Audio"
then do {
a <- readFile "audio.lhs" ;
let text = splitEvery 7 (splitRegex (mkRegex "\t") a)
list = map musicFile text
select = filter ((>1000) .size) list
orderList = sortBy (comparing title)
dir = Dir orderList
hs = "import Dir\nimport TeX\nimport System.Cmd"
++ "\ntoTeX= do { writeFile \"out.tex\" $ prettyprint dat ;"
++ "system \"pdflatex out\"}"
++ "\ndat="
++ show dir
in do { writeFile "dat.hs" hs ;
putStrLn "\nOk.\nNow load \'dat.hs\' and run \'toTeX\'\n"
}}...
Everything is running but now i need that the functions
select = filter ((>1000) .size) list
and
orderList = sortBy (comparing title)
instead of working with values that are given by me, i want them to work with values choosen by the user of the program (inputs), so if he wants to filter files that are >2000 or <500 is his choice and same with the category,size or title or another thing.
My data structure is
data File = File {
filename :: String ,
size :: Int ,
filetype :: String ,
copyright :: String ,
title :: String ,
artist :: String ,
year :: String } deriving Show
and
musicFile :: [String] -> File
musicFile [name, size, tipo, copy, title, artist, year] = File name (read size) tipo copy title artist year
Any help would be gladly appreciated.
Thanks in advance.
Upvotes: 0
Views: 603
Reputation: 152837
The simplest mechanism available in Haskell for parsing strings is the Read
typeclass. Instances of this class have enough functionality to implement
read :: (Read a) => String -> a
readLn :: (Read a) => IO a
either of which should be enough to get you started on your way to reading an Int
(which is an instance of Read
) from input.
Upvotes: 2