Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Describe types as configurable and then write specializers all in one place

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 src
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Configurable.cabal
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Setup.hs
README.md

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)))

Something went wrong with that request. Please try again.