Free Monads - Rib

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Sridhar Ratnakumar

Replacing TOML with Free monads. In a static site of tracking every data (like diet, health). a la https://quantifiedself.com/

Joel McCracken

do you have some examples?

Sridhar Ratnakumar

Using barebie to declare the per-day entry record:

declareBareB
  [d|
    data Entry'
      = Entry'
          { skin :: Mood,
            food :: [F],
            note :: Maybe Markdown
          }
    |]

And then doing free monad magic to build these entries in a monadic fashion:

      runEntry $ do
        setSkin Neutral
        common0
        addFoods [ffWagyu, costcoShrimpW]
     where
           common0 = do
            addFood $ Coffee 3
            addFood $ fwTallow
            addFood $ pepper
Sridhar Ratnakumar

No files under ./a. All data lives in Haskell source. Full type safety. :-D (Toml doesn't handle non-trivial ADTs)

Joel McCracken

speaking of which, ive thought a bit about doing this; a next-version of what I am doing might be some language within a haskell quasiquoter

Sridhar Ratnakumar

Current snapshot of the module: https://gist.github.com/srid/136adf8009e7576f2fedc3f789d34e76

GitHub Gist: instantly share code, notes, and snippets.
Sridhar Ratnakumar

One interesting thing about the free monad is that, I can swap out in-memory record building with something totally different, like writing to sqlite DB if I want, without changing the free monad 'program' (technically, DSL)