[Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

Bjorn Buckwalter bjorn.buckwalter at gmail.com
Mon Aug 18 10:59:14 EDT 2008


All,

I have a growing amount of astrodynamics code that relies on various
physical "constants". The problem with these so called "constants" are
that they either aren't really constants or aren't well known. An
example is the leap second table (see Data.Time.Clock.TAI). I'd like
to be able to fetch current values of these constants at runtime and
make them accessible to my astrodynamics functions by some means. To
clarify, once initialized the constants will be considered constant
for the remainder of the program.

I'd store the constants in a data structure along the lines of:

> data AstroData a = AstroData
>   { mu_Earth    :: GravitationalParameter a
>   , leapSeconds :: LeapSecondTable
>   }

I would like to know if there is any consensus on what is the best way
to make such a data structure accessible in pure functions. Passing it
explicitly would be a mess. It seems that two options are to use
either a Reader monad or implicit parameters. Using a Reader monad is
straight forward enough though it requires writing/converting code
in/to monadic style and adds some clutter to the formulae. It seems
implicit parameters could be cleaner but I've seen them referred to as
everything from evil to "just what you need" and rendering the Reader
monad obsolete...

What do you people recommend?

Thanks,
Bjorn Buckwalter


More information about the Haskell-Cafe mailing list