{-# 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' 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' 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 forall s a. s -> Getting a s a -> a
^. forall c. HasUID c => Lens' c UID
uid forall a. Eq a => a -> a -> Bool
== IdeaDict
b forall s a. s -> Getting a s a -> a
^. forall c. HasUID c => Lens' c UID
uid
instance HasUID IdeaDict where uid :: Lens' IdeaDict UID
uid = Lens' IdeaDict UID
uu
instance NamedIdea IdeaDict where term :: Lens' IdeaDict NP
term = 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 forall s a. s -> Getting a s a -> a
^. forall c. HasUID c => Lens' c UID
uid) (c
c forall s a. s -> Getting a s a -> a
^. forall c. NamedIdea c => Lens' c NP
term) (forall c. Idea c => c -> Maybe String
getA c
c)