{-# LANGUAGE CPP #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE OverloadedStrings #-}
module Swish.Datatype
( Datatype(..)
, typeName, typeRules, typeMkRules, typeMkModifiers, typeMkCanonicalForm
, getTypeAxiom, getTypeRule
, DatatypeVal(..)
, getDTMod
, getDTRel
, tvalMkCanonicalForm
, DatatypeMap(..)
, DatatypeRel(..), DatatypeRelFn, DatatypeRelPr
, altArgs
, UnaryFnDescr, UnaryFnTable, UnaryFnApply, unaryFnApp
, BinaryFnDescr, BinaryFnTable, BinaryFnApply, binaryFnApp
, BinMaybeFnDescr, BinMaybeFnTable, BinMaybeFnApply, binMaybeFnApp
, ListFnDescr, ListFnTable, ListFnApply, listFnApp
, DatatypeMod(..), ModifierFn
, ApplyModifier
, nullDatatypeMod
, makeVmod11inv, makeVmod11
, makeVmod21inv, makeVmod21
, makeVmod20
, makeVmod22
, makeVmodN1
, DatatypeSub(..)
)
where
import Swish.Namespace (ScopedName)
import Swish.Rule (Formula(..), Rule(..))
import Swish.Ruleset (Ruleset(..))
import Swish.Ruleset (getRulesetAxiom, getRulesetRule)
import Swish.VarBinding (VarBinding(..), VarBindingModify(..), OpenVarBindingModify)
import Swish.VarBinding (addVarBinding, nullVarBindingModify)
import Swish.RDF.Vocabulary (swishName)
import Swish.Utils.ListHelpers (flist)
#if (!defined(__GLASGOW_HASKELL__)) || (__GLASGOW_HASKELL__ < 808)
import Control.Applicative ((<$>))
#endif
import Data.Maybe (isJust, catMaybes)
import qualified Data.Map as M
import qualified Data.Text as T
data Datatype ex lb vn = forall vt . Datatype (DatatypeVal ex vt lb vn)
typeName :: Datatype ex lb vn -> ScopedName
typeName :: forall ex lb vn. Datatype ex lb vn -> ScopedName
typeName (Datatype DatatypeVal ex vt lb vn
dtv) = forall ex vt lb vn. DatatypeVal ex vt lb vn -> ScopedName
tvalName DatatypeVal ex vt lb vn
dtv
typeRules :: Datatype ex lb vn -> Ruleset ex
typeRules :: forall ex lb vn. Datatype ex lb vn -> Ruleset ex
typeRules (Datatype DatatypeVal ex vt lb vn
dtv) = forall ex vt lb vn. DatatypeVal ex vt lb vn -> Ruleset ex
tvalRules DatatypeVal ex vt lb vn
dtv
typeMkRules :: Datatype ex lb vn -> ex -> [Rule ex]
typeMkRules :: forall ex lb vn. Datatype ex lb vn -> ex -> [Rule ex]
typeMkRules (Datatype DatatypeVal ex vt lb vn
dtv) = forall ex vt lb vn. DatatypeVal ex vt lb vn -> ex -> [Rule ex]
tvalMkRules DatatypeVal ex vt lb vn
dtv
typeMkModifiers :: Datatype ex lb vn -> [OpenVarBindingModify lb vn]
typeMkModifiers :: forall ex lb vn. Datatype ex lb vn -> [OpenVarBindingModify lb vn]
typeMkModifiers (Datatype DatatypeVal ex vt lb vn
dtv) = forall ex vt lb vn.
DatatypeVal ex vt lb vn -> [OpenVarBindingModify lb vn]
tvalMkMods DatatypeVal ex vt lb vn
dtv
getTypeAxiom :: ScopedName -> Datatype ex lb vn -> Maybe (Formula ex)
getTypeAxiom :: forall ex lb vn.
ScopedName -> Datatype ex lb vn -> Maybe (Formula ex)
getTypeAxiom ScopedName
nam Datatype ex lb vn
dt = forall ex. ScopedName -> Ruleset ex -> Maybe (Formula ex)
getRulesetAxiom ScopedName
nam (forall ex lb vn. Datatype ex lb vn -> Ruleset ex
typeRules Datatype ex lb vn
dt)
getTypeRule :: ScopedName -> Datatype ex lb vn -> Maybe (Rule ex)
getTypeRule :: forall ex lb vn. ScopedName -> Datatype ex lb vn -> Maybe (Rule ex)
getTypeRule ScopedName
nam Datatype ex lb vn
dt = forall ex. ScopedName -> Ruleset ex -> Maybe (Rule ex)
getRulesetRule ScopedName
nam (forall ex lb vn. Datatype ex lb vn -> Ruleset ex
typeRules Datatype ex lb vn
dt)
typeMkCanonicalForm :: Datatype ex lb vn -> T.Text -> Maybe T.Text
typeMkCanonicalForm :: forall ex lb vn. Datatype ex lb vn -> Text -> Maybe Text
typeMkCanonicalForm (Datatype DatatypeVal ex vt lb vn
dtv) = forall ex vt lb vn. DatatypeVal ex vt lb vn -> Text -> Maybe Text
tvalMkCanonicalForm DatatypeVal ex vt lb vn
dtv
data DatatypeVal ex vt lb vn = DatatypeVal
{ forall ex vt lb vn. DatatypeVal ex vt lb vn -> ScopedName
tvalName :: ScopedName
, forall ex vt lb vn. DatatypeVal ex vt lb vn -> Ruleset ex
tvalRules :: Ruleset ex
, forall ex vt lb vn. DatatypeVal ex vt lb vn -> ex -> [Rule ex]
tvalMkRules :: ex -> [Rule ex]
, forall ex vt lb vn.
DatatypeVal ex vt lb vn -> [OpenVarBindingModify lb vn]
tvalMkMods :: [OpenVarBindingModify lb vn]
, forall ex vt lb vn. DatatypeVal ex vt lb vn -> DatatypeMap vt
tvalMap :: DatatypeMap vt
, forall ex vt lb vn. DatatypeVal ex vt lb vn -> [DatatypeRel vt]
tvalRel :: [DatatypeRel vt]
, forall ex vt lb vn.
DatatypeVal ex vt lb vn -> [DatatypeMod vt lb vn]
tvalMod :: [DatatypeMod vt lb vn]
}
getDTRel ::
ScopedName -> DatatypeVal ex vt lb vn -> Maybe (DatatypeRel vt)
getDTRel :: forall ex vt lb vn.
ScopedName -> DatatypeVal ex vt lb vn -> Maybe (DatatypeRel vt)
getDTRel ScopedName
nam DatatypeVal ex vt lb vn
dtv =
let m :: Map ScopedName (DatatypeRel vt)
m = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (\DatatypeRel vt
n -> (forall vt. DatatypeRel vt -> ScopedName
dtRelName DatatypeRel vt
n, DatatypeRel vt
n)) (forall ex vt lb vn. DatatypeVal ex vt lb vn -> [DatatypeRel vt]
tvalRel DatatypeVal ex vt lb vn
dtv)
in forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup ScopedName
nam Map ScopedName (DatatypeRel vt)
m
getDTMod ::
ScopedName -> DatatypeVal ex vt lb vn -> Maybe (DatatypeMod vt lb vn)
getDTMod :: forall ex vt lb vn.
ScopedName
-> DatatypeVal ex vt lb vn -> Maybe (DatatypeMod vt lb vn)
getDTMod ScopedName
nam DatatypeVal ex vt lb vn
dtv =
let m :: Map ScopedName (DatatypeMod vt lb vn)
m = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (\DatatypeMod vt lb vn
n -> (forall vt lb vn. DatatypeMod vt lb vn -> ScopedName
dmName DatatypeMod vt lb vn
n, DatatypeMod vt lb vn
n)) (forall ex vt lb vn.
DatatypeVal ex vt lb vn -> [DatatypeMod vt lb vn]
tvalMod DatatypeVal ex vt lb vn
dtv)
in forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup ScopedName
nam Map ScopedName (DatatypeMod vt lb vn)
m
tvalMkCanonicalForm :: DatatypeVal ex vt lb vn -> T.Text -> Maybe T.Text
tvalMkCanonicalForm :: forall ex vt lb vn. DatatypeVal ex vt lb vn -> Text -> Maybe Text
tvalMkCanonicalForm DatatypeVal ex vt lb vn
dtv Text
str = Maybe Text
can
where
dtmap :: DatatypeMap vt
dtmap = forall ex vt lb vn. DatatypeVal ex vt lb vn -> DatatypeMap vt
tvalMap DatatypeVal ex vt lb vn
dtv
val :: Maybe vt
val = forall vt. DatatypeMap vt -> Text -> Maybe vt
mapL2V DatatypeMap vt
dtmap Text
str
can :: Maybe Text
can = forall vt. DatatypeMap vt -> vt -> Maybe Text
mapV2L DatatypeMap vt
dtmap forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe vt
val
data DatatypeMap vt = DatatypeMap
{ forall vt. DatatypeMap vt -> Text -> Maybe vt
mapL2V :: T.Text -> Maybe vt
, forall vt. DatatypeMap vt -> vt -> Maybe Text
mapV2L :: vt -> Maybe T.Text
}
type DatatypeRelFn vt = [Maybe vt] -> Maybe [[vt]]
type DatatypeRelPr vt = [vt] -> Bool
data DatatypeRel vt = DatatypeRel
{ forall vt. DatatypeRel vt -> ScopedName
dtRelName :: ScopedName
, forall vt. DatatypeRel vt -> DatatypeRelFn vt
dtRelFunc :: DatatypeRelFn vt
}
type ModifierFn vn = [vn] -> [vn]
type ApplyModifier lb vn =
ScopedName -> [ModifierFn vn] -> OpenVarBindingModify lb vn
data DatatypeMod vt lb vn = DatatypeMod
{ forall vt lb vn. DatatypeMod vt lb vn -> ScopedName
dmName :: ScopedName
, forall vt lb vn. DatatypeMod vt lb vn -> [ModifierFn vt]
dmModf :: [ModifierFn vt]
, forall vt lb vn. DatatypeMod vt lb vn -> ApplyModifier lb vn
dmAppf :: ApplyModifier lb vn
}
nullDatatypeMod :: DatatypeMod vt lb vn
nullDatatypeMod :: forall vt lb vn. DatatypeMod vt lb vn
nullDatatypeMod = DatatypeMod
{ dmName :: ScopedName
dmName = LName -> ScopedName
swishName LName
"nullDatatypeMod"
, dmModf :: [ModifierFn vt]
dmModf = []
, dmAppf :: ApplyModifier lb vn
dmAppf = forall {p} {a} {b}. ScopedName -> p -> [a] -> VarBindingModify a b
nullAppf
}
where
nullAppf :: ScopedName -> p -> [a] -> VarBindingModify a b
nullAppf ScopedName
nam p
_ [a]
lbs = (forall a b. OpenVarBindingModify a b
nullVarBindingModify [a]
lbs) { vbmName :: ScopedName
vbmName = ScopedName
nam }
makeVmod11inv :: (Ord lb, Ord vn) => ApplyModifier lb vn
makeVmod11inv :: forall lb vn. (Ord lb, Ord vn) => ApplyModifier lb vn
makeVmod11inv ScopedName
nam [ModifierFn vn
f0,ModifierFn vn
f1,ModifierFn vn
f2] lbs :: [lb]
lbs@(~[lb
lb1,lb
lb2]) = VarBindingModify
{ vbmName :: ScopedName
vbmName = ScopedName
nam
, vbmApply :: [VarBinding lb vn] -> [VarBinding lb vn]
vbmApply = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap VarBinding lb vn -> [VarBinding lb vn]
app1
, vbmVocab :: [lb]
vbmVocab = [lb]
lbs
, vbmUsage :: [[lb]]
vbmUsage = [[],[lb
lb1],[lb
lb2]]
}
where
app1 :: VarBinding lb vn -> [VarBinding lb vn]
app1 VarBinding lb vn
vbind = [Maybe vn] -> VarBinding lb vn -> [VarBinding lb vn]
app2 (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. VarBinding a b -> a -> Maybe b
vbMap VarBinding lb vn
vbind) [lb]
lbs) VarBinding lb vn
vbind
app2 :: [Maybe vn] -> VarBinding lb vn -> [VarBinding lb vn]
app2 [Just vn
v1,Just vn
v2] VarBinding lb vn
vbind = forall vt (varBinding :: * -> * -> *) lb.
[vt] -> varBinding lb vt -> [varBinding lb vt]
selv (ModifierFn vn
f0 [vn
v1,vn
v2]) VarBinding lb vn
vbind
app2 [Maybe vn
Nothing,Just vn
v2] VarBinding lb vn
vbind = forall lb vt.
(Ord lb, Ord vt) =>
lb -> [vt] -> VarBinding lb vt -> [VarBinding lb vt]
addv lb
lb1 (ModifierFn vn
f1 [vn
v2]) VarBinding lb vn
vbind
app2 [Just vn
v1,Maybe vn
Nothing] VarBinding lb vn
vbind = forall lb vt.
(Ord lb, Ord vt) =>
lb -> [vt] -> VarBinding lb vt -> [VarBinding lb vt]
addv lb
lb2 (ModifierFn vn
f2 [vn
v1]) VarBinding lb vn
vbind
app2 [Maybe vn]
_ VarBinding lb vn
_ = []
makeVmod11inv ScopedName
_ [ModifierFn vn]
_ [lb]
_ =
forall a. HasCallStack => [Char] -> a
error [Char]
"makeVmod11inv: requires 3 functions and 2 labels"
makeVmod11 :: (Ord lb, Ord vn) => ApplyModifier lb vn
makeVmod11 :: forall lb vn. (Ord lb, Ord vn) => ApplyModifier lb vn
makeVmod11 ScopedName
nam [ModifierFn vn
f0,ModifierFn vn
f1] lbs :: [lb]
lbs@(~[lb
lb1,lb
_]) = VarBindingModify
{ vbmName :: ScopedName
vbmName = ScopedName
nam
, vbmApply :: [VarBinding lb vn] -> [VarBinding lb vn]
vbmApply = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap VarBinding lb vn -> [VarBinding lb vn]
app1
, vbmVocab :: [lb]
vbmVocab = [lb]
lbs
, vbmUsage :: [[lb]]
vbmUsage = [[],[lb
lb1]]
}
where
app1 :: VarBinding lb vn -> [VarBinding lb vn]
app1 VarBinding lb vn
vbind = [Maybe vn] -> VarBinding lb vn -> [VarBinding lb vn]
app2 (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. VarBinding a b -> a -> Maybe b
vbMap VarBinding lb vn
vbind) [lb]
lbs) VarBinding lb vn
vbind
app2 :: [Maybe vn] -> VarBinding lb vn -> [VarBinding lb vn]
app2 [Just vn
v1,Just vn
v2] VarBinding lb vn
vbind = forall vt (varBinding :: * -> * -> *) lb.
[vt] -> varBinding lb vt -> [varBinding lb vt]
selv (ModifierFn vn
f0 [vn
v1,vn
v2]) VarBinding lb vn
vbind
app2 [Maybe vn
Nothing,Just vn
v2] VarBinding lb vn
vbind = forall lb vt.
(Ord lb, Ord vt) =>
lb -> [vt] -> VarBinding lb vt -> [VarBinding lb vt]
addv lb
lb1 (ModifierFn vn
f1 [vn
v2]) VarBinding lb vn
vbind
app2 [Maybe vn]
_ VarBinding lb vn
_ = []
makeVmod11 ScopedName
_ [ModifierFn vn]
_ [lb]
_ =
forall a. HasCallStack => [Char] -> a
error [Char]
"makeVmod11: requires 2 functions and 2 labels"
makeVmod21inv :: (Ord lb, Ord vn) => ApplyModifier lb vn
makeVmod21inv :: forall lb vn. (Ord lb, Ord vn) => ApplyModifier lb vn
makeVmod21inv ScopedName
nam [ModifierFn vn
f0,ModifierFn vn
f1,ModifierFn vn
f2,ModifierFn vn
f3] lbs :: [lb]
lbs@(~[lb
lb1,lb
lb2,lb
lb3]) = VarBindingModify
{ vbmName :: ScopedName
vbmName = ScopedName
nam
, vbmApply :: [VarBinding lb vn] -> [VarBinding lb vn]
vbmApply = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap VarBinding lb vn -> [VarBinding lb vn]
app1
, vbmVocab :: [lb]
vbmVocab = [lb]
lbs
, vbmUsage :: [[lb]]
vbmUsage = [[],[lb
lb1],[lb
lb2],[lb
lb3]]
}
where
app1 :: VarBinding lb vn -> [VarBinding lb vn]
app1 VarBinding lb vn
vbind = [Maybe vn] -> VarBinding lb vn -> [VarBinding lb vn]
app2 (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. VarBinding a b -> a -> Maybe b
vbMap VarBinding lb vn
vbind) [lb]
lbs) VarBinding lb vn
vbind
app2 :: [Maybe vn] -> VarBinding lb vn -> [VarBinding lb vn]
app2 [Just vn
v1,Just vn
v2,Just vn
v3] VarBinding lb vn
vbind = forall vt (varBinding :: * -> * -> *) lb.
[vt] -> varBinding lb vt -> [varBinding lb vt]
selv (ModifierFn vn
f0 [vn
v1,vn
v2,vn
v3]) VarBinding lb vn
vbind
app2 [Maybe vn
Nothing,Just vn
v2,Just vn
v3] VarBinding lb vn
vbind = forall lb vt.
(Ord lb, Ord vt) =>
lb -> [vt] -> VarBinding lb vt -> [VarBinding lb vt]
addv lb
lb1 (ModifierFn vn
f1 [vn
v2,vn
v3]) VarBinding lb vn
vbind
app2 [Just vn
v1,Maybe vn
Nothing,Just vn
v3] VarBinding lb vn
vbind = forall lb vt.
(Ord lb, Ord vt) =>
lb -> [vt] -> VarBinding lb vt -> [VarBinding lb vt]
addv lb
lb2 (ModifierFn vn
f2 [vn
v1,vn
v3]) VarBinding lb vn
vbind
app2 [Just vn
v1,Just vn
v2,Maybe vn
Nothing] VarBinding lb vn
vbind = forall lb vt.
(Ord lb, Ord vt) =>
lb -> [vt] -> VarBinding lb vt -> [VarBinding lb vt]
addv lb
lb3 (ModifierFn vn
f3 [vn
v1,vn
v2]) VarBinding lb vn
vbind
app2 [Maybe vn]
_ VarBinding lb vn
_ = []
makeVmod21inv ScopedName
_ [ModifierFn vn]
_ [lb]
_ =
forall a. HasCallStack => [Char] -> a
error [Char]
"makeVmod21inv: requires 4 functions and 3 labels"
makeVmod21 :: (Ord lb, Ord vn) => ApplyModifier lb vn
makeVmod21 :: forall lb vn. (Ord lb, Ord vn) => ApplyModifier lb vn
makeVmod21 ScopedName
nam [ModifierFn vn
f0,ModifierFn vn
f1] lbs :: [lb]
lbs@(~[lb
lb1,lb
_,lb
_]) = VarBindingModify
{ vbmName :: ScopedName
vbmName = ScopedName
nam
, vbmApply :: [VarBinding lb vn] -> [VarBinding lb vn]
vbmApply = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap VarBinding lb vn -> [VarBinding lb vn]
app1
, vbmVocab :: [lb]
vbmVocab = [lb]
lbs
, vbmUsage :: [[lb]]
vbmUsage = [[],[lb
lb1]]
}
where
app1 :: VarBinding lb vn -> [VarBinding lb vn]
app1 VarBinding lb vn
vbind = [Maybe vn] -> VarBinding lb vn -> [VarBinding lb vn]
app2 (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. VarBinding a b -> a -> Maybe b
vbMap VarBinding lb vn
vbind) [lb]
lbs) VarBinding lb vn
vbind
app2 :: [Maybe vn] -> VarBinding lb vn -> [VarBinding lb vn]
app2 [Just vn
v1,Just vn
v2,Just vn
v3] VarBinding lb vn
vbind = forall vt (varBinding :: * -> * -> *) lb.
[vt] -> varBinding lb vt -> [varBinding lb vt]
selv (ModifierFn vn
f0 [vn
v1,vn
v2,vn
v3]) VarBinding lb vn
vbind
app2 [Maybe vn
Nothing,Just vn
v2,Just vn
v3] VarBinding lb vn
vbind = forall lb vt.
(Ord lb, Ord vt) =>
lb -> [vt] -> VarBinding lb vt -> [VarBinding lb vt]
addv lb
lb1 (ModifierFn vn
f1 [vn
v2,vn
v3]) VarBinding lb vn
vbind
app2 [Maybe vn]
_ VarBinding lb vn
_ = []
makeVmod21 ScopedName
_ [ModifierFn vn]
_ [lb]
_ =
forall a. HasCallStack => [Char] -> a
error [Char]
"makeVmod21: requires 2 functions and 3 labels"
makeVmod20 :: (Eq lb, Show lb, Eq vn, Show vn) => ApplyModifier lb vn
makeVmod20 :: forall lb vn.
(Eq lb, Show lb, Eq vn, Show vn) =>
ApplyModifier lb vn
makeVmod20 ScopedName
nam [ModifierFn vn
f0] lbs :: [lb]
lbs@(~[lb
_,lb
_]) = VarBindingModify
{ vbmName :: ScopedName
vbmName = ScopedName
nam
, vbmApply :: [VarBinding lb vn] -> [VarBinding lb vn]
vbmApply = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap VarBinding lb vn -> [VarBinding lb vn]
app1
, vbmVocab :: [lb]
vbmVocab = [lb]
lbs
, vbmUsage :: [[lb]]
vbmUsage = [[]]
}
where
app1 :: VarBinding lb vn -> [VarBinding lb vn]
app1 VarBinding lb vn
vbind = forall {varBinding :: * -> * -> *} {lb}.
[Maybe vn] -> varBinding lb vn -> [varBinding lb vn]
app2 (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. VarBinding a b -> a -> Maybe b
vbMap VarBinding lb vn
vbind) [lb]
lbs) VarBinding lb vn
vbind
app2 :: [Maybe vn] -> varBinding lb vn -> [varBinding lb vn]
app2 [Just vn
v1,Just vn
v2] varBinding lb vn
vbind = forall vt (varBinding :: * -> * -> *) lb.
[vt] -> varBinding lb vt -> [varBinding lb vt]
selv (ModifierFn vn
f0 [vn
v1,vn
v2]) varBinding lb vn
vbind
app2 [Maybe vn]
_ varBinding lb vn
_ = []
makeVmod20 ScopedName
_ [ModifierFn vn]
_ [lb]
_ =
forall a. HasCallStack => [Char] -> a
error [Char]
"makeVmod20: requires 1 function and 2 labels"
makeVmod22 :: (Ord lb, Ord vn) => ApplyModifier lb vn
makeVmod22 :: forall lb vn. (Ord lb, Ord vn) => ApplyModifier lb vn
makeVmod22 ScopedName
nam [ModifierFn vn
f0,ModifierFn vn
f1] lbs :: [lb]
lbs@(~[lb
lb1,lb
lb2,lb
_,lb
_]) = VarBindingModify
{ vbmName :: ScopedName
vbmName = ScopedName
nam
, vbmApply :: [VarBinding lb vn] -> [VarBinding lb vn]
vbmApply = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap VarBinding lb vn -> [VarBinding lb vn]
app1
, vbmVocab :: [lb]
vbmVocab = [lb]
lbs
, vbmUsage :: [[lb]]
vbmUsage = [[],[lb
lb1,lb
lb2]]
}
where
app1 :: VarBinding lb vn -> [VarBinding lb vn]
app1 VarBinding lb vn
vbind = [Maybe vn] -> VarBinding lb vn -> [VarBinding lb vn]
app2 (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. VarBinding a b -> a -> Maybe b
vbMap VarBinding lb vn
vbind) [lb]
lbs) VarBinding lb vn
vbind
app2 :: [Maybe vn] -> VarBinding lb vn -> [VarBinding lb vn]
app2 [Just vn
v1,Just vn
v2,Just vn
v3,Just vn
v4] VarBinding lb vn
vbind =
forall vt (varBinding :: * -> * -> *) lb.
[vt] -> varBinding lb vt -> [varBinding lb vt]
selv (ModifierFn vn
f0 [vn
v1,vn
v2,vn
v3,vn
v4]) VarBinding lb vn
vbind
app2 [Maybe vn
Nothing,Maybe vn
Nothing,Just vn
v3,Just vn
v4] VarBinding lb vn
vbind =
forall lb vt.
(Ord lb, Ord vt) =>
lb -> lb -> [vt] -> VarBinding lb vt -> [VarBinding lb vt]
addv2 lb
lb1 lb
lb2 (ModifierFn vn
f1 [vn
v3,vn
v4]) VarBinding lb vn
vbind
app2 [Maybe vn]
_ VarBinding lb vn
_ = []
makeVmod22 ScopedName
_ [ModifierFn vn]
_ [lb]
_ =
forall a. HasCallStack => [Char] -> a
error [Char]
"makeVmod22: requires 2 functions and 4 labels"
makeVmodN1 :: (Ord lb, Ord vn) => ApplyModifier lb vn
makeVmodN1 :: forall lb vn. (Ord lb, Ord vn) => ApplyModifier lb vn
makeVmodN1 ScopedName
nam [ModifierFn vn
f0,ModifierFn vn
f1] lbs :: [lb]
lbs@(~(lb
lb1:[lb]
_)) = VarBindingModify
{ vbmName :: ScopedName
vbmName = ScopedName
nam
, vbmApply :: [VarBinding lb vn] -> [VarBinding lb vn]
vbmApply = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap VarBinding lb vn -> [VarBinding lb vn]
app1
, vbmVocab :: [lb]
vbmVocab = [lb]
lbs
, vbmUsage :: [[lb]]
vbmUsage = [[],[lb
lb1]]
}
where
app1 :: VarBinding lb vn -> [VarBinding lb vn]
app1 VarBinding lb vn
vbind = [Maybe vn] -> VarBinding lb vn -> [VarBinding lb vn]
app2 (forall a b. (a -> b) -> [a] -> [b]
map (forall a b. VarBinding a b -> a -> Maybe b
vbMap VarBinding lb vn
vbind) [lb]
lbs) VarBinding lb vn
vbind
app2 :: [Maybe vn] -> VarBinding lb vn -> [VarBinding lb vn]
app2 vs :: [Maybe vn]
vs@(Maybe vn
v1:[Maybe vn]
_) VarBinding lb vn
vbind
| forall a. Maybe a -> Bool
isJust Maybe vn
v1 Bool -> Bool -> Bool
&& Bool
isJustvs = forall vt (varBinding :: * -> * -> *) lb.
[vt] -> varBinding lb vt -> [varBinding lb vt]
selv (ModifierFn vn
f0 [vn]
jvs) VarBinding lb vn
vbind
| Bool
isJustvs = forall lb vt.
(Ord lb, Ord vt) =>
lb -> [vt] -> VarBinding lb vt -> [VarBinding lb vt]
addv lb
lb1 (ModifierFn vn
f1 [vn]
jvs) VarBinding lb vn
vbind
| Bool
otherwise = []
where
isJustvs :: Bool
isJustvs = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all forall a. Maybe a -> Bool
isJust [Maybe vn]
vs
jvs :: [vn]
jvs = forall a. [Maybe a] -> [a]
catMaybes [Maybe vn]
vs
app2 [Maybe vn]
_ VarBinding lb vn
_ = forall a. HasCallStack => [Char] -> a
error [Char]
"app2 sent empty list"
makeVmodN1 ScopedName
_ [ModifierFn vn]
_ [lb]
_ =
forall a. HasCallStack => [Char] -> a
error [Char]
"makeVmodN1: requires 2 functions and at 1 or more labels"
addv :: (Ord lb, Ord vt)
=> lb -> [vt] -> VarBinding lb vt
-> [VarBinding lb vt]
addv :: forall lb vt.
(Ord lb, Ord vt) =>
lb -> [vt] -> VarBinding lb vt -> [VarBinding lb vt]
addv lb
lb [vt
val] VarBinding lb vt
vbind = [forall a b.
(Ord a, Ord b) =>
a -> b -> VarBinding a b -> VarBinding a b
addVarBinding lb
lb vt
val VarBinding lb vt
vbind]
addv lb
_ [vt]
_ VarBinding lb vt
_ = []
addv2 :: (Ord lb, Ord vt)
=> lb -> lb -> [vt] -> VarBinding lb vt
-> [VarBinding lb vt]
addv2 :: forall lb vt.
(Ord lb, Ord vt) =>
lb -> lb -> [vt] -> VarBinding lb vt -> [VarBinding lb vt]
addv2 lb
lb1 lb
lb2 [vt
val1,vt
val2] VarBinding lb vt
vbind = [forall a b.
(Ord a, Ord b) =>
a -> b -> VarBinding a b -> VarBinding a b
addVarBinding lb
lb1 vt
val1 forall a b. (a -> b) -> a -> b
$
forall a b.
(Ord a, Ord b) =>
a -> b -> VarBinding a b -> VarBinding a b
addVarBinding lb
lb2 vt
val2 VarBinding lb vt
vbind]
addv2 lb
_ lb
_ [vt]
_ VarBinding lb vt
_ = []
selv :: [vt] -> varBinding lb vt -> [varBinding lb vt]
selv :: forall vt (varBinding :: * -> * -> *) lb.
[vt] -> varBinding lb vt -> [varBinding lb vt]
selv [] varBinding lb vt
_ = []
selv [vt]
_ varBinding lb vt
vbind = [varBinding lb vt
vbind]
altArgs ::
(Eq vt)
=> DatatypeRelPr vt
-> [(vt->Bool,[b])]
-> ((vt->Bool)->b->[Maybe vt]->Maybe [vt])
-> DatatypeRelFn vt
altArgs :: forall vt b.
Eq vt =>
DatatypeRelPr vt
-> [(vt -> Bool, [b])]
-> ((vt -> Bool) -> b -> [Maybe vt] -> Maybe [vt])
-> DatatypeRelFn vt
altArgs DatatypeRelPr vt
pr [(vt -> Bool, [b])]
fnss (vt -> Bool) -> b -> [Maybe vt] -> Maybe [vt]
apfn [Maybe vt]
args = forall {t :: * -> *}.
Foldable t =>
Maybe (t [vt]) -> Maybe (t [vt])
cvals4 Maybe [[vt]]
cvals3
where
cvals1 :: [Maybe [vt]]
cvals1 = forall a b. [a -> b] -> a -> [b]
flist (forall a b. (a -> b) -> [a] -> [b]
map (forall vt b.
((vt -> Bool) -> b -> [Maybe vt] -> Maybe [vt])
-> (vt -> Bool, [b]) -> [Maybe vt] -> Maybe [vt]
applyFdescToTuple (vt -> Bool) -> b -> [Maybe vt] -> Maybe [vt]
apfn) [(vt -> Bool, [b])]
fnss) [Maybe vt]
args
cvals2 :: Maybe [[vt]]
cvals2 = forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence forall a b. (a -> b) -> a -> b
$ forall a.
Eq a =>
[a -> Bool] -> [Maybe a] -> [Maybe [a]] -> [Maybe [a]]
mergeTupleVals (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst [(vt -> Bool, [b])]
fnss) [Maybe vt]
args [Maybe [vt]]
cvals1
cvals3 :: Maybe [[vt]]
cvals3 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence Maybe [[vt]]
cvals2
cvals4 :: Maybe (t [vt]) -> Maybe (t [vt])
cvals4 Maybe (t [vt])
Nothing = forall a. Maybe a
Nothing
cvals4 cvs :: Maybe (t [vt])
cvs@(Just t [vt]
ts) = if forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all DatatypeRelPr vt
pr t [vt]
ts then Maybe (t [vt])
cvs else forall a. Maybe a
Nothing
applyFdescToTuple ::
((vt->Bool)->b->[Maybe vt]->Maybe [vt]) -> (vt->Bool,[b]) -> [Maybe vt]
-> Maybe [vt]
applyFdescToTuple :: forall vt b.
((vt -> Bool) -> b -> [Maybe vt] -> Maybe [vt])
-> (vt -> Bool, [b]) -> [Maybe vt] -> Maybe [vt]
applyFdescToTuple (vt -> Bool) -> b -> [Maybe vt] -> Maybe [vt]
apfn (vt -> Bool
p,[b]
fns) [Maybe vt]
args =
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Maybe [vt]]
cvals
where
cvals :: [Maybe [vt]]
cvals = forall a b. [a -> b] -> a -> [b]
flist (forall a b. (a -> b) -> [a] -> [b]
map ((vt -> Bool) -> b -> [Maybe vt] -> Maybe [vt]
apfn vt -> Bool
p) [b]
fns) [Maybe vt]
args
mergeTupleVals :: (Eq a) => [a->Bool] -> [Maybe a] -> [Maybe [a]] -> [Maybe [a]]
mergeTupleVals :: forall a.
Eq a =>
[a -> Bool] -> [Maybe a] -> [Maybe [a]] -> [Maybe [a]]
mergeTupleVals [a -> Bool]
_ [Maybe a]
_ (Maybe [a]
Nothing:[Maybe [a]]
_) = [forall a. Maybe a
Nothing]
mergeTupleVals (a -> Bool
_:[a -> Bool]
ps) (Maybe a
Nothing:[Maybe a]
a1s) (Just [a]
a2s:[Maybe [a]]
a2ss)
= forall a. a -> Maybe a
Just [a]
a2sforall a. a -> [a] -> [a]
:forall a.
Eq a =>
[a -> Bool] -> [Maybe a] -> [Maybe [a]] -> [Maybe [a]]
mergeTupleVals [a -> Bool]
ps [Maybe a]
a1s [Maybe [a]]
a2ss
mergeTupleVals (a -> Bool
p:[a -> Bool]
ps) (Just a
a1:[Maybe a]
a1s) (Just []:[Maybe [a]]
a2ss)
| a -> Bool
p a
a1 = forall a. a -> Maybe a
Just [a
a1]forall a. a -> [a] -> [a]
:forall a.
Eq a =>
[a -> Bool] -> [Maybe a] -> [Maybe [a]] -> [Maybe [a]]
mergeTupleVals [a -> Bool]
ps [Maybe a]
a1s [Maybe [a]]
a2ss
| Bool
otherwise = [forall a. Maybe a
Nothing]
mergeTupleVals (a -> Bool
p:[a -> Bool]
ps) (Just a
a1:[Maybe a]
a1s) (Just [a]
a2s:[Maybe [a]]
a2ss)
| a -> Bool
p a
a1 Bool -> Bool -> Bool
&& forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem a
a1 [a]
a2s = forall a. a -> Maybe a
Just [a
a1]forall a. a -> [a] -> [a]
:forall a.
Eq a =>
[a -> Bool] -> [Maybe a] -> [Maybe [a]] -> [Maybe [a]]
mergeTupleVals [a -> Bool]
ps [Maybe a]
a1s [Maybe [a]]
a2ss
| Bool
otherwise = [forall a. Maybe a
Nothing]
mergeTupleVals [a -> Bool]
_ [] [Maybe [a]]
_ = []
mergeTupleVals [a -> Bool]
_ [Maybe a]
_ [Maybe [a]]
_ = [forall a. Maybe a
Nothing]
type UnaryFnDescr a = (a->a,Int)
type UnaryFnTable a = [(a->Bool,[UnaryFnDescr a])]
type UnaryFnApply a = (a->Bool) -> UnaryFnDescr a -> [Maybe a] -> Maybe [a]
unaryFnApp :: UnaryFnApply a
unaryFnApp :: forall a. UnaryFnApply a
unaryFnApp a -> Bool
p (a -> a
f1,Int
n) [Maybe a]
args = Maybe a -> Maybe [a]
apf ([Maybe a]
args forall a. [a] -> Int -> a
!! Int
n)
where
apf :: Maybe a -> Maybe [a]
apf (Just a
a) = if a -> Bool
p a
r then forall a. a -> Maybe a
Just [a
r] else forall a. Maybe a
Nothing where r :: a
r = a -> a
f1 a
a
apf Maybe a
Nothing = forall a. a -> Maybe a
Just []
type BinaryFnDescr a = (a -> a -> a, Int, Int)
type BinaryFnTable a = [(a -> Bool, [BinaryFnDescr a])]
type BinaryFnApply a =
(a -> Bool) -> BinaryFnDescr a -> [Maybe a] -> Maybe [a]
binaryFnApp :: BinaryFnApply a
binaryFnApp :: forall a. BinaryFnApply a
binaryFnApp a -> Bool
p (a -> a -> a
f,Int
n1,Int
n2) [Maybe a]
args = Maybe a -> Maybe a -> Maybe [a]
apf ([Maybe a]
args forall a. [a] -> Int -> a
!! Int
n1) ([Maybe a]
args forall a. [a] -> Int -> a
!! Int
n2)
where
apf :: Maybe a -> Maybe a -> Maybe [a]
apf (Just a
a1) (Just a
a2) = if a -> Bool
p a
r then forall a. a -> Maybe a
Just [a
r] else forall a. Maybe a
Nothing
where r :: a
r = a -> a -> a
f a
a1 a
a2
apf Maybe a
_ Maybe a
_ = forall a. a -> Maybe a
Just []
type BinMaybeFnDescr a = (a -> a ->Maybe [a], Int, Int)
type BinMaybeFnTable a = [(a -> Bool, [BinMaybeFnDescr a])]
type BinMaybeFnApply a =
(a -> Bool) -> BinMaybeFnDescr a -> [Maybe a] -> Maybe [a]
binMaybeFnApp :: BinMaybeFnApply a
binMaybeFnApp :: forall a. BinMaybeFnApply a
binMaybeFnApp a -> Bool
p (a -> a -> Maybe [a]
f,Int
n1,Int
n2) [Maybe a]
args = Maybe a -> Maybe a -> Maybe [a]
apf ([Maybe a]
args forall a. [a] -> Int -> a
!! Int
n1) ([Maybe a]
args forall a. [a] -> Int -> a
!! Int
n2)
where
apf :: Maybe a -> Maybe a -> Maybe [a]
apf (Just a
a1) (Just a
a2) = if forall {t :: * -> *}. Foldable t => Maybe (t a) -> Bool
pm Maybe [a]
r then Maybe [a]
r else forall a. Maybe a
Nothing
where
r :: Maybe [a]
r = a -> a -> Maybe [a]
f a
a1 a
a2
pm :: Maybe (t a) -> Bool
pm Maybe (t a)
Nothing = Bool
False
pm (Just t a
x) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all a -> Bool
p t a
x
apf Maybe a
_ Maybe a
_ = forall a. a -> Maybe a
Just []
type ListFnDescr a = (a -> a -> a, a, a -> a -> a, Int)
type ListFnTable a = [(a -> Bool, [ListFnDescr a])]
type ListFnApply a = (a -> Bool) -> ListFnDescr a -> [Maybe a] -> Maybe [a]
listFnApp :: ListFnApply a
listFnApp :: forall a. ListFnApply a
listFnApp a -> Bool
p (a -> a -> a
f,a
z,a -> a -> a
g,Int
n) (Maybe a
a0:[Maybe a]
args)
| Int
n forall a. Eq a => a -> a -> Bool
== Int
0 =
Maybe [a] -> Maybe [a]
app forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (forall a. (a -> a -> a) -> Maybe a -> Maybe [a] -> Maybe [a]
apf a -> a -> a
f) (forall a. a -> Maybe a
Just [a
z]) [Maybe a]
args
| Bool
otherwise =
Maybe [a] -> Maybe [a]
app forall a b. (a -> b) -> a -> b
$ forall a. (a -> a -> a) -> Maybe a -> Maybe [a] -> Maybe [a]
apf a -> a -> a
g Maybe a
a0 (forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (forall a. (a -> a -> a) -> Maybe a -> Maybe [a] -> Maybe [a]
apf a -> a -> a
f) (forall a. a -> Maybe a
Just [a
z]) ([Maybe a]
args forall a. [a] -> Int -> [a]
`deleteIndex` (Int
n forall a. Num a => a -> a -> a
- Int
1)))
where
apf :: (a->a->a) -> Maybe a -> Maybe [a] -> Maybe [a]
apf :: forall a. (a -> a -> a) -> Maybe a -> Maybe [a] -> Maybe [a]
apf a -> a -> a
fn (Just a
a1) (Just [a
a2]) = forall a. a -> Maybe a
Just [a -> a -> a
fn a
a1 a
a2]
apf a -> a -> a
_ Maybe a
_ Maybe [a]
_ = forall a. a -> Maybe a
Just []
app :: Maybe [a] -> Maybe [a]
app Maybe [a]
Nothing = forall a. Maybe a
Nothing
app r :: Maybe [a]
r@(Just [a
a]) = if a -> Bool
p a
a then Maybe [a]
r else forall a. Maybe a
Nothing
app Maybe [a]
_ = forall a. a -> Maybe a
Just []
listFnApp a -> Bool
_ (a -> a -> a, a, a -> a -> a, Int)
_ [] = forall a. HasCallStack => [Char] -> a
error [Char]
"listFnApp called with an empty list"
deleteIndex :: [a] -> Int -> [a]
deleteIndex :: forall a. [a] -> Int -> [a]
deleteIndex [] Int
_ = []
deleteIndex xxs :: [a]
xxs@(a
x:[a]
xs) Int
n
| Int
n forall a. Ord a => a -> a -> Bool
< Int
0 = [a]
xxs
| Int
n forall a. Eq a => a -> a -> Bool
== Int
0 = [a]
xs
| Bool
otherwise = a
xforall a. a -> [a] -> [a]
:forall a. [a] -> Int -> [a]
deleteIndex [a]
xs (Int
nforall a. Num a => a -> a -> a
-Int
1)
data DatatypeSub ex lb vn supvt subvt = DatatypeSub
{ forall ex lb vn supvt subvt.
DatatypeSub ex lb vn supvt subvt -> DatatypeVal ex supvt lb vn
trelSup :: DatatypeVal ex supvt lb vn
, forall ex lb vn supvt subvt.
DatatypeSub ex lb vn supvt subvt -> DatatypeVal ex subvt lb vn
trelSub :: DatatypeVal ex subvt lb vn
, forall ex lb vn supvt subvt.
DatatypeSub ex lb vn supvt subvt -> subvt -> supvt
trelToSup :: subvt -> supvt
, forall ex lb vn supvt subvt.
DatatypeSub ex lb vn supvt subvt -> supvt -> Maybe subvt
trelToSub :: supvt -> Maybe subvt
}