Skip to content

Instantly share code, notes, and snippets.

@glguy
glguy / Each.hs
Created February 24, 2014 18:48
Stand-alone implementation of the automatic Each instance generation
{-# LANGUAGE TemplateHaskell #-}
module Each (makeEachInstance) where
import Control.Applicative (Applicative, (<*>), (<$>), pure)
import Control.Lens (Each(each), _2, folded, lengthOf, to, toListOf, view)
import Control.Monad (replicateM)
import Data.Map (Map, fromList)
import Data.Traversable (sequenceA)
import Language.Haskell.TH.Lens (HasTypeVars, conFields, name, substTypeVars, typeVars)