On 20 April 2014 14:57, S. H. Aegis <shaegis@gmail.com> wrote:Is there any other ways to use variables outside of the "do-block"?You can pass the list of names as an argument where it is needed.import Data.Listimport Data.List.Splitimport Data.Charimport Data.Maybemain :: IO ()main = donames <- readFile "names.txt"print $ sum $ map (\x -> getPosition names x * getScore x) namesgetPosition :: [String] -> String -> IntgetPosition names x = fromMaybe 0 (elemIndex x $ sortedNamesList names) + 1getScore :: String -> IntgetScore xs = sum $ map (\x -> ord x - 64) xssortedNamesList :: [String] -> [String]sortedNamesList names = sort $ nameList namesnameList :: String -> [String]nameList = split (dropDelims . dropBlanks $ oneOf ",\"")
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners