2

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:
...................
Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
123Ex
  • 906
  • 2
  • 21
  • 34
  • While we are at web frameworks, have you checked out yesod? My personal opinion is that it looks around 100x more promising than snap and happstack together. Why? Because it's more active, I see daily pushes and blog posts every week for Yesod. Link: http://www.yesodweb.com/ – Tarrasch Apr 21 '11 at 08:35
  • 1) ghc-pkg list 2) what if: ghci >import Happstack.Server – voidlizard Apr 21 '11 at 08:53
  • thanxx for the reply,I tried with yesod ,@Tarrasch I can not install yesod that give an configuration error when I try to install that – 123Ex Apr 21 '11 at 08:57
  • thaxx for the reply @voidizard,I did not get what you have said here,I tried with 1) one it shows all ghci packages,what is the 2) ??? – 123Ex Apr 21 '11 at 09:03
  • Look at my answer below. Seems the cabal packages are messed -- it's happen quite often. I use cabal-dev to make new projects in a sanbox, without affecting global packages. If you do not want to deal with sandbox, just try to sweep all packages out, install cabal and then install Happstack. It should work then. But if you do not want to do it often, then use cabal-dev or capri – voidlizard Apr 21 '11 at 09:08
  • I moved away from yesod for the same reasons.. impossible to install! – Melsi Dec 13 '12 at 11:53

3 Answers3

4

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

mightybyte
  • 7,282
  • 3
  • 23
  • 39
3

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.

voidlizard
  • 805
  • 5
  • 10
  • thanxx for the reply,I think Happstack is not installed well.But when I use >cabal install happstack it says "No packages to be installed. All the requested packages are already installed. If you want to reinstall anyway then use the --reinstall flag" I'm using fedora 13 ,installed using yum – 123Ex Apr 21 '11 at 09:13
  • what if you try to import Happstack.Server in ghci ? – voidlizard Apr 21 '11 at 09:17
  • Prelude> import Happstack.Server : Could not find module `Happstack.Server': it is not a module in the current program, or in any known package. Is this correct link??? – 123Ex Apr 21 '11 at 09:22
  • The link is correct. You have a problem with dependencies. Personally, I solve thouse problem by: 1) sweeping $HOME/.cabal and $HOME/.ghc directories and reinstalling cabal and then reinstalling cabal from hackage. Probably it you will install the Happstack after that, it will work. If you do not want to do all thouse operations too often, it's better to use cabal-dev tool to make sandboxes to play with packages without affecting the system. – voidlizard Apr 21 '11 at 09:28
  • hmm,sounds like pretty interesting,If I remove .ghc do I need to install ghc again??,I think link is not working for me,there is a video on that site,I couldn't see any haskell related thing on that,I really appreciate your help thank you very much, – 123Ex Apr 21 '11 at 09:44
  • Just back up your .ghc and .cabal if you doubt. Seems that you will need to install again only cabal-install – voidlizard Apr 21 '11 at 09:46
  • Hi,I have reinstalled cabal and happstack,1) ghc-pkg list | grep happstack ,I can see the happstack libraries but I problem is not solved.It give same error,What can I do to this?? – 123Ex Apr 21 '11 at 10:15
  • Did you install cabal with yum? Did you reinstall cabal from the Hackage (and put $HOME/.cabal/bin to PATH before /usr/bin ?) – voidlizard Apr 21 '11 at 10:23
  • There is no bin folder within the .cabal folder.What can I do now ?? – 123Ex Apr 21 '11 at 12:17
  • Now I try to run cabal install,it gives an error telling "cabal: cannot configure hint-0.3.3.2. It requires ghc >6.6 There is no available version of ghc that satisfies >6.6", But I'm using ghc version 6.12.1 – 123Ex Apr 21 '11 at 12:24
  • Ouch. Seems that Fedora is quite different. Well, now I'm close to give up. I'm facing the problems with dependencies almost every day, probably I should not have to be so sure that they may be easily fixed everywhere. For me, it's always work to sweep the package directories and install required packages from the scratch. The last idea --- may be it's better to install a haskell-platform if you have not done this yet. Too bad but I have no Fedora installation somewhere around to try it myself. – voidlizard Apr 21 '11 at 13:09
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.

stepcut
  • 1,502
  • 8
  • 10