Haskell Web Framework

做~自己de王妃 提交于 2019-12-24 00:01:34

问题


I'm creating simple web application using haskell. First I used Snap in front and I was able to run the application, but I want to add user input to the application.
I couldn't find a way to get user input parameters to the function. How might I do that?

Other thing, I also used Happstack framework, I can not import "Happstack.Server". I use cabal installation configure Happstack. It was successfully installed, but when I try to import to "Happstack.Server", it gives me an error:

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

If I run my program using ghc --make HelloWorld.hs -v, I get:

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:
...................

回答1:


Snap's getParam function allows you to get HTTP request parameters specified by the user. These can come in the post body of a form submission or from the query string. For example, consider the following code:

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

If I request the url "myapp.com/mypage?foo=bar", then I will see "bar" as the response. If I leave off the "?foo=bar" part, then it will return "no value".




回答2:


1) Check out that Happstack is actually installed and exposed:

ghc-pkg list | grep Happstack

2) What if you try to import Happstack.Server in ghci ?

3) Better use cabal-dev or capri for installing such things and making a sandbox

4) Snap and Yesod a quite new and they are under heavy development, Happstack is pretty stable and solid.

5) What OS are you using? How did your installed the haskell? Ubuntu + haskell 6.12 + Happstack work out of the box

Regarding to the log, seems that cabal packages are messed up somehow. I recommend you to remove all packages from the .cabal and .ghc, reinstall cabal, then install cabal-dev as explained here:

http://www.reddit.com/r/haskell/comments/f3ykj/psa_use_cabaldev_to_solve_dependency_problems/

and then have fun with Happstack. Some guys actually use capri, it works as well.




回答3:


Your installation is messed up. Unfortunately, cabal does that sometimes.

Your best bet is use 'ghc-pkg unregister ' to remove all the happstack packages, hslogger, and sendfile. Make sure they are removed from the user and global package databases. (ghc-pkg list will show you what is installed). Once you have the old versions removed, do, cabal update and the cabal install happstack. Then things should work.

What do you mean by 'user input' ? Do you mean html forms? Or something else ?

This section of the crash course may address your needs:

http://www.happstack.com/docs/crashcourse/RqData.html

It is also possible to use digestive-functors with Happstack to get type-safe form processing. Unfortunately, this is not well documented yet. Though I believe the disgestive-functors source code does include a working Happstack example.



来源:https://stackoverflow.com/questions/5740746/haskell-web-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!