{-# LANGUAGE NoImplicitPrelude #-} module Bamboo.Type.State where import qualified Bamboo.Type.Pager as Pager import Bamboo.Model.Tag import Random (randomRs, mkStdGen) import System.Time import Bamboo.Helper.PreludeEnv import Data.Default import Bamboo.Model.Post data State = State -- model state { uid :: String -- current view resource , pager :: Pager.Pager -- pager -- theme state , tags :: [Tag] , nav_location :: String , resource_title :: String , human_test_data :: HumanTestData , latest_posts :: [Post] } deriving (Show) show_left = human_test_data > left > show show_right = human_test_data > right > show show_op = human_test_data > op > display_op read_op "+" = Plus read_op "-" = Minus read_op x = error ("can not read operator: " ++ x) display_op Plus = "+" display_op Minus = "-" data HumanTestData = HumanTestData { left :: Int , right :: Int , op :: Op } deriving (Show) instance Default HumanTestData where def = HumanTestData def def def data Op = Plus | Minus deriving (Show) instance Default Op where def = Plus instance Default State where def = State def def def def def def def ops = [Plus, Minus] nums = [0, 5, 10, 15, 20] simple_eval a b Plus = a + b simple_eval a b Minus = a - b mk_human_test = do seed <- (getClockTime >>= toCalendarTime) ^ ctPicosec ^ from_i let (a,b,c) = randomRs (0,100) (mkStdGen seed) .in_group_of 3 .map make_sample .lb good_test .first return $ HumanTestData a b c where make_sample [a,b,c] = ((get_num a), (get_num b), (get_op c)) make_sample _ = error "human test sample fail" good_test = splash3 simple_eval > belongs_to nums get_num n = nums.at (n `mod` (nums.length)) get_op n = ops.at (n `mod` (ops.length))