ユーザーにダイアログを表示する方法を構築しています。
data DialogConfig t m b e =
DialogConfig { _dialogConfig_title :: Dynamic t T.Text
, _dialogConfig_content :: b -> m (Dynamic t (Maybe b))
, _dialogConfig_footer :: Dynamic t (Maybe b) -> m (Event t e)
}
dialog :: MonadWidget t m =>
DialogConfig t m b e -> Event t b -> m (Event t (DialogEvent e))
関数の初期化にある種の「デフォルト」インスタンスを使用して、たとえばとして使用できるようにしたいとDialogConfig
思います。しかし、私は型推論と戦っています。これは機能します:dialog
defaultConfig{_dialogConfig_content=content}
confirmDialog :: forall t m. MonadWidget t m =>
T.Text -> Event t T.Text -> m (Event t ())
...
evt <- dialog
(DialogConfig { _dialogConfig_title = constDyn title
, _dialogConfig_content = content
, _dialogConfig_footer = buttons}
) contentEvt
ただし、デフォルトを使用するとDialogConfig
(たとえば、ここでは直接インライン化されます)、次のことはできません。
evt <- dialog
(DialogConfig { _dialogConfig_title = constDyn mempty
, _dialogConfig_content = const $ return $ constDyn Nothing
, _dialogConfig_footer = const $ return never }
{ _dialogConfig_title = constDyn title
, _dialogConfig_content = content
, _dialogConfig_footer = buttons}
) contentEvt
エラーは次のとおりです。
Could not deduce (Reflex t0) arising from a use of ‘constDyn’ from the context (MonadWidget t m)
Could not deduce (Monad t1) arising from a use of ‘return’ from the context (MonadWidget t m)
asScopedTypeVariables
でデフォルトの設定を使用して入力することはできますが、それがなくても動作するはずではありませんか? タイプはかなり明確であるように私には思えます。confirmDialog
DialogConfig t m a b