-- | For deriving equations in examples.
module Language.Drasil.Derivation where

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

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