Skip to content

Instantly share code, notes, and snippets.

@co-dan co-dan/Home.hs
Last active Aug 29, 2015

Embed
What would you like to do?
cabal install
Resolving dependencies...
Configuring haskellfun-0.0.1...
Building haskellfun-0.0.1...
Preprocessing executable 'haskellfun' for haskellfun-0.0.1...
[2 of 3] Compiling Controllers.Home ( Controllers/Home.hs, dist/dist-sandbox-ef4979d3/build/haskellfun/haskellfun-tmp/Controllers/Home.o )
Controllers/Home.hs:15:16:
Couldn't match expected type `Database.RethinkDB.NoClash.RethinkDBHandle'
with actual type `IO Database.RethinkDB.NoClash.RethinkDBHandle'
In the first argument of Database.RethinkDB.NoClash.run', namely
`conn'
In the expression: Database.RethinkDB.NoClash.run' conn
In the expression:
Database.RethinkDB.NoClash.run' conn
$ Database.RethinkDB.NoClash.dbCreate "haskellfun"
Controllers/Home.hs:16:16:
Couldn't match expected type `Database.RethinkDB.NoClash.RethinkDBHandle'
with actual type `IO Database.RethinkDB.NoClash.RethinkDBHandle'
In the first argument of `Database.RethinkDB.NoClash.run', namely
`conn'
In the expression: Database.RethinkDB.NoClash.run conn
In the expression:
Database.RethinkDB.NoClash.run conn
$ Database.RethinkDB.NoClash.dbList ::
IO (Maybe [String])
Failed to install haskellfun-0.0.1
cabal: Error: some packages failed to install:
haskellfun-0.0.1 failed during the building phase. The exception was:
ExitFailure 1
{-# LANGUAGE OverloadedStrings #-}
module Controllers.Home (homeRoutes) where
import Web.Scotty
import Data.Monoid (mconcat)
import qualified Database.RethinkDB as R
import qualified Database.RethinkDB.NoClash
homeRoutes :: ScottyM ()
homeRoutes = do
conn <- liftIO $ R.connect "localhost" 28015 Nothing
setDb <- liftIO $ R.run' conn $ R.dbCreate "haskellfun"
getDbs <- liftIO $ R.run conn $ R.dbList
get "/" $ do
dbs <- getDbs
html $ mconcat ["<form action='/' method='post'><input type='text' name='name'></input><input type='submit'></input></form>"]
post "/" $ do
name <- param "name"
redirect $ mconcat ["/home/", name]
get "/home/:word" $ do
beam <- param "word"
html $ mconcat ["<h1>Scotty, ", beam, " me up home!</h1>"]
{-# LANGUAGE OverloadedStrings #-}
import Web.Scotty
import Data.Monoid (mconcat)
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
-- Controllers
import Controllers.Home (homeRoutes)
main = scotty 3000 $ do
middleware logStdoutDev
homeRoutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.