3

我有以下类型:

data Cheese = Cheddar Int | Edam String String | Cottage String Int

data Meal = Meal {
      nameOfMeal :: String,
      ... other generic fields
      cheese :: Cheese
}

目前我的表格如下所示:

cheddarForm = renderTable $ construct 
             <$> areq textField "Name of meal" Nothing
             <*> areq intField "Cheddar fat" Nothing
      where 
          construct name fat = Meal name (Cheddar fat)

我目前对以下事实感到非常满意,即每种“奶酪”都需要一种形式(尽管我当然不介意使用动态形式..)。但是,我真的很想摆脱在每种形式中重复“用餐名称”。我可以以某种方式组合这些表格,还是我最终必须选择 Monadic 表格?

4

1 回答 1

3

你就不能随便转转吗

conWithNOM ctr = ctr
    <$> areq textField "Name of meal" Nothing

并针对您的其他表单字段调用它?

cheddarForm = renderTable $ conWithNOM construct
    <*> areq intField "Cheddar fat" Nothing
  where 
      construct name fat = Meal name (Cheddar fat)
于 2012-02-12T11:16:28.807 回答