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)

私は現在、すべてのタイプの「チーズ」に 1 つのフォームが必要であるという事実に非常に満足しています (ただし、動的なフォームを使用してもかまいません..)。ただし、あらゆる形で「食事の名前」を繰り返すのは本当にやめたいと思います。どういうわけかフォームを組み合わせることができますか、それとも最終的にモナディックフォームを使用する必要がありますか?

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 に答える