-- | For deriving equations in examples.
module Theory.Drasil.Components.Derivation (
  -- * Types
  Derivation(..),
  -- * Typeclasses
  MayHaveDerivation(..),
  -- * Constructors
  mkDeriv, mkDerivName, mkDerivNoHeader
) where

import Control.Lens (Lens')

import Language.Drasil (Sentence(EmptyS, S), (+:))

-- * Type

-- | Derivations are an ordered list of sentences and expressions.
-- They are rendered in order as paragraphs and equation blocks to display
-- the derivation.
data Derivation = Derivation Sentence [Sentence]

-- * Class

-- | A class that might have a 'Derivation'.
class MayHaveDerivation c where
  -- | Provides a 'Lens' to a possible derivation.
  derivations :: Lens' c (Maybe Derivation)

-- * Functions

-- | Smart constructor for creating a 'Derivation'.
mkDeriv :: Sentence -> [Sentence] -> Derivation
mkDeriv :: Sentence -> [Sentence] -> Derivation
mkDeriv = Sentence -> [Sentence] -> Derivation
Derivation

-- | Similar to 'mkDeriv', but prepends "Detailed derivation of" to the header.
mkDerivName :: Sentence -> [Sentence] -> Derivation
mkDerivName :: Sentence -> [Sentence] -> Derivation
mkDerivName Sentence
s = Sentence -> [Sentence] -> Derivation
Derivation (String -> Sentence
S String
"Detailed derivation of" Sentence -> Sentence -> Sentence
+: Sentence
s)

-- | Similar to 'mkDeriv', but without a header 'Sentence'.
mkDerivNoHeader :: [Sentence] -> Derivation
mkDerivNoHeader :: [Sentence] -> Derivation
mkDerivNoHeader = Sentence -> [Sentence] -> Derivation
Derivation Sentence
EmptyS