A way to avoid a common use of unsafePerformIO

前端 未结 5 842
天命终不由人
天命终不由人 2021-01-03 23:37

I often find this pattern in Haskell code:

options :: MVar OptionRecord
options = unsafePerformIO $ newEmptyMVar

...

doSomething :: Foo -> Bar
doSomethi         


        
5条回答
  •  太阳男子
    2021-01-03 23:51

    Use implicit parameters. They're slightly less heavyweight than making every function have Reader or ReaderT in its type. You do have to change the type signatures of your functions, but I think such a change can be scripted. (Would make a nice feature for a Haskell IDE.)

提交回复
热议问题