{-# LANGUAGE TemplateHaskell #-}
module Language.Drasil.Chunk.NamedIdea (
IdeaDict,
NamedIdea(..), Idea(..),
nc, ncUID, nw, mkIdea, mkIdeaUID
) where
import Language.Drasil.UID (mkUid, UID, HasUID(..))
import Control.Lens ((^.), makeLenses)
import Language.Drasil.NounPhrase.Core ( NP )
import Control.Lens.Lens (Lens')
class HasUID c => NamedIdea c where
term :: Lens' c NP
class NamedIdea c => Idea c where
getA :: c -> Maybe String
nc :: String -> NP -> IdeaDict
nc :: String -> NP -> IdeaDict
nc String
s NP
np' = UID -> NP -> Maybe String -> IdeaDict
IdeaDict (String -> UID
mkUid String
s) NP
np' Maybe String
forall a. Maybe a
Nothing
ncUID :: UID -> NP -> IdeaDict
ncUID :: UID -> NP -> IdeaDict
ncUID UID
u NP
np' = UID -> NP -> Maybe String -> IdeaDict
IdeaDict UID
u NP
np' Maybe String
forall a. Maybe a
Nothing
data IdeaDict = IdeaDict {
IdeaDict -> UID
_uu :: UID,
IdeaDict -> NP
_np :: NP,
IdeaDict -> Maybe String
mabbr :: Maybe String
}
makeLenses ''IdeaDict
instance Eq IdeaDict where IdeaDict
a == :: IdeaDict -> IdeaDict -> Bool
== IdeaDict
b = IdeaDict
a IdeaDict -> Getting UID IdeaDict UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID IdeaDict UID
forall c. HasUID c => Getter c UID
Getter IdeaDict UID
uid UID -> UID -> Bool
forall a. Eq a => a -> a -> Bool
== IdeaDict
b IdeaDict -> Getting UID IdeaDict UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID IdeaDict UID
forall c. HasUID c => Getter c UID
Getter IdeaDict UID
uid
instance HasUID IdeaDict where uid :: Getter IdeaDict UID
uid = (UID -> f UID) -> IdeaDict -> f IdeaDict
Lens' IdeaDict UID
uu
instance NamedIdea IdeaDict where term :: Lens' IdeaDict NP
term = (NP -> f NP) -> IdeaDict -> f IdeaDict
Lens' IdeaDict NP
np
instance Idea IdeaDict where getA :: IdeaDict -> Maybe String
getA = IdeaDict -> Maybe String
mabbr
mkIdea :: String -> NP -> Maybe String -> IdeaDict
mkIdea :: String -> NP -> Maybe String -> IdeaDict
mkIdea String
s = UID -> NP -> Maybe String -> IdeaDict
IdeaDict (String -> UID
mkUid String
s)
mkIdeaUID :: UID -> NP -> Maybe String -> IdeaDict
mkIdeaUID :: UID -> NP -> Maybe String -> IdeaDict
mkIdeaUID = UID -> NP -> Maybe String -> IdeaDict
IdeaDict
nw :: Idea c => c -> IdeaDict
nw :: forall c. Idea c => c -> IdeaDict
nw c
c = UID -> NP -> Maybe String -> IdeaDict
IdeaDict (c
c c -> Getting UID c UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID c UID
forall c. HasUID c => Getter c UID
Getter c UID
uid) (c
c c -> Getting NP c NP -> NP
forall s a. s -> Getting a s a -> a
^. Getting NP c NP
forall c. NamedIdea c => Lens' c NP
Lens' c NP
term) (c -> Maybe String
forall c. Idea c => c -> Maybe String
getA c
c)