Popularity
2.1
Declining
Activity
0.0
Stable
1
2
2

Monthly Downloads: 5
Programming language: Haskell
License: BSD 3-clause "New" or "Revised" License
Tags: Control    
Latest version: v0.2.1.0

shared-fields alternatives and similar packages

Based on the "Control" category.
Alternatively, view shared-fields alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of shared-fields or a related project?

Add another 'Control' Package

README

shared-fields

view on hackage

A simple single-module library for creating lens field typeclasses in a way that allows them to be shared between modules.

By default, lens' makeFields creates a new class if it can't find a matching one in scope. This means that if you try to makeFields records in different modules without importing one module into the other, you'll get conflicting class definitions rather than a single lens which functions with both records.

module A where
data A = A { _aThing :: Bool }
  deriving (Show, Read, Eq)
makeFields ''A

module B where
data B = B { _bThing :: String }
   deriving (Show, Read, Eq)
makeFields ''B

module Main where
import A
import B
import Control.Lens

main = print $ A False ^. thing -- fails because there are two HasThing classes

If you use shared-fields, though:

module SharedFields where
generateField "Thing"

-- alternatively:
-- generateFields ["Thing"]

module A where
import SharedFields
data A = A { _aThing :: Bool }
  deriving (Show, Read, Eq)
makeFields ''A

module B where
import SharedFields
data B = B { _bThing :: String }
   deriving (Show, Read, Eq)
makeFields ''B

module Main where
import A
import B
import Control.Lens

main = print $ A False ^. thing -- works now because there's one consistent HasThing class!