Functor → Applicative Functor → Monad
ghci> :t fmap
{-# OPTIONS -Wall -Werror #-} | |
{- | |
https://gist.github.com/fujiyan/483893d875ff7e350ef1 | |
-} | |
data Warrior = Warrior { attack :: Int } deriving (Show) | |
data Monster = Monster { hitPoint :: Int, defence :: Int } deriving (Show) | |
data Attack = Normal | Critical | Gira | Begirama | |
damage :: Warrior -> Monster -> Attack -> Int | |
damage (Warrior a) (Monster _ d) Normal |
import Data.Char | |
import System.Environment | |
myLength :: String -> Int | |
myLength [] = 0 | |
myLength (x:xs) = if isAscii x then 1 else 2 + myLength xs | |
main = do | |
args <- getArgs | |
let shi = if null args then "死" else args !! 0 |
import Control.DeepSeq | |
import Data.Char(toUpper) | |
main = do | |
str <- readFile "inout.txt" | |
str `deepseq` writeFile "inout.txt" (map toUpper str) | |
{- | |
% runghc toUpper.hs | |
-} |
#include <stdio.h> | |
int main() | |
{ | |
if (int x = 0) { | |
printf("true: %d\n", x); | |
//printf("true: %d, ?: %d\n", x, y); // ‘y’ was not declared in this scope | |
} else if (int y = 0) { | |
printf("false: %d, true: %d\n", x, y); | |
} else { | |
printf("false: %d, false: %d\n", x, y); |
# based on the example in https://docs.python.org/2.7/library/multiprocessing.html | |
from multiprocessing import Process, Queue, Manager | |
def f(q): | |
q.put('X' * 1000000) | |
if __name__ == '__main__': | |
manager = Manager() | |
queue = manager.Queue() | |
p = Process(target=f, args=(queue,)) |
#!/bin/bash | |
BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
REMOTE=$(git config --get branch.${BRANCH}.remote) | |
if [ -z ${REMOTE} ]; then | |
echo "no remote" | |
exit -1 | |
fi | |
git fetch | |
if [ $? != 0 ]; then |