Creating a Budget Template using Haskell, Org, and Literate Programming - Part 1 (probably)

Table of Contents

1. Budgeting Fundamentals

Whenever I right out my monthly budget, it usually is categories with line items or subcategories under those. Then add up the numbers, compare to my expected take-home page, do any adjustments, and then add we accumulate expenses, the actual spending is compared to the budgeting, with live adjustments. All the way until the next month. Usually this are handwritten (or sometimes use YNAB), but use a spreadsheet or calculator anyways, write these out and make an inky mess of corrections throughout the month. Ideally, this will help with that problem by providing a bit of a fresh interface to this, that can still be printed if desired.

  • Adding and subtracting numbers (into groups, difference actual to budgeting)
  • Tables / list of numbers
  • grouping numbers by categories (Bills, Savings, Debt, etc)

A Future state of this may try to address the paid-every-2-weeks that doesn't perfectly fit into a month issue, but for now, that is ignored.

2. Adding list of numbers

Fortunately, Haskell makes it easy to add a list of numbers by running the sum function on the list. Here I'm setting a list with numbers, then summing them up. Additionally, I've passed in the #+NAME to the source block so that I can pass that name into other blocks of code (this will be especially usefull when creating a summary.

let b = [128.3, 90, 223.3, 120, 175]
sum b
736.6

3. Input into the next eval block

Now that the previous example was successfull, We can try to pass the result into this next code block by setting a variable with :var in the #+BEGING_SRC declaration. Then assigning another source block name (the #+NAME: above) to a variable to be used in the current source block. In this case setting intArraySum to the result from initial-array.

let c = [123, 85.3, 12.4]
subtract (sum c) intArraySum
ghci> 515.9

Not sure why this block's evaluated differently with the ghci string as part of the result. Lets pass the output to another block now to see if the ghci> gets in the way.

addFive x = x + 5
addFive nextVar
ghci> 
<interactive>:368:1-7: error:
    * No instance for (Num String) arising from a use of `addFive'
    * In the expression: addFive nextVar
      In an equation for `it': it = addFive nextVar

So the ghci looks like it is messing up passing, but when I added a sum c into the source block it returned without the ghci (still not sure why). Which means we can pass this result to yet another function.

let c = [123, 85.3, 12.4]
sum c
subtract (sum c) intArraySum
515.9
addFive x = x + 5
addFive nextVar
ghci> 520.9

and I get the gchi prompt again…

4. Next Time

May or may not continue part 2 tomorrow, but I do need to figure out how to get org table in as list. If I can do that natively without custom effort, then I part 2 may be it. Otherwise, I'm probably going to work on some other task tomorrow.

Date: 2022-11-23

Author: Russell Brinson

Created: 2022-11-22 Tue 14:56

Validate