-
Notifications
You must be signed in to change notification settings - Fork 57
Conversation
This reverts commit 2a0b2d7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does depend on #1150 |
I'll take a look at this in detail as I need to get in the habit of doing this sort of thing anyway. I'm guessing we can merge it into |
Should lib/generators be refactored to also be using an explicitly monadic style? (That's the like, preexisting IO monad that is similarly used for forms, and also does the impossible to migrate in-flight "wrap it all in a continuation" thing; still hoping to figure out a way to add wires / explicit state to both tbh) |
I do think that would look cleaner at the call site with I do hope to eventaually extend something that looks like the ph monad to be able to upgrade in-flight. It's not necessary for ph tests (just nuke 'em on upgrade), but obviously for most apps/vanes you want that. Basic strategies are (1) include a prep/stay arm in the monad type; (2) occasionally "save your state" explicitly; on reload just start from that point; (3) record "inputs" and replay them (similar to how old ford handled this). I thought you would get a kick out of this:
If you call Useful if you want to define a function which first sends all its arguments to another function (in my case, |
I rejiggered pH tests to have monadic operations and satisfy the monad laws. This allows them to be fully composable, which makes it much easier to build more complex tests in terms of simpler ones.
This also includes "philters", which are stateful wrappers around tests. In
lib/ph/azimuth.hoon
we implement a mock ethereum node as a philter.I refactored
lib/ph.hoon
into five files:lib/ph.hoon
: the ph monad.lib/ph/tests.hoon
: small library of tests that may be composed into larger tests.lib/ph/util.hoon
: useful functions for building raw tests.lib/ph/philter.hoon
: the philter framework.lib/ph/azimuth.hoon
: a philter for mocking an ethereum node.A few notes on naming:
The name of the type of the monad was "data", but I've changed it to "form". If we write more monads, we should try to be consistent with these names. "data" is meaningless and yet still misleading (sure, code is data, but we don't need to rub it in their faces), "M" (following the notation used in papers) is problematic, and "t" (following ML) is one letter and claimed for "tail of a list" and "fifth element of a quintuple". "form" is unused in the standard library, though there are a couple of uses of it in more specific contexts. However, that sort of collision isn't relevant here because you should always be qualifying your monadic operations; e.g.
form:(ph ,~)
.I've changed "return" to "pure". "return" is a weird word that is likely to confuse anyone who's more familiar with imperative programming than monads. "unit" is taken, so "pure" is the other standard name for it. I like that it gives the idea of "don't do anything special or stateful or effectful, just produce this result".
Then, a monad in this form looks like:
I would write a lead superclass for monads, but wet gates don't nest in anything.