Building web app with FP - Part V - Configuring your application with #Dhall ⚙️

This article talks about embedding a simple Dhall configuration within a Servant app.
https://matsumonkie.fr/post/5

3 Likes

Another nice article. Thanks!

A couple of questions:

  • What do you think about passing configurations flags as environment variables? Is that bad practice?
  • What do you think about having something like type App = (<constraints>) or even newtype App = <transformers-stack> instead of using mtl in functions?

Btw ask <&> f can also be written as asks f :slight_smile:

2 Likes

Thank you gilmi!

What do you think about having something like type App = () or even newtype App = instead of using mtl in functions?

I personally prefer to use constraints rather than one huge application type. It’s more composable, and readable (IMO). It’s nice to be able to tell at a glance, this function needs IO, Reader,…

Also, sometimes, for a given function, you don’t need the whole stack capabilities:

closeDBConnection :: (IO.MonadIO m) => PG.Connection -> m () -- doesn't need MonadReader
closeDBConnection connection =
  IO.liftIO $ PG.close connection

There is a nice ghc option - -Wredundant-constraints that triggers a warning if I add MonadReader constraint on this function.

What do you think about passing configurations flags as environment variables? Is that bad practice?

I personally like having a static and typed configuration with Dhall for medium to big projects but for everything else I don’t mind using environment variable, yaml, json,…

Btw ask <&> f can also be written as asks f :slight_smile:

Good pick! I edited the article.

1 Like

Thank you for the posts! I’m gonna start reading your blog posts when I’m less busy with school. This is right up my alley.

2 Likes

You’re welcome! Don’t hesitate to ask if there’s anything unclear :wink:

1 Like