From 6429ed7148a5be1057d3f6441e9a023f43c2da17 Mon Sep 17 00:00:00 2001 From: Eve Date: Sun, 6 Apr 2025 14:54:15 +0200 Subject: [PATCH] Choice-splitting versions of mapVariants and mapConstVs --- src/compiler/api/GF/Compile/Compute/Concrete2.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/compiler/api/GF/Compile/Compute/Concrete2.hs b/src/compiler/api/GF/Compile/Compute/Concrete2.hs index ee7e4b024..930f16f15 100644 --- a/src/compiler/api/GF/Compile/Compute/Concrete2.hs +++ b/src/compiler/api/GF/Compile/Compute/Concrete2.hs @@ -3,7 +3,8 @@ module GF.Compile.Compute.Concrete2 (Env, Scope, Value(..), Variants(..), Constraint, OptionInfo(..), ChoiceMap, cleanOptions, ConstValue(..), ConstVariants(..), Globals(..), PredefTable, EvalM, - mapVariants, unvariants, variants2consts, consts2variants, + mapVariants, mapVariantsC, unvariants, variants2consts, + mapConstVs, mapConstVsC, unconstVs, consts2variants, runEvalM, runEvalMWithOpts, stdPredef, globals, withState, PredefImpl, Predef(..), ($\), pdCanonicalArgs, pdArity, @@ -102,6 +103,10 @@ mapVariants :: (Value -> Value) -> Variants -> Variants mapVariants f (VarFree vs) = VarFree (f <$> vs) mapVariants f (VarOpts n cs) = VarOpts n (second f <$> cs) +mapVariantsC :: (Choice -> Value -> Value) -> Choice -> Variants -> Variants +mapVariantsC f c (VarFree vs) = VarFree (mapC f c vs) +mapVariantsC f c (VarOpts n cs) = VarOpts n (mapC (second . f) c cs) + unvariants :: Variants -> [Value] unvariants (VarFree vs) = vs unvariants (VarOpts n cs) = snd <$> cs @@ -142,6 +147,10 @@ mapConstVs :: (ConstValue a -> ConstValue b) -> ConstVariants a -> ConstVariants mapConstVs f (ConstFree vs) = ConstFree (f <$> vs) mapConstVs f (ConstOpts n cs) = ConstOpts n (second f <$> cs) +mapConstVsC :: (Choice -> ConstValue a -> ConstValue b) -> Choice -> ConstVariants a -> ConstVariants b +mapConstVsC f c (ConstFree vs) = ConstFree (mapC f c vs) +mapConstVsC f c (ConstOpts n cs) = ConstOpts n (mapC (second . f) c cs) + unconstVs :: ConstVariants a -> [ConstValue a] unconstVs (ConstFree vs) = vs unconstVs (ConstOpts n cs) = snd <$> cs