All Projects → kcsongor → Generic Lens

kcsongor / Generic Lens

Licence: bsd-3-clause
Generically derive traversals, lenses, and prisms.

Programming Languages

haskell
3896 projects
optics
23 projects

Projects that are alternatives of or similar to Generic Lens

concave
🧐 Lens-like state management (for React).
Stars: ✭ 13 (-96.74%)
Mutual labels:  lenses
GENERIS
Versatile Go code generator.
Stars: ✭ 32 (-91.98%)
Mutual labels:  generics
Typed
Improvements to PHP's type system in userland: generics, typed lists, tuples and structs
Stars: ✭ 322 (-19.3%)
Mutual labels:  generics
lenses-jdbc
Lenses.io JDBC driver for Apache Kafka
Stars: ✭ 20 (-94.99%)
Mutual labels:  lenses
go2linq
Generic Go implementation of .NET's LINQ to Objects.
Stars: ✭ 41 (-89.72%)
Mutual labels:  generics
purescript-barlow-lens
Increase your magnification 🔭 and zoom deep into a record.
Stars: ✭ 32 (-91.98%)
Mutual labels:  lenses
rueidis
A Fast Golang Redis RESP3 client that supports Client Side Caching, Auto Pipelining, Generics OM, RedisJSON, RedisBloom, RediSearch, RedisAI, RedisGears, etc.
Stars: ✭ 422 (+5.76%)
Mutual labels:  generics
Language Ext
C# functional language extensions - a base class library for functional programming
Stars: ✭ 3,964 (+893.48%)
Mutual labels:  lenses
lru
LRU cache using go generics
Stars: ✭ 108 (-72.93%)
Mutual labels:  generics
GenericTableViewController
An example of Generic UITableViewController implementation
Stars: ✭ 31 (-92.23%)
Mutual labels:  generics
go-inline
Generic Data Structures/Algorithms in golang.
Stars: ✭ 52 (-86.97%)
Mutual labels:  generics
optics.js
🔭 Lenses, Prisms and Traversals in JavaScript!
Stars: ✭ 46 (-88.47%)
Mutual labels:  lenses
generics
No description or website provided.
Stars: ✭ 25 (-93.73%)
Mutual labels:  generics
genx
GenX: Generics For Go, Yet Again.
Stars: ✭ 37 (-90.73%)
Mutual labels:  generics
Use Profunctor State
React Hook for state management with profunctor lenses
Stars: ✭ 331 (-17.04%)
Mutual labels:  lenses
go-callbag
golang implementation of Callbag
Stars: ✭ 19 (-95.24%)
Mutual labels:  generics
lenses-go
Lenses.io CLI (command-line interface)
Stars: ✭ 34 (-91.48%)
Mutual labels:  lenses
Dontfeartheprofunctoroptics
Don't Fear the Profunctor Optics!
Stars: ✭ 367 (-8.02%)
Mutual labels:  lenses
Observable
The easiest way to observe values in Swift.
Stars: ✭ 346 (-13.28%)
Mutual labels:  generics
core
The XP Framework is an all-purpose, object oriented PHP framework.
Stars: ✭ 13 (-96.74%)
Mutual labels:  generics

generic-lens

Build Status Hackage

Generically derive isos, traversals, lenses and prisms.

This library uses GHC.Generics to derive efficient optics (traversals, lenses and prisms) for algebraic data types in a type-directed way, with a focus on good type inference and error messages when possible.

The library is described in the paper:

Csongor Kiss, Matthew Pickering, and Nicolas Wu. 2018. Generic deriving of generic traversals. Proc. ACM Program. Lang. 2, ICFP, Article 85 (July 2018), 30 pages. DOI: https://doi.org/10.1145/3236780

Package structure

  • generic-lens: Generic derivation of van Laarhoven optics, compatible with the lens library. There is no dependency on lens, however, and other mainstream lens libraries sharing the same interface are supported just as well.

  • generic-optics: Generic derivation of optics compatible with the optics library.

  • generic-lens-core: The bulk of the work happens here. Indeed, generic-lens and generic-optics are just thin layers on top of generic-lens-core.

generic-lens are generic-optics are designed to be drop-in replacements for each other. This means that they share the same module names. If, for whatever reason, they are both used in the same project, the module imports can be disambiguated using the -XPackageImports extension.

Getting started

A typical module using generic-lens or generic-optics will usually have the following extensions turned on:

{-# LANGUAGE AllowAmbiguousTypes       #-}
{-# LANGUAGE DataKinds                 #-}
{-# LANGUAGE DeriveGeneric             #-}
{-# LANGUAGE DuplicateRecordFields     #-}
{-# LANGUAGE FlexibleContexts          #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE TypeApplications          #-}

In particular, NoMonomorphismRestriction can be helpful as it enables proper type inference for top-level functions without a type signature.

For usage examples, visit the documentation on hackage, or have a look in the examples and tests folders in generic-lens or generic-optics.

Performance

The runtime characteristics of the derived optics is in most cases identical at -O1, in some cases only slightly slower than the hand-written version. This is thanks to GHC's optimiser eliminating the generic overhead.

The inspection-testing library is used to ensure (see here) that everything gets inlined away.

There is also a benchmark suite with larger, real-world examples.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].