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

Alexander Dunlap alexander.dunlap at gmail.com
Fri Aug 22 21:58:22 EDT 2008


On Wed, Aug 20, 2008 at 1:49 AM, Henning Thielemann
<lemming at henning-thielemann.de> wrote:
>
> On Mon, 18 Aug 2008, ajb at spamcop.net wrote:
>
>> G'day all.
>>
>> Quoting Bjorn Buckwalter <bjorn.buckwalter at gmail.com>:
>>
>>> 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.
>>
>> In this situation, there isn't necessarily any shame in using a
>> top-level unsafePerformIO as long as it's well-hidden:
>>
>>  module AstroData (AstroData(..), globalAstroData) where
>>
>>  data AstroData = AstroData Int
>
> But here my argument about playing around with the Planck constant becomes
> relevant.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

You can always change how you unsafePerformIO the data, though. If you
want to set Planck's constant to 42 (or whatever), just change the
unsafePerformIO $ <whatever> to unsafePerformIO $ return 42.

Alex


More information about the Haskell-Cafe mailing list