Limited multi-argument option parsing #510
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @HuwCampbell, it's been a while, but I think I've figured this one out, based loosely on your idea of changing
ReadM.My realisation was that both your concerns, breaking
ReadMand users' ability to do crazy stuff with it, could be addressed by means of a tiered system ofConsumeMand the originalReadM.This separates the concerns nicely and lets us hide the undesired operations that the
ConsumeMwould otherwise provide.This way you can have a straightforward but powerful core, as well as a limited user interface that only exposes whatever we deem sensible argument handling strategies. For now that's statically fixed sets of 0, 1 or 2 arguments, where of course only the 2-argument case is truly new. The 0 and 1 just fall out of the design naturally, and could perhaps play a role in someone's code if they have a use for abstracting over their options' arity somewhat.
Anyway, this is now entirely "simple" Haskell if that's the right term for it. No new extensions.
My only worry in terms of code complexity is the extra indirections due to the
Internalmodule. I suppose what we could do instead is inline that into theConsumeAmodule, "hide" its symbols there and drop the tests for it. They're not too interesting anyway. Then we can get rid of some type parameters and type aliases.I'd be happy to do that if you prefer.
Example:
->
References