
Hi, I’ve haskell files parser.hs and email.hs email.hs is a module imported into parser and parser has the main. email has various passwords and server names needed to connect and send email. I want to have those details in a config file and read it in at start - using say config module. I’m ok with this part but the practicality of doing it eludes me... It seems to me that email module can either get the config details itself or be told them by parser. If email wants to get them how would it do this? It does not have a main that gets run so can’t load a config file.(can it ??) However parser can load the config in its main and then tell mail what the values are but how would mail save them? Of course I could chanage the signatures of the email send/receive functions in mail to take the connection details but that seems wrong. Thanks Mike

It would me more logical if you had three modules, Parser, EMail, Main,
where Main imports the other two, and they are independent.
On 7 June 2015 at 00:13, Mike Houghton
Hi,
I’ve haskell files parser.hs and email.hs email.hs is a module imported into parser and parser has the main.
email has various passwords and server names needed to connect and send email. I want to have those details in a config file and read it in at start - using say config module. I’m ok with this part but the practicality of doing it eludes me...
It seems to me that email module can either get the config details itself or be told them by parser. If email wants to get them how would it do this? It does not have a main that gets run so can’t load a config file.(can it ??)
However parser can load the config in its main and then tell mail what the values are but how would mail save them?
Of course I could chanage the signatures of the email send/receive functions in mail to take the connection details but that seems wrong.
Thanks
Mike
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Regards Sumit Sahrawat

You can save the values inside the EMail module at startup using a global variable, but that is not recommended. ( https://wiki.haskell.org/Top_level_mutable_state) On 7 June 2015 at 00:15, Sumit Sahrawat, Maths & Computing, IIT (BHU) < sumit.sahrawat.apm13@iitbhu.ac.in> wrote:
It would me more logical if you had three modules, Parser, EMail, Main, where Main imports the other two, and they are independent.
On 7 June 2015 at 00:13, Mike Houghton
wrote: Hi,
I’ve haskell files parser.hs and email.hs email.hs is a module imported into parser and parser has the main.
email has various passwords and server names needed to connect and send email. I want to have those details in a config file and read it in at start - using say config module. I’m ok with this part but the practicality of doing it eludes me...
It seems to me that email module can either get the config details itself or be told them by parser. If email wants to get them how would it do this? It does not have a main that gets run so can’t load a config file.(can it ??)
However parser can load the config in its main and then tell mail what the values are but how would mail save them?
Of course I could chanage the signatures of the email send/receive functions in mail to take the connection details but that seems wrong.
Thanks
Mike
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Regards
Sumit Sahrawat
-- Regards Sumit Sahrawat

Global state is an option - thanks. Didn't think Haskell allowed this.
Having three modules may be more logical but doesn't it just put the same problem into the new module?
Thanks
On Saturday, 6 June 2015, 19:43, Mike Houghton

Yeah, sorry I missed the last line on my first read.
The link I gave you also explains how to achieve the same functionality as
global variables without using them.
The unsafePerformIO hack works, but for small modules it's much more
helpful to do it safely.
On 7 June 2015 at 00:37, mike h
Global state is an option - thanks. Didn't think Haskell allowed this.
Having three modules may be more logical but doesn't it just put the same problem into the new module?
Thanks
On Saturday, 6 June 2015, 19:43, Mike Houghton < mike_k_houghton@yahoo.co.uk> wrote:
Hi,
I’ve haskell files parser.hs and email.hs email.hs is a module imported into parser and parser has the main.
email has various passwords and server names needed to connect and send email. I want to have those details in a config file and read it in at start - using say config module. I’m ok with this part but the practicality of doing it eludes me...
It seems to me that email module can either get the config details itself or be told them by parser. If email wants to get them how would it do this? It does not have a main that gets run so can’t load a config file.(can it ??)
However parser can load the config in its main and then tell mail what the values are but how would mail save them?
Of course I could chanage the signatures of the email send/receive functions in mail to take the connection details but that seems wrong.
Thanks
Mike
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Regards Sumit Sahrawat

Can we please not suggest "not recommended" solutions (that most of us
probably wouldn't use) without at least providing a recommended alternative?
You can parse the config file into a record and then either pass it as an
argument wherever it is needed or use Reader (or ReaderT) to make it more
implicit.
On Sat, Jun 6, 2015 at 12:16 PM Sumit Sahrawat, Maths & Computing, IIT
(BHU)
Yeah, sorry I missed the last line on my first read.
The link I gave you also explains how to achieve the same functionality as global variables without using them. The unsafePerformIO hack works, but for small modules it's much more helpful to do it safely.
On 7 June 2015 at 00:37, mike h
wrote: Global state is an option - thanks. Didn't think Haskell allowed this.
Having three modules may be more logical but doesn't it just put the same problem into the new module?
Thanks
On Saturday, 6 June 2015, 19:43, Mike Houghton < mike_k_houghton@yahoo.co.uk> wrote:
Hi,
I’ve haskell files parser.hs and email.hs email.hs is a module imported into parser and parser has the main.
email has various passwords and server names needed to connect and send email. I want to have those details in a config file and read it in at start - using say config module. I’m ok with this part but the practicality of doing it eludes me...
It seems to me that email module can either get the config details itself or be told them by parser. If email wants to get them how would it do this? It does not have a main that gets run so can’t load a config file.(can it ??)
However parser can load the config in its main and then tell mail what the values are but how would mail save them?
Of course I could chanage the signatures of the email send/receive functions in mail to take the connection details but that seems wrong.
Thanks
Mike
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Regards
Sumit Sahrawat _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

On 7 June 2015 at 01:44, Rein Henrichs
Can we please not suggest "not recommended" solutions (that most of us probably wouldn't use) without at least providing a recommended alternative?
I wholeheartedly agree. I mentioned that it is not recommended, and gave a link where that point was stressed much better than I could hope to do. A global variable turns out be the most accessible and easy solution, and it provides a good playground to experiment with trying to replace them with something else. -- Regards Sumit Sahrawat

Hi, My primary uses case was to set username/passord and server details for an emailing module. Using some of the ideas in this email chain I’ve written a small module at https://github.com/mike-k-houghton/AppConfig I hope someone might find it useful. Thanks
On 6 Jun 2015, at 21:14, Rein Henrichs
wrote: Can we please not suggest "not recommended" solutions (that most of us probably wouldn't use) without at least providing a recommended alternative?
You can parse the config file into a record and then either pass it as an argument wherever it is needed or use Reader (or ReaderT) to make it more implicit. On Sat, Jun 6, 2015 at 12:16 PM Sumit Sahrawat, Maths & Computing, IIT (BHU)
wrote: Yeah, sorry I missed the last line on my first read. The link I gave you also explains how to achieve the same functionality as global variables without using them. The unsafePerformIO hack works, but for small modules it's much more helpful to do it safely.
On 7 June 2015 at 00:37, mike h
wrote: Global state is an option - thanks. Didn't think Haskell allowed this. Having three modules may be more logical but doesn't it just put the same problem into the new module?
Thanks
On Saturday, 6 June 2015, 19:43, Mike Houghton
wrote: Hi,
I’ve haskell files parser.hs and email.hs email.hs is a module imported into parser and parser has the main.
email has various passwords and server names needed to connect and send email. I want to have those details in a config file and read it in at start - using say config module. I’m ok with this part but the practicality of doing it eludes me...
It seems to me that email module can either get the config details itself or be told them by parser. If email wants to get them how would it do this? It does not have a main that gets run so can’t load a config file.(can it ??)
However parser can load the config in its main and then tell mail what the values are but how would mail save them?
Of course I could chanage the signatures of the email send/receive functions in mail to take the connection details but that seems wrong.
Thanks
Mike
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Regards
Sumit Sahrawat _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Greetings,
Better style in functional programming is to be as stateless as possible. Reverting to using global state, your life would be easier coding in Python. Isn’t this a classic use for a Reader monad, which is for the purpose of passing an environment around without having to do so explicitly?
Andrew
On 7/06/2015, 05:07, "Beginners on behalf of mike h"
participants (5)
-
Andrew Bernard
-
mike h
-
Mike Houghton
-
Rein Henrichs
-
Sumit Sahrawat, Maths & Computing, IIT (BHU)