[Haskell-beginners] global variables

prad prad at towardsfreedom.com
Wed Aug 11 15:54:18 EDT 2010


i'm curious about the best way to deal with conn to make db connections.

i define it in main like this, then when i want to use it in a function
i have to pass it as a parameter:

main = do
    conn <- connectPostgreSQL ...
    fn conn something


fn conn x = ...


now conn is a global variable i guess because it is defined in main,
but perhaps main isn't considered a global namespace? i recall in
python a global variable could be accessed by functions, but in php
they can't unless you use "global" within the function.

so is this the correct way to handle such things? right now it seems
to be the only way in haskell.

-- 
In friendship,
prad

                                      ... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's


More information about the Beginners mailing list