Passing around config

15 views
Skip to first unread message

Mark Wales

unread,
Mar 31, 2018, 8:03:08 AM3/31/18
to Brick Users
Is there any recommended way of passing around (immutable) config?

When my project loads I read various config stuff from various files. If it wasn't a Brick app I'd use `ReaderT` to pass it around the place. But given Brick's type is already using a few layers of monads, adding *another* one seems like it might get a bit confusing - I did try this, but got a bit stuck. The only other way I can think would be to add it to my State. Am I missing something obvious? Still fairly new to Haskell.


Thanks,

Mark

Jonathan Daugherty

unread,
Mar 31, 2018, 11:57:47 AM3/31/18
to Mark Wales, Brick Users
Hello,

> Is there any recommended way of passing around (immutable) config?
>
> When my project loads I read various config stuff from various files.
> If it wasn't a Brick app I'd use `ReaderT` to pass it around the
> place. But given Brick's type is already using a few layers of monads,
> adding *another* one seems like it might get a bit confusing - I did
> try this, but got a bit stuck. The only other way I can think would be
> to add it to my State. Am I missing something obvious? Still fairly
> new to Haskell.

Another approach is to bind such configuration to your top-level
functions like so, e.g.,

mkApp :: Config -> App s e n
mkApp cfg =
App { appDraw = drawUI cfg
, appChooseCursor = ...
, appHandleEvent = appEvent cfg
, appStartEvent = ...
, appAttrMap = ...
}

main :: IO ()
main = do
cfg <- ...
let app = mkApp cfg
...

--
Jonathan Daugherty

Mark Wales

unread,
Apr 3, 2018, 4:46:15 AM4/3/18
to Brick Users
Ah, ok. Think that's what I'm doing already. Glad it's not a mad way of doing things.

Mark Wales

unread,
Apr 3, 2018, 4:46:52 AM4/3/18
to Brick Users
And thanks!
Reply all
Reply to author
Forward
0 new messages