关于 Haskell/HappStack 中语法和类型签名的新手问题
为什么我做不到,
z = x?
但我却能做到这一点?
y s = x s
我是哈斯克尔新手 这是我在 GHCi 中一直在尝试的:
Prelude> import Happstack.Server
Prelude Happstack.Server> let x s = ok $ toResponse $ "Some string"
Prelude Happstack.Server> :t x
x :: FilterMonad Response m => t -> m Response
Prelude Happstack.Server> let y s = x s
Prelude Happstack.Server> :t y
y :: FilterMonad Response m => t -> m Response
Prelude Happstack.Server> let z = x
<interactive>:1:9:
No instance for (FilterMonad Response m0)
arising from a use of `x'
Why is it that I can't do
z = x?
but I can do this?
y s = x s
I'm a Haskell newbie
This is what I've been trying in GHCi:
Prelude> import Happstack.Server
Prelude Happstack.Server> let x s = ok $ toResponse $ "Some string"
Prelude Happstack.Server> :t x
x :: FilterMonad Response m => t -> m Response
Prelude Happstack.Server> let y s = x s
Prelude Happstack.Server> :t y
y :: FilterMonad Response m => t -> m Response
Prelude Happstack.Server> let z = x
<interactive>:1:9:
No instance for (FilterMonad Response m0)
arising from a use of `x'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来像是单态限制的另一种情况。
您可以显式包含参数,即
ys = x s
,包含显式类型签名,或者使用-XNoMonomorphismRestriction
运行 GHCi。Looks like another case of the monomorphism restriction.
You can either include the argument explicitly, i.e.
y s = x s
, include an explicit type signature, or run GHCi with-XNoMonomorphismRestriction
.