[Haskell-beginners] How to pass configuration to a function further down the call stack?

Christopher Allen cma at bitemyapp.com
Tue Sep 30 21:23:58 UTC 2014


First, define a datatype unifying all this config information.

Then there are two simple, common solutions.

If only one or two functions need to be passed the Config data, then just
pass it as an argument. If use of the config data is going to be prolific,
you might want to consider Reader.

http://stackoverflow.com/questions/14178889/reader-monad-purpose
http://book.realworldhaskell.org/read/programming-with-monads.html
https://hackage.haskell.org/package/transformers-0.4.1.0/docs/Control-Monad-Trans-Reader.html

You could engage in deeper magic than this, but it's not worth it for your
use-case.

Hope this helps.

-- Chris


On Tue, Sep 30, 2014 at 3:15 PM, Thomas Koch <thomas at koch.ro> wrote:

> Hi,
>
> I wrote my first Haskell 'project', a test suite for my personal SIEVE mail
> filter script using dovecots 'sieve-test' tool:
>
> https://github.com/thkoch2001/sieve-test-hs
>
> The file Network/Sieve/Test.hs might actually be interesting as a
> standalone
> library. The most important function is
>
> assertMailActions :: Mail -> Actions -> IO ()
>
> 'Actions' is a type that describes the result of running a SIEVE filter
> over
> the passed mail, e.g. store in a certain folder, discard, reject, ...
>
> Somewhere the external process 'sieve-test' is called. At this point I'd
> like
> to make certain things configurable:
>
> - the path and name of the executable
> - the parameters for the test-sieve executable
> - the name of the sieve script
> - the place where to store the temporary mail files
> - whether or not to remove the temporary mail files
>
> Does anybody has an idea where I could start to look for a solution?
>
> Thank you,
>
> Thomas Koch
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140930/cdc97e05/attachment.html>


More information about the Beginners mailing list