Skip to content

Commit

Permalink
Clean warnings in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Rosén committed May 4, 2013
1 parent dea999e commit 0215a9a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 117 deletions.
13 changes: 2 additions & 11 deletions backend/Grid.hs
Expand Up @@ -4,21 +4,15 @@ module Grid where
import Data.HashSet (HashSet)
import qualified Data.HashSet as HS

import Control.Applicative

import Data.Maybe
import Data.List
import Data.Ord

import Control.Monad
import Control.Monad.Random
import Control.Monad.Random.Class

import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T

import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HM

import Data.Map (Map)
Expand Down Expand Up @@ -81,7 +75,7 @@ trigramsAround' t g x =

trigramsAround :: Trigrams -> Grid -> Coord -> [(Grid,Int)]
trigramsAround t g x = sortBy (flip $ comparing snd)
[ (g,x) | (g,Just x) <- trigramsAround' t g x]
[ (g',x') | (g',Just x') <- trigramsAround' t g x ]

-- Fails if there is no trigrams around this coordinate,
pickSomeTrigram :: MonadRandom m => Trigrams -> Grid -> m (Maybe Grid)
Expand All @@ -93,7 +87,7 @@ pickSomeTrigram t g = do
grids -> do
k <- getRandomR (2000,20000)
u <- getRandomR (5,20)
let grids' = filter (\(g,v) -> v > k && not (bad g)) grids
let grids' = filter (\(g',v) -> v > k && not (bad g')) grids
n = length grids' `div` u + 1
case grids' of
[] -> return Nothing
Expand Down Expand Up @@ -141,9 +135,6 @@ emptyGrid = replicate 4 " "
emptyPos :: Grid -> Coord -> Bool
emptyPos g x = g `at` x == ' '

neighbour :: Coord -> Coord -> Bool
neighbour (x,y) (x',y') = max (abs (x - x')) (abs (x + x')) == 1

neighbours :: Coord -> [Coord]
neighbours (x,y) = filter okCoord $ concat
[
Expand Down
28 changes: 6 additions & 22 deletions backend/Main.hs
@@ -1,5 +1,4 @@
{-# LANGUAGE OverloadedStrings, DeriveGeneric, GeneralizedNewtypeDeriving,
ViewPatterns, RecordWildCards #-}
{-# LANGUAGE RecordWildCards #-}
module Main where

import Prelude hiding (words)
Expand All @@ -8,34 +7,19 @@ import Data.Monoid (mconcat)
import Control.Monad.IO.Class (liftIO)

import Control.Applicative hiding ((<|>))
import Control.Monad.Random
import Control.Monad.Random.Class
import Control.Monad
import Control.Concurrent.STM

import Network.Wai.Middleware.RequestLogger (logStdout)
import Network.Wai.Middleware.Static
import Web.Scotty
import Web.Scotty hiding (next)

import Data.Aeson hiding (json)
import GHC.Generics

import Data.Maybe

import Network.WebSockets as WS
-- import Network

import Data.Map (Map)
import qualified Data.Map as M
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HM
import Data.HashSet (HashSet)
import qualified Data.HashSet as HS

import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T

import Control.Concurrent
import Data.Time.Clock
Expand Down Expand Up @@ -113,7 +97,7 @@ main = do
let (mod_score,mod_history)
| ok = ((+ value),((word_text,value):))
| otherwise = (id,id)
userMod name mod_score mod_history db
void $ userMod name mod_score mod_history db
return ok
return Response
{ correct = ok
Expand All @@ -137,7 +121,7 @@ main = do
(mg,users) <- atomically $ liftM2 (,) grid_var (readTVar db)
timeout <- calc_next_change
case mg of
Just grid -> do
Just{} -> do
let scores =
[ (u,user_score,user_words)
| (u,User{..}) <- M.toList users
Expand Down Expand Up @@ -165,7 +149,7 @@ main = do
print $ "ms to next change: " ++ show ms
return ms

forkIO $ forever $ do
void $ forkIO $ forever $ do
p <- atomically play_mode
let delay = if p then play_length else score_length
t0 <- getCurrentTime
Expand Down Expand Up @@ -197,7 +181,7 @@ main = do
(`withJust` sendToAll) =<< makeGridMsg

-- Web server
forkIO $ scotty 3000 $ do
void $ forkIO $ scotty 3000 $ do

middleware logStdout
middleware $ staticPolicy $ mconcat
Expand Down
83 changes: 0 additions & 83 deletions backend/Server.hs

This file was deleted.

2 changes: 1 addition & 1 deletion russell.cabal
Expand Up @@ -11,7 +11,7 @@ cabal-version: >=1.8

executable russell
main-is: Main.hs
ghc-options: -threaded -O2
ghc-options: -threaded -O2 -Wall
hs-source-dirs: backend
build-depends:
base >=4.5
Expand Down

0 comments on commit 0215a9a

Please sign in to comment.