Most recent pastes (filtered)
newGame :: [Player] -> Player -> Poker () newGame players player = do currentplayer <- pickRandom players put (emptyGame player currentplayer players) payBlinds giveCards payBlinds :: Poker () payBlinds = do (small,big) <- gets blinds bet small nextPlayer bet big nextPlayer -- ...
-- Example: playerStats :: Player -> Block playerStats (Player name money mhand) = toBlock [ "Name: " , "Money: " , "Hand: " ] <|> toBlock [ name , show money , maybe "[hidden]" show mhand ]
-- ID Title Body Lang Tags data Paste = Paste Int [Char] [Char] [Char] [[Char]] Pasta :: Paste -> [Char] Pasta (ID Title Body Lang Tags) = Title
import Data.IORef inc x = modifyIORef x (+1) main = do x <- newIORef 1 inc x inc x inc x print =<< readIORef x
{-# LANGUAGE BangPatterns #-} import Control.Monad import System.Random -------------------------------------------------------------------------------- -- * Configuration -- Size of our L=100 lattice n :: Int n = 100 -- All values for mu that should be tested in units of v0 mus :: [Double] mus = map (/10) [1..40] -- Temperature beta :: Double beta = 1
{-# LANGUAGE BangPatterns #-} import Control.Monad import System.Random -------------------------------------------------------------------------------- -- * Configuration -- Size of our lattice n :: Int n = 2 -- All values for mu that should be tested in units of v0 mus :: [Double] mus = [1.07, 4.48388, 0,1,2,3,4] beta :: Double beta = 1 -- Number of steps in our MC loop
-- this loop runs fine for few steps (~1000), but fails with 'Stack space overflow' for ~100000 steps: loop :: RandomGen g => Int -> g -> [[Int]] -> [[Int]] loop step g l | step >= steps = l | otherwise = do let (p, g') = pickRandom g -- pickRandom :: RandomGen g => g -> (Int,Int) l' = flipValue p l -- flipValue :: (Int,Int) -> [[Int]] -> [[Int]] deltaE = energy l' - energy l -- energy :: [[Int]] -> Int (i, g'') = randomR (0,1) g' accept = deltaE <= 0 || i <= minimum [ 1, exp(-(fromIntegral deltaE)*beta) ] in loop (step+1) g'' (if accept then l' else l)
import Control.Monad.Trans import System.Random -------------------------------------------------------------------------------- -- * Configuration -- Size of our lattice n :: Int n = 2 -- Constants beta :: Double beta = 1 -------------------------------------------------------------------------------- -- * Code type Lattice = [[Int]]
import Control.Monad import Control.Monad.Trans import Data.Time import System.Directory import Happstack.Server import Text.Blaze (toHtml, toValue, (!)) import Text.Blaze.Html5 (docTypeHtml, p, img) import Text.Blaze.Html5.Attributes (src) main :: IO () main = simpleHTTP nullConf $ msum -- handle all file uploads first [ handleFileUpload -- serve static files if they exist , serveDirectory DisableBrowsing ["index.html"] "." -- if no file upload is done look for "/funny-picture.jpg" and (try) to show this , listPictures ]
len :: [a] -> Int len [] = 0 len (_:xs) = 1 + len xs sum' :: Num a => [a] -> a sum' [] = 0 sum' (x:xs) = x + sum' xs avrg :: (Real a, Fractional b) => [a] -> b avrg l = realToFrac (sum' l) / fromIntegral (len l) foo :: [Int] foo = [1,2,3,4,5] bar :: [Double] bar = [1,2,3,4,5] main :: IO () main = print (avrg foo, avrg bar)
len :: [a] -> Int len [] = 0 len (_:xs) = 1 + len xs sum' :: Num a => [a] -> a sum' [] = 0 sum' (x:xs) = x + sum' xs avrg :: (Fractional a) => [a] -> a avrg l = sum' l / fromIntegral (len l)
len :: [a] -> Int len [] = 0 len (_:xs) = 1 + len xs sum' :: Num a => [a] -> a sum' [] = 0 sum' (x:xs) = x + sum' xs avrg :: (Num a, Integral a, Fractional b) => [a] -> b avrg l = fromIntegral (sum' l) / fromIntegral (len l)
fibo :: Int -> Int -> Int -> [Int] fibo a b max = if a + b <= max then [a+b] ++ fibo b (a + b) max else []
import Control.Monad.State -- type variables newtype Var = Var { unVar :: String } deriving (Eq) -------------------------------------------------------------------------------- -- Types type TyVar = Var tyVar :: String -> TyVar tyVar = Var -- inspired by GHCs type representation data Type = TyVar TyVar | TyForAll TyVar Type | TyDep (DepTy Int Type) | TyApp Type Type