Elm app inspired by the paper Out of the Tar Pit
The idea is as follows:
- all code adds complexity, and too much complexity is bad
- "essential" complexity lives in essential business logic you can't do without
- "accidental" complexity is everything else
- essential code should never be aware of or require accidental code
- (bonus - the relational algebra is a preferred way to represent data)
Given these ideas, I've created a "student course enrollment" app.
Essential.elm
contains the Essential model and it's operations.
this enables a clean separation of persistence concerns. It has it's own update : EssentialModel -> Message -> Result String EssentialModel
.
Note that this will never return a command or enable subscriptions as those are accidental complexities.
AppTypes.elm
contains our Model
type. It is comprised of an EssentialModel
and a UIState
.
Because essential complexity is cleanly separated from accidental complexity, the app can operate in 2 modes "strategies".
See: App.elm
We see
strategy : Model -> EssentialModel -> ( Model, Cmd Message )
is responsible for taking a model, our updated essential model, adn deciding what to do.
It can either:
- update the model
- send a Cmd representing an essential model diff
In the second case, we imagine this diff goes to an extarnal database, and we are informed of patches coming from the database via subscription.
Our dummy db (see here) simply echoes diffs back as patches after a delay to immitate lag.
ListBackedSet.elm is simply a way to have a Set interface in Elm without requireing comparability of members. It's for example purposes only and not recommmended for production code.
Json.elm is our Encoder/Decoder stuff. Not particulary interesting.
Diff.elm is our Diffing stuff. Not particulary interesting.