gpt4 book ai didi

Haskell Web 框架

转载 作者:行者123 更新时间:2023-12-02 14:20:02 34 4
gpt4 key购买 nike

我正在使用 haskell 创建简单的 Web 应用程序。首先,我在前面使用了 Snap,并且能够运行应用程序,但我想将用户输入添加到应用程序中。
我找不到一种方法来获取函数的用户输入参数。我该怎么做?

另一件事,我也使用了Happstack框架,我无法导入“Happstack.Server”。我使用 cabal 安装配置 Happstack。它已成功安装,但是当我尝试导入到“Happstack.Server”时,出现错误:

<no location info>:
Could not find module `Happstack.Server':
it is not a module in the current program, or in any known package.

如果我使用 ghc --make HelloWorld.hs -v 运行我的程序,我会得到:

Glasgow Haskell Compiler, Version 6.12.1, for Haskell 98, stage 2 booted by GHC version 6.12.1
Using binary package database: /usr/lib/ghc-6.12.1/package.conf.d/package.cache
Using binary package database: /home/udeshika/.ghc/i386-linux-6.12.1/package.conf.d/package.cache
package happstack-6.0.0-0f0c2507d590ebd01e8601c8667ec809 is unusable due to missing or recursive dependencies:
happstack-ixset-6.0.0-4e1b5476a551c4501c5734b22e0b280d happstack-server-6.0.3-6d71e7bb09489130538fb851a694b927 happstack-state-6.0.0-0e753e61d7092b6a5139e473113877a1 happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c
package happstack-ixset-6.0.0-4e1b5476a551c4501c5734b22e0b280d is unusable due to missing or recursive dependencies:
happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c
package happstack-server-6.0.3-6d71e7bb09489130538fb851a694b927 is unusable due to missing or recursive dependencies:
happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9 network-2.2.1.7-72dad7eb07ee7a683982f7475b8a449f network-bytestring-0.1.3.4-937fd511949a2d5ef21e86ec5306c791 sendfile-0.7.3-137cf51cc81a277d724637a7cd1e6b09
package happstack-state-6.0.0-0e753e61d7092b6a5139e473113877a1 is unusable due to missing or recursive dependencies:
happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9
package happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c is unusable due to missing or recursive dependencies:
hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9 network-2.2.1.7-72dad7eb07ee7a683982f7475b8a449f
package hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9 is unusable due to missing or recursive dependencies:
...................

最佳答案

Snap 的 getParam函数允许您获取用户指定的HTTP请求参数。这些可以来自表单提交的帖子正文或来自查询字符串。例如,考虑以下代码:

site = dir "mypage" pageHandler
pageHandler = do
val <- getParam "foo"
writeBS $ maybe "no value" id val

如果我请求 url“myapp.com/mypage?foo=bar”,那么我将看到“bar”作为响应。如果我省略“?foo=bar”部分,那么它将返回“无值”。

关于Haskell Web 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5740746/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com