Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. module "static" data (Dennis Raddle) 2. Re: module "static" data (Dennis Raddle) 3. Re: module "static" data (Felipe Almeida Lessa) ---------------------------------------------------------------------- Message: 1 Date: Tue, 10 Jan 2012 10:45:57 -0800 From: Dennis Raddle <dennis.rad...@gmail.com> Subject: [Haskell-beginners] module "static" data To: Haskell Beginners <beginners@haskell.org> Message-ID: <CAKxLvoqR+manWFtVPT76gSwFjCn2t7k=YtQhSS97st+=C=g...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" I would like to know how to do something in Haskell. I have a module which needs to load some data from disk in order to run, and I'd like to load it at most once. In C, I would use a "static" variable in the module to store the data. How can I do this in Haskell? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20120110/bd92fd9c/attachment-0001.htm> ------------------------------ Message: 2 Date: Tue, 10 Jan 2012 11:17:22 -0800 From: Dennis Raddle <dennis.rad...@gmail.com> Subject: Re: [Haskell-beginners] module "static" data To: Haskell Beginners <beginners@haskell.org> Message-ID: <CAKxLvoo_ZqS4+AX=poyefahj5vz+gs7zl+vqg+pnajt0urr...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" I should clarify. I have many modules A, B, C, D, .. which need to load configuration from disk--each module its own data type AData, BData, CData... . One solution is to load the data once at the highest common level (call it Common) and pass it to each module. But the way Common calls the modules is like this (this is my original code which ignores the need for configuration: fnLookupTable :: [(String, String -> Int)] fnLookupTable = [ ("a", moduleAFn) ,("b", moduleBFn) ] commonFunction :: [String] -> [Int] commonFunction ss = do let lookupFn functionName = fromJust $ lookup functionName fnLookupTable result = map (\s -> ((lookupFn s) "some input")) ss return result So if I were to pass some configuration to each module I would need to change the type signature of fnLookupTable: fnLookupTable :: [(String, ConfigurationData -> String -> Int)] data ConfigurationData = TypeACons AData | TypeBCons BData | TypeCCons CData What's annoying about this is the need to make this extra type ConfigurationData and what's worse, I can't hide AData, BData, CData in the modules A, B, C. This commonFunction has to "know" about them. If I modify modules or add new modules there's an extra step, modifying ConfigurationData. On Tue, Jan 10, 2012 at 10:45 AM, Dennis Raddle <dennis.rad...@gmail.com>wrote: > I would like to know how to do something in Haskell. I have a module which > needs to load some data from disk in order to run, and I'd like to load it > at most once. In C, I would use a "static" variable in the module to store > the data. How can I do this in Haskell? > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20120110/c3cd3d47/attachment-0001.htm> ------------------------------ Message: 3 Date: Tue, 10 Jan 2012 17:26:54 -0200 From: Felipe Almeida Lessa <felipe.le...@gmail.com> Subject: Re: [Haskell-beginners] module "static" data To: Dennis Raddle <dennis.rad...@gmail.com> Cc: Haskell Beginners <beginners@haskell.org> Message-ID: <CANd=OGG6TbbqhMADryvtR9v30QSVc8JS24qa+mpC99Y=tcy...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 You could try something like fnLookupTable :: IO [(String, String -> Int)] fnLookupTable = do confA <- getConfigA confB <- getConfigB return [("a", moduleAFn confA) ("b", moduleBFn confB)] Now you pass the result of fnLookupTable around. HTH, -- Felipe. ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 43, Issue 14 *****************************************