- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一种向用户显示对话框的方法。
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)
ScopedTypeVariables
并在
confirmDialog
中输入默认配置如
DialogConfig t m a b
这行得通,但是即使没有它也不应该工作吗?在我看来,这些类型相当明确。
最佳答案
正如评论中提到的,问题在于记录更新可以改变记录的类型(起初可能会令人惊讶)。这是 GHCi 中的一个测试:
> data T a = T { tA :: a }
> let x = T "foo"
> :t x
x :: T [Char]
> :t x { tA = True }
x { tA = True } :: T Bool
> let def :: Read a => T a ; def = T (read "True")
> :t def :: T Bool
def :: T Bool :: T Bool
> :t def { tA = 5 }
Could not deduce (Read t0) arising from a use of ‘def’
The type variable ‘t0’ is ambiguous
def
可以是任何类型。
T a -> T a
来强制更新具有相同类型。延续功能。
> let defF :: Read a => (T a -> T a) -> T a ; defF f = f (T (read "True"))
> :t defF (\d -> d { tA = False })
defF (\d -> d { tA = False }) :: T Bool
d
是默认值,通过构造,更新后必须具有相同类型的记录。
关于haskell - 类型推断 - 无法推断出 Monad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36859279/
基础问题 我要解决的基本问题是: 我有一个模板参数包 ArgTypes,我需要用包装在 std::optional 中的每个类型创建一个元组。例如:make_optional_tuple应该返回 st
我使用 createEntityAdapter 设置了一个简单的 redux store。初始状态包含实体、ID、状态、错误设置等 const carouselEventAdapter = creat
我有一些(遗留)代码,如下所示: void castFoo(string type, void* foo) { FooA* foo_a = NULL; FooB* foo_b = NULL;
我的代码是 const int *const ptrA = nullptr; auto *ptrB = &ptrA; 我对 const int *const ptrA 的看法是: (*
我目前正在尝试用 C++ 实现 XOR 链表。我尝试使用模板使其通用。编译时会弹出此错误,我无法解决这个问题。 我尝试使用模板在谷歌上搜索 XOR 链表,但到目前为止似乎还没有实现它。 异或链表.h:
我正在尝试找到一种方法来调用多个类成员函数,每个函数都有不同的参数,并且在调用前后会发生某些已知功能。 这个包装函数是我试过的,但是例如对它的最终调用不会编译错误: 'bool Wrapper(Wor
此代码在 上编译成功g++ ( Coliru ) ,但不是 Visual C++ ( rextester ) - 在线和我的桌面。 它是一个更大的 Visual Studio 2015 项目的简化版本
我正在尝试编写一个通用类,它传递一个键 key 对应于一组已知接口(interface)中的一个的键,稍后可以传递一个对象 thing 并类型安全地访问 thing[key]。这是我得到的: inte
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我是一名优秀的程序员,十分优秀!