{-# LANGUAGE TemplateHaskell #-}
-- | Defines chunk types for use in code generation.
module Drasil.Code.CodeVar where

import Data.Char (isSpace)
import Control.Lens ((^.), view, makeLenses, Lens')

import Drasil.Code.Classes (Callable)
import Drasil.Code.CodeExpr.Lang (CodeExpr)
import Drasil.Database.UID (HasUID(uid), (+++))

import Language.Drasil.Classes (CommonIdea(abrv), Quantity, Idea(getA), NamedIdea(..), Definition (defn), ConceptDomain (cdom))
import Language.Drasil.Space (HasSpace(..), Space(..))
import Language.Drasil.Symbol (HasSymbol(symbol))
import Language.Drasil.Chunk.UnitDefn (MayHaveUnit(getUnit))
import Language.Drasil.Stages (Stage(..))

import Utils.Drasil (toPlainName)
import Language.Drasil.Chunk.DefinedQuantity (DefinedQuantityDict, implVarAU')
-- not using lenses for now
-- | A 'CodeIdea' must include some code and its name. 
class CodeIdea c where
  -- | Name of the idea.
  codeName  :: c -> String
  -- | Code chunk associated with the idea.
  codeChunk :: c -> CodeChunk

-- | A 'DefiningCodeExpr' must have it's underlying chunk 
--   defined in the CodeExpr language.
class CodeIdea c => DefiningCodeExpr c where
  codeExpr  :: Lens' c CodeExpr

-- | Convert an abbreviation into one deemed 'code-friendly', removing spaces,
--   and replacing special characters with underscores.
--
--   FIXME: This should NOT be treated as a 'getter', but something we cache
--   local to something that has a 'program name'.
programName :: CommonIdea c => c -> String
programName :: forall c. CommonIdea c => c -> String
programName = String -> String
toPlainName (String -> String) -> (c -> String) -> c -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isSpace) (String -> String) -> (c -> String) -> c -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> String
forall c. CommonIdea c => c -> String
abrv

-- | Used when a function name needs to be distinguishable from a variable name.
funcPrefix :: String
funcPrefix :: String
funcPrefix = String
"func_"
 
-- | Details if a piece of code is meant to be a variable or a function.
data VarOrFunc = Var | Func

-- | Basic chunk representation in the code generation context.
-- Contains a DefinedQuantityDict and the kind of code (variable or function).
data CodeChunk = CodeC { CodeChunk -> DefinedQuantityDict
_qc  :: DefinedQuantityDict
                       , CodeChunk -> VarOrFunc
kind :: VarOrFunc  -- TODO: Jason: Once we have function spaces, I believe we won't need to store this
                       }
makeLenses ''CodeChunk

-- | Finds the 'UID' of the 'DefinedQuantityDict' used to make the 'CodeChunk'.
instance HasUID        CodeChunk where uid :: Getter CodeChunk UID
uid = (DefinedQuantityDict -> f DefinedQuantityDict)
-> CodeChunk -> f CodeChunk
Lens' CodeChunk DefinedQuantityDict
qc ((DefinedQuantityDict -> f DefinedQuantityDict)
 -> CodeChunk -> f CodeChunk)
-> ((UID -> f UID) -> DefinedQuantityDict -> f DefinedQuantityDict)
-> (UID -> f UID)
-> CodeChunk
-> f CodeChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID -> f UID) -> DefinedQuantityDict -> f DefinedQuantityDict
forall c. HasUID c => Getter c UID
Getter DefinedQuantityDict UID
uid
-- | Finds the term ('NP') of the 'DefinedQuantityDict' used to make the 'CodeChunk'.
instance NamedIdea     CodeChunk where term :: Lens' CodeChunk NP
term = (DefinedQuantityDict -> f DefinedQuantityDict)
-> CodeChunk -> f CodeChunk
Lens' CodeChunk DefinedQuantityDict
qc ((DefinedQuantityDict -> f DefinedQuantityDict)
 -> CodeChunk -> f CodeChunk)
-> ((NP -> f NP) -> DefinedQuantityDict -> f DefinedQuantityDict)
-> (NP -> f NP)
-> CodeChunk
-> f CodeChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NP -> f NP) -> DefinedQuantityDict -> f DefinedQuantityDict
forall c. NamedIdea c => Lens' c NP
Lens' DefinedQuantityDict NP
term
-- | Finds the idea contained in the 'DefinedQuantityDict' used to make the 'CodeChunk'.
instance Idea          CodeChunk where getA :: CodeChunk -> Maybe String
getA = DefinedQuantityDict -> Maybe String
forall c. Idea c => c -> Maybe String
getA (DefinedQuantityDict -> Maybe String)
-> (CodeChunk -> DefinedQuantityDict) -> CodeChunk -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting DefinedQuantityDict CodeChunk DefinedQuantityDict
-> CodeChunk -> DefinedQuantityDict
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting DefinedQuantityDict CodeChunk DefinedQuantityDict
Lens' CodeChunk DefinedQuantityDict
qc
-- | Finds the Definition contained in the 'DefinedQuantityDict' used to make the CodeChunk
instance Definition    CodeChunk where defn :: Lens' CodeChunk Sentence
defn = (DefinedQuantityDict -> f DefinedQuantityDict)
-> CodeChunk -> f CodeChunk
Lens' CodeChunk DefinedQuantityDict
qc ((DefinedQuantityDict -> f DefinedQuantityDict)
 -> CodeChunk -> f CodeChunk)
-> ((Sentence -> f Sentence)
    -> DefinedQuantityDict -> f DefinedQuantityDict)
-> (Sentence -> f Sentence)
-> CodeChunk
-> f CodeChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Sentence -> f Sentence)
-> DefinedQuantityDict -> f DefinedQuantityDict
forall c. Definition c => Lens' c Sentence
Lens' DefinedQuantityDict Sentence
defn

instance ConceptDomain CodeChunk where cdom :: CodeChunk -> [UID]
cdom = DefinedQuantityDict -> [UID]
forall c. ConceptDomain c => c -> [UID]
cdom (DefinedQuantityDict -> [UID])
-> (CodeChunk -> DefinedQuantityDict) -> CodeChunk -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting DefinedQuantityDict CodeChunk DefinedQuantityDict
-> CodeChunk -> DefinedQuantityDict
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting DefinedQuantityDict CodeChunk DefinedQuantityDict
Lens' CodeChunk DefinedQuantityDict
qc
-- | Finds the 'Space' of the 'DefinedQuantityDict' used to make the 'CodeChunk'.
instance HasSpace      CodeChunk where typ :: Getter CodeChunk Space
typ = (DefinedQuantityDict -> f DefinedQuantityDict)
-> CodeChunk -> f CodeChunk
Lens' CodeChunk DefinedQuantityDict
qc ((DefinedQuantityDict -> f DefinedQuantityDict)
 -> CodeChunk -> f CodeChunk)
-> ((Space -> f Space)
    -> DefinedQuantityDict -> f DefinedQuantityDict)
-> (Space -> f Space)
-> CodeChunk
-> f CodeChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Space -> f Space) -> DefinedQuantityDict -> f DefinedQuantityDict
forall c. HasSpace c => Getter c Space
Getter DefinedQuantityDict Space
typ
-- | Finds the 'Stage' dependent 'Symbol' of the 'DefinedQuantityDict' used to make the 'CodeChunk'.
instance HasSymbol     CodeChunk where symbol :: CodeChunk -> Stage -> Symbol
symbol = DefinedQuantityDict -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol (DefinedQuantityDict -> Stage -> Symbol)
-> (CodeChunk -> DefinedQuantityDict)
-> CodeChunk
-> Stage
-> Symbol
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting DefinedQuantityDict CodeChunk DefinedQuantityDict
-> CodeChunk -> DefinedQuantityDict
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting DefinedQuantityDict CodeChunk DefinedQuantityDict
Lens' CodeChunk DefinedQuantityDict
qc
-- | 'CodeChunk's have a 'Quantity'.
instance Quantity      CodeChunk
-- | Equal if 'UID's are equal.
instance Eq            CodeChunk where CodeChunk
c1 == :: CodeChunk -> CodeChunk -> Bool
== CodeChunk
c2 = (CodeChunk
c1 CodeChunk -> Getting UID CodeChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID CodeChunk UID
forall c. HasUID c => Getter c UID
Getter CodeChunk UID
uid) UID -> UID -> Bool
forall a. Eq a => a -> a -> Bool
== (CodeChunk
c2 CodeChunk -> Getting UID CodeChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID CodeChunk UID
forall c. HasUID c => Getter c UID
Getter CodeChunk UID
uid)
-- | Finds the units of the 'DefinedQuantityDict' used to make the 'CodeChunk'.
instance MayHaveUnit   CodeChunk where getUnit :: CodeChunk -> Maybe UnitDefn
getUnit = DefinedQuantityDict -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit (DefinedQuantityDict -> Maybe UnitDefn)
-> (CodeChunk -> DefinedQuantityDict)
-> CodeChunk
-> Maybe UnitDefn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting DefinedQuantityDict CodeChunk DefinedQuantityDict
-> CodeChunk -> DefinedQuantityDict
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting DefinedQuantityDict CodeChunk DefinedQuantityDict
Lens' CodeChunk DefinedQuantityDict
qc

-- | Chunk representing a variable. The @obv@ field represents the object containing 
-- this variable, if it is an object field.
data CodeVarChunk = CodeVC {CodeVarChunk -> CodeChunk
_ccv :: CodeChunk,
                            CodeVarChunk -> Maybe CodeChunk
_obv :: Maybe CodeChunk}
makeLenses ''CodeVarChunk

-- | Finds the 'UID' of the 'CodeChunk' used to make the 'CodeVarChunk'.
instance HasUID        CodeVarChunk where uid :: Getter CodeVarChunk UID
uid = (CodeChunk -> f CodeChunk) -> CodeVarChunk -> f CodeVarChunk
Lens' CodeVarChunk CodeChunk
ccv ((CodeChunk -> f CodeChunk) -> CodeVarChunk -> f CodeVarChunk)
-> ((UID -> f UID) -> CodeChunk -> f CodeChunk)
-> (UID -> f UID)
-> CodeVarChunk
-> f CodeVarChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID -> f UID) -> CodeChunk -> f CodeChunk
forall c. HasUID c => Getter c UID
Getter CodeChunk UID
uid
-- | Finds the term ('NP') of the 'CodeChunk' used to make the 'CodeVarChunk'.
instance NamedIdea     CodeVarChunk where term :: Lens' CodeVarChunk NP
term = (CodeChunk -> f CodeChunk) -> CodeVarChunk -> f CodeVarChunk
Lens' CodeVarChunk CodeChunk
ccv ((CodeChunk -> f CodeChunk) -> CodeVarChunk -> f CodeVarChunk)
-> ((NP -> f NP) -> CodeChunk -> f CodeChunk)
-> (NP -> f NP)
-> CodeVarChunk
-> f CodeVarChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NP -> f NP) -> CodeChunk -> f CodeChunk
forall c. NamedIdea c => Lens' c NP
Lens' CodeChunk NP
term
-- | Finds the idea contained in the 'CodeChunk' used to make the 'CodeVarChunk'.
instance Idea          CodeVarChunk where getA :: CodeVarChunk -> Maybe String
getA = CodeChunk -> Maybe String
forall c. Idea c => c -> Maybe String
getA (CodeChunk -> Maybe String)
-> (CodeVarChunk -> CodeChunk) -> CodeVarChunk -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting CodeChunk CodeVarChunk CodeChunk
-> CodeVarChunk -> CodeChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting CodeChunk CodeVarChunk CodeChunk
Lens' CodeVarChunk CodeChunk
ccv

instance Definition    CodeVarChunk where defn :: Lens' CodeVarChunk Sentence
defn = (CodeChunk -> f CodeChunk) -> CodeVarChunk -> f CodeVarChunk
Lens' CodeVarChunk CodeChunk
ccv ((CodeChunk -> f CodeChunk) -> CodeVarChunk -> f CodeVarChunk)
-> ((Sentence -> f Sentence) -> CodeChunk -> f CodeChunk)
-> (Sentence -> f Sentence)
-> CodeVarChunk
-> f CodeVarChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Sentence -> f Sentence) -> CodeChunk -> f CodeChunk
forall c. Definition c => Lens' c Sentence
Lens' CodeChunk Sentence
defn

instance ConceptDomain CodeVarChunk where cdom :: CodeVarChunk -> [UID]
cdom = CodeChunk -> [UID]
forall c. ConceptDomain c => c -> [UID]
cdom (CodeChunk -> [UID])
-> (CodeVarChunk -> CodeChunk) -> CodeVarChunk -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting CodeChunk CodeVarChunk CodeChunk
-> CodeVarChunk -> CodeChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting CodeChunk CodeVarChunk CodeChunk
Lens' CodeVarChunk CodeChunk
ccv
-- | Finds the 'Space' of the 'CodeChunk' used to make the 'CodeVarChunk'.
instance HasSpace      CodeVarChunk where typ :: Getter CodeVarChunk Space
typ = (CodeChunk -> f CodeChunk) -> CodeVarChunk -> f CodeVarChunk
Lens' CodeVarChunk CodeChunk
ccv ((CodeChunk -> f CodeChunk) -> CodeVarChunk -> f CodeVarChunk)
-> ((Space -> f Space) -> CodeChunk -> f CodeChunk)
-> (Space -> f Space)
-> CodeVarChunk
-> f CodeVarChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Space -> f Space) -> CodeChunk -> f CodeChunk
forall c. HasSpace c => Getter c Space
Getter CodeChunk Space
typ
-- | Finds the 'Stage' dependent 'Symbol' of the 'CodeChunk' used to make the 'CodeVarChunk'.
instance HasSymbol     CodeVarChunk where symbol :: CodeVarChunk -> Stage -> Symbol
symbol = CodeChunk -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol (CodeChunk -> Stage -> Symbol)
-> (CodeVarChunk -> CodeChunk) -> CodeVarChunk -> Stage -> Symbol
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting CodeChunk CodeVarChunk CodeChunk
-> CodeVarChunk -> CodeChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting CodeChunk CodeVarChunk CodeChunk
Lens' CodeVarChunk CodeChunk
ccv
-- | 'CodeVarChunk's have a 'Quantity'.
instance Quantity      CodeVarChunk
-- | Equal if 'UID's are equal.
instance Eq            CodeVarChunk where CodeVarChunk
c1 == :: CodeVarChunk -> CodeVarChunk -> Bool
== CodeVarChunk
c2 = (CodeVarChunk
c1 CodeVarChunk -> Getting UID CodeVarChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID CodeVarChunk UID
forall c. HasUID c => Getter c UID
Getter CodeVarChunk UID
uid) UID -> UID -> Bool
forall a. Eq a => a -> a -> Bool
== (CodeVarChunk
c2 CodeVarChunk -> Getting UID CodeVarChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID CodeVarChunk UID
forall c. HasUID c => Getter c UID
Getter CodeVarChunk UID
uid)
-- | Finds the units of the 'CodeChunk' used to make the 'CodeVarChunk'.
instance MayHaveUnit   CodeVarChunk where getUnit :: CodeVarChunk -> Maybe UnitDefn
getUnit = CodeChunk -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit (CodeChunk -> Maybe UnitDefn)
-> (CodeVarChunk -> CodeChunk) -> CodeVarChunk -> Maybe UnitDefn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting CodeChunk CodeVarChunk CodeChunk
-> CodeVarChunk -> CodeChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting CodeChunk CodeVarChunk CodeChunk
Lens' CodeVarChunk CodeChunk
ccv

-- | Chunk representing a function.
newtype CodeFuncChunk = CodeFC {CodeFuncChunk -> CodeChunk
_ccf :: CodeChunk}
makeLenses ''CodeFuncChunk

-- | Finds the 'UID' of the 'CodeChunk' used to make the 'CodeFuncChunk'.
instance HasUID        CodeFuncChunk where uid :: Getter CodeFuncChunk UID
uid = (CodeChunk -> f CodeChunk) -> CodeFuncChunk -> f CodeFuncChunk
Iso' CodeFuncChunk CodeChunk
ccf ((CodeChunk -> f CodeChunk) -> CodeFuncChunk -> f CodeFuncChunk)
-> ((UID -> f UID) -> CodeChunk -> f CodeChunk)
-> (UID -> f UID)
-> CodeFuncChunk
-> f CodeFuncChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID -> f UID) -> CodeChunk -> f CodeChunk
forall c. HasUID c => Getter c UID
Getter CodeChunk UID
uid
-- | Finds the term ('NP') of the 'CodeChunk' used to make the 'CodeFuncChunk'.
instance NamedIdea     CodeFuncChunk where term :: Lens' CodeFuncChunk NP
term = (CodeChunk -> f CodeChunk) -> CodeFuncChunk -> f CodeFuncChunk
Iso' CodeFuncChunk CodeChunk
ccf ((CodeChunk -> f CodeChunk) -> CodeFuncChunk -> f CodeFuncChunk)
-> ((NP -> f NP) -> CodeChunk -> f CodeChunk)
-> (NP -> f NP)
-> CodeFuncChunk
-> f CodeFuncChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NP -> f NP) -> CodeChunk -> f CodeChunk
forall c. NamedIdea c => Lens' c NP
Lens' CodeChunk NP
term
-- | Finds the idea contained in the 'CodeChunk' used to make the 'CodeFuncChunk'.
instance Idea          CodeFuncChunk where getA :: CodeFuncChunk -> Maybe String
getA = CodeChunk -> Maybe String
forall c. Idea c => c -> Maybe String
getA (CodeChunk -> Maybe String)
-> (CodeFuncChunk -> CodeChunk) -> CodeFuncChunk -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting CodeChunk CodeFuncChunk CodeChunk
-> CodeFuncChunk -> CodeChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting CodeChunk CodeFuncChunk CodeChunk
Iso' CodeFuncChunk CodeChunk
ccf
-- | Finds the Definition of the 'CodeChunk' used to make the 'CodeFuncChunk'
instance Definition    CodeFuncChunk where defn :: Lens' CodeFuncChunk Sentence
defn = (CodeChunk -> f CodeChunk) -> CodeFuncChunk -> f CodeFuncChunk
Iso' CodeFuncChunk CodeChunk
ccf ((CodeChunk -> f CodeChunk) -> CodeFuncChunk -> f CodeFuncChunk)
-> ((Sentence -> f Sentence) -> CodeChunk -> f CodeChunk)
-> (Sentence -> f Sentence)
-> CodeFuncChunk
-> f CodeFuncChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Sentence -> f Sentence) -> CodeChunk -> f CodeChunk
forall c. Definition c => Lens' c Sentence
Lens' CodeChunk Sentence
defn
-- | Finds the ConceptDomain of the 'CodeChunk' used to make the 'CodeFuncChunk'
instance ConceptDomain CodeFuncChunk where cdom :: CodeFuncChunk -> [UID]
cdom = CodeChunk -> [UID]
forall c. ConceptDomain c => c -> [UID]
cdom (CodeChunk -> [UID])
-> (CodeFuncChunk -> CodeChunk) -> CodeFuncChunk -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting CodeChunk CodeFuncChunk CodeChunk
-> CodeFuncChunk -> CodeChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting CodeChunk CodeFuncChunk CodeChunk
Iso' CodeFuncChunk CodeChunk
ccf
-- | Finds the 'Space' of the 'CodeChunk' used to make the 'CodeFuncChunk'.
instance HasSpace      CodeFuncChunk where typ :: Getter CodeFuncChunk Space
typ = (CodeChunk -> f CodeChunk) -> CodeFuncChunk -> f CodeFuncChunk
Iso' CodeFuncChunk CodeChunk
ccf ((CodeChunk -> f CodeChunk) -> CodeFuncChunk -> f CodeFuncChunk)
-> ((Space -> f Space) -> CodeChunk -> f CodeChunk)
-> (Space -> f Space)
-> CodeFuncChunk
-> f CodeFuncChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Space -> f Space) -> CodeChunk -> f CodeChunk
forall c. HasSpace c => Getter c Space
Getter CodeChunk Space
typ
-- | Finds the 'Stage' dependent 'Symbol' of the 'CodeChunk' used to make the 'CodeFuncChunk'.
instance HasSymbol     CodeFuncChunk where symbol :: CodeFuncChunk -> Stage -> Symbol
symbol = CodeChunk -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol (CodeChunk -> Stage -> Symbol)
-> (CodeFuncChunk -> CodeChunk) -> CodeFuncChunk -> Stage -> Symbol
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting CodeChunk CodeFuncChunk CodeChunk
-> CodeFuncChunk -> CodeChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting CodeChunk CodeFuncChunk CodeChunk
Iso' CodeFuncChunk CodeChunk
ccf
-- | 'CodeFuncChunk's have a 'Quantity'.
instance Quantity      CodeFuncChunk
-- | Functions are Callable.
instance Callable      CodeFuncChunk
-- | Equal if 'UID's are equal.
instance Eq            CodeFuncChunk where CodeFuncChunk
c1 == :: CodeFuncChunk -> CodeFuncChunk -> Bool
== CodeFuncChunk
c2 = (CodeFuncChunk
c1 CodeFuncChunk -> Getting UID CodeFuncChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID CodeFuncChunk UID
forall c. HasUID c => Getter c UID
Getter CodeFuncChunk UID
uid) UID -> UID -> Bool
forall a. Eq a => a -> a -> Bool
== (CodeFuncChunk
c2 CodeFuncChunk -> Getting UID CodeFuncChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID CodeFuncChunk UID
forall c. HasUID c => Getter c UID
Getter CodeFuncChunk UID
uid)
-- | Finds the units of the 'CodeChunk' used to make the 'CodeFuncChunk'.
instance MayHaveUnit   CodeFuncChunk where getUnit :: CodeFuncChunk -> Maybe UnitDefn
getUnit = CodeChunk -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit (CodeChunk -> Maybe UnitDefn)
-> (CodeFuncChunk -> CodeChunk) -> CodeFuncChunk -> Maybe UnitDefn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting CodeChunk CodeFuncChunk CodeChunk
-> CodeFuncChunk -> CodeChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting CodeChunk CodeFuncChunk CodeChunk
Iso' CodeFuncChunk CodeChunk
ccf

-- FIXME: use show for the UID here? Perhaps need a different implVar function for UIDs
-- Changes a 'CodeVarChunk'\'s space from 'Vect' to 'Array'.
listToArray :: CodeVarChunk -> CodeVarChunk
listToArray :: CodeVarChunk -> CodeVarChunk
listToArray CodeVarChunk
c = Space -> CodeVarChunk
newSpc (CodeVarChunk
c CodeVarChunk -> Getting Space CodeVarChunk Space -> Space
forall s a. s -> Getting a s a -> a
^. Getting Space CodeVarChunk Space
forall c. HasSpace c => Getter c Space
Getter CodeVarChunk Space
typ)
  where newSpc :: Space -> CodeVarChunk
newSpc (Vect Space
t) = CodeChunk -> Maybe CodeChunk -> CodeVarChunk
CodeVC (DefinedQuantityDict -> VarOrFunc -> CodeChunk
CodeC (String
-> NP
-> Sentence
-> Maybe String
-> Space
-> Symbol
-> Maybe UnitDefn
-> DefinedQuantityDict
implVarAU' (UID -> String
forall a. Show a => a -> String
show (UID -> String) -> UID -> String
forall a b. (a -> b) -> a -> b
$ CodeVarChunk
c CodeVarChunk -> String -> UID
forall a. HasUID a => a -> String -> UID
+++ String
"_array")
          (CodeVarChunk
c CodeVarChunk -> Getting NP CodeVarChunk NP -> NP
forall s a. s -> Getting a s a -> a
^. Getting NP CodeVarChunk NP
forall c. NamedIdea c => Lens' c NP
Lens' CodeVarChunk NP
term) (CodeVarChunk
c CodeVarChunk -> Getting Sentence CodeVarChunk Sentence -> Sentence
forall s a. s -> Getting a s a -> a
^. Getting Sentence CodeVarChunk Sentence
forall c. Definition c => Lens' c Sentence
Lens' CodeVarChunk Sentence
defn) (CodeVarChunk -> Maybe String
forall c. Idea c => c -> Maybe String
getA CodeVarChunk
c)
          (Space -> Space
Array Space
t) (CodeVarChunk -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol CodeVarChunk
c Stage
Implementation) (CodeVarChunk -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit CodeVarChunk
c)) VarOrFunc
Var) (CodeVarChunk
c CodeVarChunk
-> Getting (Maybe CodeChunk) CodeVarChunk (Maybe CodeChunk)
-> Maybe CodeChunk
forall s a. s -> Getting a s a -> a
^. Getting (Maybe CodeChunk) CodeVarChunk (Maybe CodeChunk)
Lens' CodeVarChunk (Maybe CodeChunk)
obv)
        newSpc Space
_ = CodeVarChunk
c