GitHub

Control.Configurable

Declare types as Configurable and then specialize them all in one place. For example

data A = A VarA deriving (Show)
data B = B VarB deriving (Show)
data VarA = VarA Int deriving (Typeable, Show)
data VarB = VarB Int deriving (Typeable, Show)
instance Monoid VarA where
  mempty      = VarA 0
  mappend v _ = v
instance Monoid VarB where
  mempty      = VarB 0
  mappend v _ = v
instance Configurable VarA
instance Configurable VarB
instance ConfiguredBy A VarA
instance ConfiguredBy B VarB
c = unsafeDoConfig [confs (undefined :: A),
                    confs (undefined :: B)]
    $ toConfigure (\(VarA n) -> VarA (n+1))
    . toConfigure (\(VarB n) -> VarB (n-1))
fmap A (getConfig c)
> Just (A (VarA 1))
fmap B (getConfig c)
> Just (A (VarA (-1)))

Read the original on github.com ↗