This file contains 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 Data.List | |
import Data.Function | |
isSeq :: [Int] -> Bool | |
isSeq l = | |
let l' = sort l | |
in all (==(-1)) $ zipWith (-) l' (tail l') | |
longest :: [Int] -> [Int] | |
longest = maximumBy (compare `on` length) |
This file contains 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 Test (test) where | |
test :: [Int] -> Bool | |
test l = all (==(-1)) $ zipWith (-) l (tail l) | |
{- | |
ghc -ddump-simpl -O ghc-optimization.hs | |
after clean up: |
This file contains 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 Test where | |
import qualified Data.Vector as V | |
import qualified Data.HashMap.Strict as M | |
import Data.Hashable (Hashable) | |
type MyData k v = V.Vector (M.HashMap k v) | |
adjustVec :: Int -> (a -> a) -> V.Vector a -> V.Vector a | |
adjustVec ix f vec = |
This file contains 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 pymongo | |
db = pymongo.Connection('dev')['fund'] | |
db.system_js.update = ''' | |
function () { | |
db.test.find().forEach(function(obj) { | |
continue; | |
}); | |
} | |
''' | |
print db.system_js.update() |
This file contains 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 Data.ByteString.Char8 () | |
import Data.Monoid (mappend) | |
import qualified Blaze.ByteString.Builder as B | |
import Data.Conduit.Blaze (builderToByteString) | |
import Data.Conduit | |
import qualified Data.Conduit.List as CL | |
main :: IO () |
This file contains 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
diff --git a/Cabal/Distribution/Simple.hs b/Cabal/Distribution/Simple.hs | |
index 02a5255..c2a0859 100644 | |
--- a/Cabal/Distribution/Simple.hs | |
+++ b/Cabal/Distribution/Simple.hs | |
@@ -1,3 +1,4 @@ | |
+{-# LANGUAGE CPP #-} | |
----------------------------------------------------------------------------- | |
-- | | |
-- Module : Distribution.Simple | |
@@ -142,7 +143,10 @@ import Control.Monad (when) |
This file contains 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 ScopedTypeVariables #-} | |
import qualified Data.IntMap as M | |
import Data.IORef | |
import Data.Unique | |
{-- | |
- listen :: Event a -> (a -> IO ()) -> IO () | |
- fire :: Event a -> a -> IO () | |
-} |
This file contains 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 GADTs #-} | |
-- take `Monad` for example | |
class Monad m where | |
return :: a -> m a | |
(>>=) :: m a -> (a -> m b) -> m b | |
-- we can define an instance mechanically: | |
data IsMonad a where |
This file contains 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
sum' :: Int -> Int | |
sum' n = loop n 0 | |
where | |
loop 0 x = x | |
loop n x = loop (n-1) (x+n) | |
main = print $ sum' 1000000000 |
This file contains 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
$ python fight.py | |
-- 200(50) 200(50) <--> -- 200(50) 200(50) | |
200(50) 200(50) -- <--> 200(50) -- -- | |
-- -- 200(50) <--> -- 200(50) 200(50) | |
R2 -> L5 | |
普攻 | |
反击 | |
伤害 R2 45, L5 90 | |
-- 200(50) 200(50) <--> -- 200(50) 200(50) | |
200(50) 110(75) -- <--> 155(75) -- -- |