简体   繁体   English

关于Haskell / HappStack中语法和类型签名的新手问题

[英]Newbie question on syntax and type signature in Haskell/HappStack

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: 我是Haskell新手这是我在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'

Looks like another case of the monomorphism restriction . 看起来像单态限制的另一种情况。

You can either include the argument explicitly, ie ys = xs , include an explicit type signature, or run GHCi with -XNoMonomorphismRestriction . 您可以显式包含参数,即ys = xs ,包含显式类型签名,或使用-XNoMonomorphismRestriction运行GHCi。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM