[Haskell-beginners] About scope range: outside of the do-block

S. H. Aegis shaegis at gmail.com
Sun Apr 20 13:47:10 UTC 2014


It works !
Thank you so much !
Have a nice day~




2014-04-20 22:09 GMT+09:00 Roel van Dijk <vandijk.roel at gmail.com>:

> On 20 April 2014 14:57, S. H. Aegis <shaegis at 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.List
>> import Data.List.Split
>> import Data.Char
>> import Data.Maybe
>>
>> main :: IO ()
>> main = do
>>     names <- readFile "names.txt"
>>     print $ sum $ map (\x -> getPosition names x * getScore x) names
>>
>> getPosition :: [String] -> String -> Int
>> getPosition names x = fromMaybe 0 (elemIndex x $ sortedNamesList names) +
>> 1
>>
>> getScore :: String -> Int
>> getScore xs = sum $ map (\x -> ord x - 64) xs
>>
>> sortedNamesList :: [String] -> [String]
>> sortedNamesList names = sort $ nameList names
>>
>> nameList :: String -> [String]
>> nameList = split (dropDelims . dropBlanks $ oneOf ",\"")
>>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>


-- 
Sok Ha, CHANG
Dr. Chang's Clinic. #203. 503-23. AmSa-Dong, GangDong-Gu, Seoul.
Tel: +82-2-442-7585
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140420/452b2234/attachment-0001.html>


More information about the Beginners mailing list