Functional PHP
effectful
Functional PHP | effectful | |
---|---|---|
6 | 21 | |
1,964 | 334 | |
- | 4.5% | |
0.0 | 8.0 | |
3 months ago | 5 days ago | |
PHP | Haskell | |
MIT License | BSD 3-clause "New" or "Revised" License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
Functional PHP
-
I asked GPT-4 what top 5 improvements it would make to the PHP language to make it more competitive
A lot of this can be handled in userland. For examples libraries such as https://github.com/lstrojny/functional-php/blob/main/docs/functional-php.md handle a lot of this.
-
How do I become a better dev?
I’m also trying to use all of these at least once or twice to have these tools under my belt should I want them https://github.com/lstrojny/functional-php
- How to Lose Functional Programming at Work
-
PHP 8.2 Released
https://github.com/lstrojny/functional-php
The no-brainers to me are the missing array_some()/array_any() array_every()/array_all() and an array_search() that takes a predicate an iterable. I do these now in userland but an optimized native version would be nice.
-
PHP Map - PHP arrays and collections made easy
Functional PHP, which provides a lot of similar functionality, also uses pluck and has for many years https://github.com/lstrojny/functional-php
-
Simple Composition with Array.Reduce
While looking at functional-php, I saw a pretty neat way of doing composition with an array_reduce method, and wanted to recreate it in JavaScript. There are plenty of libraries that implement this (and do so more effectively), but it's pretty fun knowing that you can get this functionality with a couple lines of plain JavaScript.
effectful
-
Haskell in Production: Standard Chartered
Also a much simpler alternative in my opinion to monad transformers is effectful:
https://github.com/haskell-effectful/effectful
Here's a talk on it:
https://www.youtube.com/watch?v=BUoYKBLOOrE
-
The "Services" design pattern
effectful got rid of all issues I listed (I expanded a little on it here).
-
effectful and polysemy users: How do you test? Any of "same as mtl", "novel ways enabled by effects", or "same but more efficiently because..."? Please share experiences
There is also a long document on Issues with the Transformer/mtl library.
-
Haskell ecosystem questions.
cats-effects -> https://github.com/haskell-effectful/effectful
-
How to Handle My Horrible Haskell: Global State
I think ReaderT over IO or an algebraic effect system that uses it under the hood like effectful is the way to go. However, you mentioned redux, so perhaps you'd be comfortable with organizing things using TEA (the elm architecture)? You would have actions that different components listen to , and your async stuff could be handled using subscriptions.
-
Real world applications with tagless-final, ReaderT, and three-layers
API for basic usage is very similar, but things quickly go south once you want to use higher order effects (i.e. effects that make use of the m type parameter). A lot of things then become very hard to write due to complex types or outright impossible (this issue is a good example - a reasonable thing to do that is very straightforward to write with effectful, apparently impossible to do with polysemy).
-
How to Lose Functional Programming at Work
> Lets say you have a huge overly-convoluted Haskell program. Somewhere deep down a call hierachy of pure functions you need to print something to the console. That is not easy to refactor.
> Or vice-versa you have a huge convoluted program where everything happens inside an IO monad because at some point something is written to the console. Now you realize you dont need to write to the console.
These problems are essentially completely resolved these days by a modern effect system like effectful. Basically, they allow you to do arbitrary effects deep down a call stack with minimal plumbing (you still have adjust the types, as you should: that's the point of effect tracking!) and also to remove effects, so you can easily convert between pure code and "effectful code that just so happens to do no effects".
https://github.com/haskell-effectful/effectful
-
Published my first Haskell library on Hackage: xdg-basedir-compliant
Also note that Polysemy has some really bad performance characteristics. Don't know how much of a problem it could be at such a small scale, but if you need to use an effect system, maybe something faster like effectful would be a better choice.
-
Effectful | Paweł Szulc | Lambda Days 2022
See also https://github.com/haskell-effectful/effectful/issues/99.
-
Monad transformer libraries
FYI, transformers and mtl have several subtle traps. You can read about them here.
What are some alternatives?
Design Patterns PHP - sample code for several design patterns in PHP 8
godot-haskell - Haskell bindings for GdNative
PHP Option - Option Type for PHP
cleff - Fast and concise extensible effects
Pipeline - League\Pipeline
unliftio - The MonadUnliftIO typeclass for unlifting monads to IO
Iter - Iteration primitives using generators
ghc-proposals - Proposed compiler and language changes for GHC and GHC/Haskell
Monad PHP - A simple Monad library for PHP
hpqtypes-effectful - Effectful bindings for hpqtypes
Ruler - A simple stateless production rules engine for modern PHP
PolysemyCleanArchitecture - Showcasing how the Polysemy library can be used to implement a REST application conforming to the guidelines of the Clean Architecture model.