2727 . Monad m
2828 ⇒ SD.Value a
2929 ⇒ { code ∷ M.Maybe LanguageId → String → m a
30- , textBox ∷ SD.TextBox (Const String ) → m (SD.TextBox Identity )
31- , value ∷ String → m a
32- , list ∷ String → m (L.List a )
30+ , textBox ∷ String → SD.TextBox (Const String ) → m (SD.TextBox Identity )
31+ , value ∷ String → String → m a
32+ , list ∷ String → String → m (L.List a )
3333 }
3434 → SD.SlamDownP a
3535 → m (SD.SlamDownP a )
@@ -44,48 +44,48 @@ eval fs = everywhereM b i
4444
4545 i ∷ SD.Inline a → m (SD.Inline a )
4646 i (SD.Code true code) = SD.Code false <<< SD .renderValue <$> fs.code M.Nothing code
47- i (SD.FormField l r field) = SD.FormField l r <$> f field
47+ i (SD.FormField lbl r field) = SD.FormField lbl r <$> f lbl field
4848 i other = pure $ other
4949
50- f ∷ SD.FormField a → m (SD.FormField a )
51- f (SD.TextBox tb) = SD.TextBox <<< M .fromMaybe tb <$> nbeTextBox tb
50+ f ∷ String → SD.FormField a → m (SD.FormField a )
51+ f lbl (SD.TextBox tb) = SD.TextBox <<< M .fromMaybe tb <$> nbeTextBox tb
5252 where
5353 -- normalization-by-evaluation proceeds by evaluating an object into a semantic model
5454 -- (in this case, `Identity`), and then quoting the result back into the syntax.
5555 nbeTextBox ∷ SD.TextBox (Compose M.Maybe SD.Expr ) → m (M.Maybe (SD.TextBox (Compose M.Maybe SD.Expr )))
5656 nbeTextBox = evalTextBox >>> map (map quoteTextBox)
5757
5858 evalTextBox ∷ SD.TextBox (Compose M.Maybe SD.Expr ) → m (M.Maybe (SD.TextBox Identity ))
59- evalTextBox tb' = T .sequence $ fs.textBox <$> asCode tb' <|> pure <$> asLit tb'
59+ evalTextBox tb' = T .sequence $ fs.textBox lbl <$> asCode tb' <|> pure <$> asLit tb'
6060 where
6161 asLit = SD .traverseTextBox (unwrap >>> (_ >>= SD .getLiteral) >>> map Identity )
6262 asCode = SD .traverseTextBox (unwrap >>> (_ >>= SD .getUnevaluated) >>> map Const )
6363
6464 quoteTextBox ∷ SD.TextBox Identity → SD.TextBox (Compose M.Maybe SD.Expr )
6565 quoteTextBox = SD .transTextBox (unwrap >>> SD.Literal >>> M.Just >>> Compose )
6666
67- f (SD.RadioButtons sel opts) = do
68- sel' ← evalExpr fs.value sel
69- opts' ← evalExpr fs.list opts
67+ f lbl (SD.RadioButtons sel opts) = do
68+ sel' ← evalExpr lbl fs.value sel
69+ opts' ← evalExpr lbl fs.list opts
7070 pure $ SD.RadioButtons sel' (mergeSelection (L .singleton <$> sel') opts')
7171
72- f (SD.CheckBoxes sel vals) = do
73- sel' ← evalExpr fs.list sel
74- vals' ← evalExpr fs.list vals
72+ f lbl (SD.CheckBoxes sel vals) = do
73+ sel' ← evalExpr lbl fs.list sel
74+ vals' ← evalExpr lbl fs.list vals
7575 pure $ SD.CheckBoxes sel' (mergeSelection sel' vals')
7676
77- f (SD.DropDown msel opts) = do
78- msel' ← T .traverse (evalExpr fs.value) msel
79- opts' ← evalExpr fs.list opts
77+ f lbl (SD.DropDown msel opts) = do
78+ msel' ← T .traverse (evalExpr lbl fs.value) msel
79+ opts' ← evalExpr lbl fs.list opts
8080 pure $ SD.DropDown msel' $ M .maybe opts' (flip mergeSelection opts' <<< map L .singleton) msel'
8181
8282 mergeSelection ∷ SD.Expr (L.List a ) → SD.Expr (L.List a ) → SD.Expr (L.List a )
8383 mergeSelection (SD.Literal sel) (SD.Literal xs) = SD.Literal $ L .union sel xs
8484 mergeSelection _ exs = exs
8585
86- evalExpr ∷ ∀ e . ( String → m e ) → SD.Expr e → m (SD.Expr e )
87- evalExpr _ (SD.Literal a) = pure $ SD.Literal a
88- evalExpr e (SD.Unevaluated s) = SD.Literal <$> e s
86+ evalExpr ∷ ∀ e . String → ( String → String → m e ) → SD.Expr e → m (SD.Expr e )
87+ evalExpr _ _ (SD.Literal a) = pure $ SD.Literal a
88+ evalExpr l e (SD.Unevaluated s) = SD.Literal <$> e l s
8989
9090 getValues ∷ ∀ e . SD.Expr (L.List e ) → L.List e
9191 getValues (SD.Literal vs) = vs
0 commit comments