Feedback requested: book on API type patterns

Thank you everyone for the feedback! I'm going to work on a second draft this week. I already fleshed out the representational principles, and I added a note about parsing/validating to the intro.

I also use take_mut for this pattern if it doesn't make sense to explicitly represent a Faulted state.

1 Like

It could be just me.. but parsing the cryptic diagrams has taken so much mental energy that I had I seen them on my first reading of the book I would have probably given up and not tried to read any further.

Each reader is equipped with just limited mental capacity per day and to me it seems better spent on HList than on Babylonian numbers and pictures more suited for an IQ test.. Seriously on the first read I just breezed through the intro nodded and delved into the stuff that mattered..

The colors example in the simple 1st version of the intro was prized for a reason - it's light easy to understand and very relatable, we've all been there. The diagrams are also familiar - but for a different reason - these are the sort of puzzles that make my head ache and motivate me to turn and run away.

Hmm, well I certainly don't want to scare people away. Perhaps I can more clearly telegraph that the "main idea" section is optional? You can certainly still learn from the remainder of the book without the representational principles. But I wanted to talk about them because representation theory is a cornerstone of my philosophy on API design. It's how I come up with ideas and wrote this book, so I think it's valuable for people who are interested in that level of depth.

If you want a bridge between typestates and session types, or maybe between session types and HLists, something like this two-phase commit system might make a good example: Each operation has an associated undo log, akin to your session types' duals, which get collected via a series of combinators into an aggregate undo log for the entire transaction. If any operation fails, the collected log is used to immediately revert and no future operations are attempted.

Edit: More info, incl. the combinators I've implemented

1 Like

Hey that's a cool design. I like the idea of commit logs and undo as a thematic concept. I'll read through your implementation and give it some thought.

4 Likes

@willcrichton Any updates on the "semi-cohesive book"?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.