module Main where
import HAppS
import Data.Typeable
import Control.Monad.State (get, put)
auth :: Int -> IO Bool
auth id = return True
homepage :: String
homepage = "<form action=\"print\" method=\"post\"><p><label for=\"file\">File to print: </label><input type=\"text\" name=\"file\"><br><input type=\"submit\" value=\"Send\"> <input type=\"reset\"></p></input>"
data MyState = MySt { appVal :: Int } deriving (Read,Show,Typeable)
instance Serialize MyState where
encodeStringM = defaultEncodeStringM
decodeStringM = defaultDecodeStringM
$(inferStartState ''MyState)
instance FromReqURI [String] MyState where
fromReqURI expr uri
= do [val] <- fromReqURI (Prefix expr) uri
fmap MySt $ mbRead val
main = stdHTTP $ noState :
[
h [""] () $ ok $ val $ homepage,
h ["set"] GET $ ok $ \newVal () -> do put newVal; respond ("New value is " ++ show newVal)
]
uncommenting: h ["set"] GET $ ok $ \newVal () -> do respond ("New value is " ++ show newVal),
BlueTux:~/Desktop/Haskell/Guttemberg Phas$ ghc
[1 of 1] Compiling Main ( AuthTest.hs, AuthTest.o )
Loading package base ... linking ... done.
Loading package templatehaskell ... linking ... done.
Loading package haskell98 ... linking ... done.
Loading package HaXml1.13.2 ... linking ... done.
Loading package mtl1.0 ... linking ... done.
Loading package parsec2.0 ... linking ... done.
Loading package html1.0 ... linking ... done.
Loading package network2.0 ... linking ... done.
Loading package stm2.0 ... linking ... done.
Loading package regexbase0.71 ... linking ... done.
Loading package regexposix0.71 ... linking ... done.
Loading package regexcompat0.71 ... linking ... done.
Loading package binary0.2 ... linking ... done.
Loading package HList0.1 ... linking ... done.
Loading package HAppS0.8.8 ... linking ... done.
AuthTest.hs:33:8:
No instance for (FromReqURI [[Char]] a)
arising from use of `h' at AuthTest.hs:33:820
Possible fix:
add an instance declaration for (FromReqURI [[Char]] a)
In the first argument of `($)', namely `h ["set"] GET'
In the expression:
(h ["set"] GET)
$ (ok
$ (\ newVal () -> do respond ("New value is " ++ (show newVal))))
In the second argument of `(:)', namely
`[(h [""] ()) $ (ok $ (val $ homepage)),
(h ["set"] GET)
$ (ok
$ (\ newVal () -> do respond ("New value is " ++ (show newVal)))),
(h ["set"] GET)
$ (ok
$ (\ newVal ()
-> do put newVal
respond ("New value is " ++ (show newVal))))]'