Popularity
2.4
Declining
Activity
0.0
Stable
6
2
0

Monthly Downloads: 4
Programming language: Haskell
License: BSD 3-clause "New" or "Revised" License
Tags: Data     Lens    
Latest version: v0.1.0.0

lens-th-rewrite alternatives and similar packages

Based on the "lens" category.
Alternatively, view lens-th-rewrite alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of lens-th-rewrite or a related project?

Add another 'lens' Package

README

lens-th-rewrite

A GHC plugin that rewrites TH splices into regular Haskell functions.

Usage

build-depends: lens-th-rewrite
ghc-options: -fplugin=GHC.Plugin.LensThRewrite

Operation

import Control.Lens

data Person
  = Person
  { _name :: String
  , _age :: Int
  } deriving (Show, Eq)

$(makeLenses ''Person)

becomes

import Control.Lens

data Person
  = Person
  { _name :: String
  , _age :: Int
  } deriving (Show, Eq)

age :: Lens' Person Int
age = lens _age $ \record field -> record { _age = field }

name :: Lens' Person String
name = lens _name $ \record field -> record { _name = field }

Why

Cross-compilation of Haskell code requires TH splices to be executed on the target machine, as opposed to the host. This can be a non-starter for many projects.

Limitations

Only makeLenses is supported. Also, you must define your data type in the same module makeLenses is used.

Preprocessor

It is possible to use the executable bundled with this library as a pre-processor.

Add {-# options_ghc -F -pgmF=lens-th-rewrite-pp #-}

Long term

GHC should split up Template Haskell into pure and impure variants. Allowing pure TH code to be executed on the host, and impure on the target.