Conversation
Miso applications consist of very simple state management in a State monad. Given the shortcomings of Haskell records it is incumbent upon us to provide users with a simple way to get / set their records. This module is meant to make miso more "batteries-included" and reduce dependency footprint, along with exposing new users to lensing, but with a seatbelt. This lens formulation is very simple (much simpler than microlens and the original 'lens' library). It exposes an identical interface wih fixity parity of existing combinators in microlens. Some combinators have been omitted for brevity, others because of conflicts (e.g. @view@ is omitted because of conflicts, and @effect@ only operates in 'MonadState'). We are attempting to make an identical interface (so as not to confuse LLMs) and to make it easy for users to upgrade to more mature, sophisticated lens libraries at their leisure. - Update README.md and examples/simple/Main.hs to use Miso.Lens - Document combinators, smart constructors, haddockage
amenable -> conducive
Owner
Author
|
Will add ----------------------------------------------------------------------------
-- | Field class
class Field (name :: Symbol) record field | record name -> field where
field :: Proxy name -> Lens record field
default field
:: ( Generic record
, GField name record field (Rep record)
) => Proxy name -> Lens record field
field name = gField name (Proxy @(Rep record))
----------------------------------------------------------------------------
-- | Generic Field
class GField name record field rep | record name -> field where
gField :: Proxy name -> Proxy rep -> Lens record field |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🍜 Miso.Lens
Miso applications consist of very simple state management (using the
EffectStatemonad). Given the necessity (and convenience) of lenses defined in terms ofMonadState(.=,%=, etc.), the importance of state management in web / mobile applications, the shortcomings of vanilla Haskell records in regards to updating deeply nested state, and the dependency footprint of existinglenslibraries, we believe it is a good idea to include our ownMiso.Lensabstraction that is lightweight, powerful and accessible for new users.The documentation will describe the motivation, formulation and usage of
Lensin terms of buildingmisoapplications (specifically when using theupdatefunction).This module is meant to make
misomore "batteries-included" and reduce dependency footprint, along with exposing new users to lensing, but with a seatbelt. This lens formulation is very simple (simpler thanmicrolensand the originallenslibrary). It exposes an identical interface (and keeps fixity parity) of existing combinators inlens.This module is not meant to "compete" with other
lenslibraries likelensandmicrolensthat are based on Van Laarhoven formulations and are much more flexible, and have different project goals. With that said, for user's writingmisoapplications, this module should meet at least 98% of your needs regarding state management ofmodelin your applications.Some combinators have been elided for brevity, others because of conflicts (e.g.
viewis omitted because of conflicts withApp { view }, and is also irrelevant since it's defined in terms ofMonadReader-- we only useMonadStateforEffect). We also believe exposing an identical interface to existinglenslibraries will allow LLMs to produce identical code, and it will make it easier for new users to transition to more mature lens libraries if and when they decide.Since most
misoapplications are cross-compiled to Web Asembly and JavaScript it is important to have a small dependency footprint. If a user wants something more flexible then it will come at the cost of payload size in their application. Exposing aMiso.Lensprovides a good power-to-weight ratio and optimizes for minimal payload.Convenience and simplicity, this is a simpler formulation, and its semantically equivalent. It has a smaller dependency footprint, it's also more approachable for beginners (which is a goal of the project, to learn Haskell through web development). It is also extensible (you can define your own
Lenscombinators simply since we re-export everything).This formulation might be less efficient when it comes to updating very large and deeply nested records when compared to an existing lens library, but this needs to be benchmarked on JS / WASM platforms. Miso's new
Componentfeature also amortizes this cost, since nowModeldo not need to be deeply nested, but are locally-stateful and isolated, and updated independently in separate threads.Miso.Lensis also not as flexible and is not meant to be a general purpose library, but only a more powerful way to manage state inmisoapplications (while maintaining API parity with the ecosystem for the subset of lens combinators it exposes). TheMonadStatecombinators for lenses are very convenient and powerful andmisowould like to make them first class and exposed by default fromimport Miso.Lens.Miso.LensGenericcombinatorfield(might be best for follow-up PR)