n3paste.de

::

a haskell happstack pastebin

  • New paste
  • View pastes

  • Login

  • About
  • Most recent pastes (filtered)

    Filter pastes (help):

    17:58 - Tue 2012.05.15

    Haskell

    Paste: /9T/Show related

    No description.

    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
    
    -- ...
    

    16:55 - Tue 2012.05.15

    Haskell

    Paste: /d0nJ/Show related

    Reply to /C1OV/

    -- Example:
    playerStats :: Player -> Block
    playerStats (Player name money mhand) =
      toBlock [ "Name: "
              , "Money: "
              , "Hand: " ]
      <|>
      toBlock [ name
              , show money
              , maybe "[hidden]" show mhand ]
    

    15:03 - Sun 2012.04.22

    Haskell

    Paste: /vW/Show related

    No description.

    --                  ID  Title     Body      Lang      Tags
    data Paste = Paste  Int [Char]    [Char]    [Char]    [[Char]]
    
    Pasta :: Paste -> [Char]
    Pasta (ID Title Body Lang Tags) = Title
    

    23:52 - Sun 2012.04.01

    Haskell

    Paste: /Xr/Show related

    Reply to /Hn/

    import Data.IORef
    
    inc x = modifyIORef x (+1)
    
    main = do
      x <- newIORef 1
      inc x
      inc x
      inc x
      print =<< readIORef x
    

    23:50 - Sun 2012.04.01

    Haskell

    Paste: /Hn/Show related

    No description.

    import Control.Monad.State
    
    inc = modify (+1)
    
    run = execState (inc >> inc >> inc) 1 -- 4
    

    09:39 - Thu 2012.03.29

    Haskell

    Paste: /1w/Show related

    No description.

    {-# 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
    
    

    00:44 - Thu 2012.03.29

    Haskell

    Paste: /wl/Show related

    Reply to /9E/

    {-# 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
    

    20:37 - Tue 2012.03.27

    Haskell

    Paste: /Urx/Show related

    No description.

    -- 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)
    

    20:16 - Tue 2012.03.27

    Haskell

    Paste: /DAvP/Show related

    No description.

    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]]
    

    01:07 - Mon 2012.03.05

    Haskell

    Paste: /fV/Show related

    No description.

    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
      ]
    

    16:38 - Wed 2012.02.08

    Haskell

    Paste: /x4P/Show related

    No description.

    delEven :: (Integral a) => [[a]] -> [[a]]
    delEven xss = [y | y <- [xs | xs <- xss], even y]
    

    23:36 - Tue 2012.02.07

    Haskell

    Paste: /PIH/Show related

    Reply to /wad/

    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)
    

    23:34 - Tue 2012.02.07

    Haskell

    Paste: /wad/Show related

    Reply to /dd/

    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)
    

    23:26 - Tue 2012.02.07

    Haskell

    Paste: /dd/Show related

    No description.

    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)
    

    12:25 - Tue 2012.02.07

    Haskell

    Paste: /uWc/Show related

    No description.

    e m = m * c ^ 2.0
      where
         c = 3 e 9
    

    21:59 - Mon 2012.02.06

    Haskell

    Paste: /5CW/Show related

    No description.

    constantSpeed :: Int
    cosntantSpeed = 260
    

    20:50 - Mon 2012.01.23

    Haskell

    Paste: /qmc/Show related

    Reply to /UcR/

    fibo' max = takeWhile (<= max) (f 0 1)
     where
      f a b = a+b : f b (a+b)
    

    20:09 - Mon 2012.01.23

    Haskell

    Paste: /UcR/Show related

    My fibo be ugly

    fibo :: Int -> Int -> Int -> [Int]
    fibo a b max = if a + b <= max
      then [a+b] ++ fibo b (a + b) max
      else []
    

    23:56 - Thu 2012.01.19

    Haskell

    Paste: /i9t/Show related

    No description.

    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
    

    20:03 - Wed 2012.01.18

    Haskell

    Paste: /Ekim/Show related

    Reply to /Y2/

    {-# OPTIONS -fno-warn-missing-signatures
                -fno-warn-type-defaults
                #-}
    
    --
    -- messwerte
    --
    
    delta = 808.0e6
    
    t = 423.15
    
    --
    -- rechnung
    --
    
    lambda = 780.25e-9
    k = 2 * pi / lambda
    
    u = 1.660538921e-27