I have been writing higher-order functional programming in Python for the last few weekends:
- hofppy (https://github.com/equational/hofppy) will be a Python library. For the moment it is a collection of Jupyter notebooks.
- My initial goal was to have a handy FP toolkit which supports applied math with JAX's JIT. Yet I realise that in fact what I am really doing is reimplementing the generic part of a compiler for a reactive (trading) language I wrote in 2010 in F#, while including a few tricks I picked up since then, the primary one being to think of code as implementing a synchronous execution model.
- There is really very little code like this on the web, therefore why I am doing this open source.
This blog is in part written to mention the above, as already the first JAX JIT supporting monad and comonad models are "nice". Yet this blog is also to bring up the subject of the process of creating new technology.
My recipe to do something new, such as lead a team on a new subject, write software that did not exist before is the following:
- Create a "mind's eye" imaginary world of "usage" of the end result.
- Imagine how it should work.
- Start very quickly to implement features.
- Review 1, 2, and 3, as you regularly cycle through them, again, again, and again!
I use the word imagine twice above. For a few reasons...
People are constantly asking me "how do you know?", with regards to client's requirements, technology, design, approach, etc. The reality is that I do not completely know: I know much, I have done much, written hundreds and hundreds of thousands of lines of software. Yet when something is new, no one knows fully how things will look in the end. The reality is the newer it is, the less you know. And... the more you think you know, the more you are fooling yourself. However, just like with poker, the optimal approach is to imagine much and often, and to work as hard as possible to build and maintain a mindful view of "new usage" and "new functioning technology".
The more experience, the better! As your imagination is only as good as the real details it contains. I have tons of real-life learning that I use for this higher-order FP in python. I mention here a few of them:
- Lazy software design are easier express in code.
- The most flexible design, is the code that does nothing but accumulates lazily what it could do, until finally because output is expected, it works backwards from output expectations to pull out the desired output.
- Multi-stack semantics is perfectly normal.
- For example, in the project's above monadic code, the free monads have "their" variables, "normal" Python has its variables, and these are carefully kept separate.
- Multiple flows of causality exist in the real world, stacks of various semantics is the only cheap way to capture these cleanly in software.
- For every Ying, there is a Yang.
- If there is more, there is also less; If there are variables, there are constraints, etc.
- Structure is more important than types.
- I started in functional programming without the types. Then I embraced types. And yet to understand that the sweet spot is somewhere in between. The reality is that it is much easier to use code to constrain software "just a right level" than to use types.
- Math is the most powerful structure.
- Think geometry, topology, and dualities!
All original content copyright James Litsios, 2024.
No comments:
Post a Comment