verbosity-0.4.0.0: Simple enum that encodes application verbosity.

Copyright(c) 2015-2019 Peter Trško
LicenseBSD3
Maintainerpeter.trsko@gmail.com
Stabilityexperimental
PortabilityGHC specific language extensions.
Safe HaskellNone
LanguageHaskell2010

Data.Verbosity.Class

Contents

Description

Type class for accessing Verbosity.

Synopsis

GHC Generics Example

Lets define simple data type that looks something like:

data Config = Config
    { _appVerbosity :: Verbosity
    , ...
    }
  deriving (Generic, Show, ...)

Type class HasVerbosity uses generic-lens package and DefaultSignatures language extension so that we can define instance of HasVerbosity by simply stating:

instance HasVerbosity Config

With DerivingStrategies we can rewrite the above example as:

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}

import GHC.Generics (Generic)


data Config = Config
    { _appVerbosity :: Verbosity
    , ...
    }
  deriving stock (Generic, Show, ...)
  deriving anyclass (HasVerbosity)

Hand Written Instance Example

Lets define simple data type that looks something like:

data Config = Config
    { _appVerbosity :: Verbosity
    , ...
    }
  deriving (Show, ...)

Now we can define instance of HasVerbosity by hand:

instance HasVerbosity Config where
    verbosity f c@Config{_appVerbosity = a} =
        (\b -> c{_appVerbosity = b}) <$> f a

TemplateHaskell Example

Package lens has TemplateHaskell functions that can define lenses for you:

{-# LANGUAGE TemplateHaskell #-}

import Control.Lens.TH (makeLenses)

data Config = Config
    { _appVerbosity :: Verbosity
    , ...
    }
  deriving (Show, ...)

makeLenses ''Config

Now definition of HasVerbosity instance will look like:

instance HasVerbosity Config where
    verbosity = appVerbosity   -- Lens generated by makeLenses.

HasVerbosity Type Class

class HasVerbosity s where Source #

Minimal complete definition

Nothing

Methods

verbosity :: Functor f => (Verbosity -> f Verbosity) -> s -> f s Source #

Lens for accessing Verbosity embedded in the type s.

Default implementaton in terms of HasType added in version 0.3.0.0.

verbosity :: (HasType Verbosity s, Functor f) => (Verbosity -> f Verbosity) -> s -> f s Source #

Lens for accessing Verbosity embedded in the type s.

Default implementaton in terms of HasType added in version 0.3.0.0.

Instances
HasVerbosity Verbosity Source # 
Instance details

Defined in Data.Verbosity.Class

getVerbosity :: HasVerbosity s => s -> Verbosity Source #

Specialization of verbosity lens in to getter function.

setVerbosity :: HasVerbosity s => Verbosity -> s -> s Source #

Specialization of verbosity lens in to setter function.

modifyVerbosity :: HasVerbosity s => (Verbosity -> Verbosity) -> s -> s Source #

Specialization of verbosity lens in to modification function.

Verbosity Re-export