This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
↓こんな JSON データの変換 (Play framework 2.0.2) | |
{ | |
"users": [ | |
{ "name" : "krdlab", "point": 12345 }, | |
{ "name" : "hoge", "point": 2000 }, | |
... | |
] | |
} | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Control.Monad.Reader | |
{- | |
(1) local 関数の例 | |
local :: (r -> r) -> m a -> m a | |
r は Reader Monad が伝搬する読み取り値の型 | |
-} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE QuasiQuotes, TemplateHaskell, TypeFamilies, OverloadedStrings #-} | |
{-# LANGUAGE GADTs, FlexibleContexts #-} | |
import Database.Persist | |
import Database.Persist.MySQL | |
import Database.Persist.TH | |
import Control.Monad.IO.Class (liftIO) | |
import Data.Conduit | |
import qualified Data.Conduit.List as CL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Locale (defaultTimeLocale) | |
import Data.Time | |
-- 時刻をフォーマット | |
formatISO8601 :: ZonedTime -> String | |
formatISO8601 t = formatTime defaultTimeLocale "%FT%T%z" t | |
-- 時刻を表した文字列のパース (今回は Twitter の created_at) | |
parseCreatedAt :: String -> Maybe UTCTime | |
parseCreatedAt s = parseTime defaultTimeLocale "%a %b %d %H:%M:%S %z %Y" s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
import qualified System.IO.UTF8 as U | |
import Control.Applicative ((<$>), (<*>)) | |
import Control.Monad (mzero) | |
import Data.Aeson | |
import Data.Aeson.Types | |
import Data.Text (Text) | |
import qualified Data.Attoparsec as AP (Result(..), parseOnly) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Hoge = Hoge { get :: Int } | |
foo :: Hoge -> String | |
foo (Hoge _) = "foo!" | |
foo undefined | |
-- "*** Exception: Prelude.undefined |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad (forM_) | |
import Control.Concurrent | |
import Control.Concurrent.Chan | |
import Control.Concurrent.STM | |
import System.Random | |
postString :: Int -> IO () | |
postString num = do | |
ch <- atomically newTChan | |
forM_ [1..num] $ forkIO . worker ch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Concurrent | |
import Control.Concurrent.STM | |
import System.Random | |
countUp :: Int -> IO () | |
countUp num = do | |
counter <- atomically $ newTVar 0 | |
sequence_ $ replicate num $ forkIO $ worker counter | |
putStrLn "start..." | |
printWorkerOutput counter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sender := Object clone | |
sender start := method(f, t, r, | |
for(i, f, t, r post(i); yield; wait(Random value(2))) | |
) | |
receiver := Object clone | |
receiver post := method(val, | |
val println | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ThinHttpParser ( | |
HttpRequest(..), | |
Method(..), | |
parseRequest | |
) where | |
import Control.Applicative | |
import Control.Monad (MonadPlus(..), ap) | |
import Text.ParserCombinators.Parsec hiding (many, optional, (<|>)) | |
import Numeric (readHex) |
NewerOlder