Skip to content

Instantly share code, notes, and snippets.

Mitsuji, Takamasa mitsuji

Block or report user

Report or block mitsuji

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mitsuji
mitsuji / BWord.hs
Last active May 24, 2019
Word type supports Underflow/Overflow error
View BWord.hs
module Data.BWord(BWord(..),fromBWord) where
newtype BWord = BWord Integer
deriving (Eq,Ord,Show)
fromBWord :: BWord -> Integer
fromBWord (BWord x) = x
minBound' :: Integer
minBound' = fromIntegral (minBound::Word)
@mitsuji
mitsuji / BWord.hs
Created May 24, 2019
Word type supports Underflow/Overflow error
View BWord.hs
module Data.BWord(BWord(..),fromBWord) where
newtype BWord = BWord Integer
deriving (Eq,Ord,Show)
fromBWord :: BWord -> Integer
fromBWord (BWord x) = x
minBound' :: Integer
minBound' = fromIntegral (minBound::Word)
View queryCheck.hs
{-# LANGUAGE OverloadedStrings #-}
import Data.String (fromString)
import System.Environment (getArgs)
import qualified Network.Wai.Handler.Warp as Warp
import qualified Network.Wai as Wai
import qualified Network.HTTP.Types as H
import qualified Data.ByteString as BS -- use for input
import qualified Data.ByteString.Lazy as LBS -- use for out
View list.hs
type MemberId = Int
type ItemId = Int
data Sex = Man | Woman deriving (Show,Eq)
data Member = Member {
memberId :: MemberId
,memberName :: String
,memberSex :: Sex
View either.hs
import Data.Either (isLeft)
type Err = String
type ID = Int
type Rank = Int
type Name = String
type RankDB = [(Rank,ID)]
type NameDB = [(ID,Name)]
idFromRank :: RankDB -> Rank -> Either Err ID
View maybe.hs
import Data.Maybe (isNothing,fromJust)
type ID = Int
type Rank = Int
type Name = String
type RankDB = [(Rank,ID)]
type NameDB = [(ID,Name)]
idFromRank :: RankDB -> Rank -> Maybe ID
idFromRank db rk = lookup rk db
View reader.hs
import Data.List (foldl')
import Control.Monad.Reader (Reader,runReader,ask)
import Control.Monad (foldM)
main = do
print $ total 0.08 [(108,True,2),(200,False,1),(324,True,2),(400,False,1)]
print $ totalG [(108,True,2),(200,False,1),(324,True,2),(400,False,1)]
print $ totalR 0.08 [(108,True,2),(200,False,1),(324,True,2),(400,False,1)]
@mitsuji
mitsuji / bc.hs
Last active Aug 29, 2015
broadcast by STM
View bc.hs
import Control.Concurrent(forkIO,threadDelay)
import qualified Control.Concurrent.STM.TChan as TChan
import qualified Control.Monad.STM as STM
main = do
rp <- TChan.newTChanIO
bc <- TChan.newBroadcastTChanIO
forkIO $ broadcast bc
forkIO $ receive 0 rp bc
forkIO $ receive 1 rp bc
@mitsuji
mitsuji / pc.hs
Created Aug 19, 2015
Producer-Consumer by STM
View pc.hs
import Control.Concurrent(forkIO,threadDelay)
import qualified Control.Concurrent.STM.TChan as TChan
import qualified Control.Monad.STM as STM
main = do
rp <- TChan.newTChanIO
pc <- TChan.newTChanIO
forkIO $ produce pc
forkIO $ produce pc
forkIO $ produce pc
View pick.hs
{-# LANGUAGE PackageImports #-}
import Control.Monad
import Control.Applicative ((<$>),(<*>))
import "mtl" Control.Monad.RWS
import qualified System.Random as R
main = do
You can’t perform that action at this time.