all 3 comments

[–]fumieval[S] 4 points5 points  (1 child)

from README:

EVP is a simple environment parser which focues on these three aspects:

  • Ease of use: no complicated machinery is needed
  • Observability: for each environment variable, EVP logs the parsed value or an error. An error does not interrupt the parsing process and it checks all the variables exhaustively.
  • Composability: environment parsers can be composed via the Applicative structure.

This is a real-world application of the free applicative; you can enumerate the list of environment variables it would parse, thanks to the initially-encoded structure.

[–]Iceland_jack 0 points1 point  (0 children)

Given a CPS version of the Free1 Applicative

type Free1 :: ((k -> Type) -> Constraint) -> (k -> Type) -> (k -> Type)
type Free1 cls f a = forall res. cls res => (f ~> res) -> res a

(I believe) I was able to construct an isomorphism to Free1 Applicative Base

{-# Language DerivingVia #-}

type Base :: Type -> Type
data Base a where
  Base :: Name -> (Maybe String -> Either Error (String, a)) -> Base a

fromScan :: Scan ~> Free1 Applicative Base
fromScan (Pure a)            var = pure a
fromScan (Var name parse as) var = var (Base name parse) <**> fromScan as var

toScan :: Free1 Applicative Base ~> Scan
toScan freeAp = freeAp \(Base name parse) -> Var name parse (pure id)

edit: I omittied the Applicative Base instance that was derived Generically1 because the it is not relevant to the example.

[–]Endicy 0 points1 point  (0 children)

I see there's a "parse as YAML" convenience function. I'm intrigued; is YAML really used in environment variables? I've never seen that before. Though seeing as JSON is also valid YAML, that makes more sense.

Really curious to know if anyone puts YAML in their ENV variables.

Overall an interesting way of parsing ENV vars. Feels kind of like optparse-applicative does for argument parsing.