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 TupleSections #-} | |
module Main where | |
import Data.Function.YaMemo (Memo, memo) | |
import Data.Map (Map) | |
main :: IO () | |
main = undefined |
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 (mapAccumR) | |
pascal :: [[Integer]] | |
pascal = [1] : [f cs | cs <- pascal ] | |
where | |
f xs = snd $ mapAccumR g xs' xs' | |
where xs' = 0:xs | |
g (y:ys) z = (ys, y+z) | |
comb :: Int -> Int -> Integer |
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 DelayList where | |
import Control.Concurrent (threadDelay) | |
import System.IO.Unsafe (unsafeInterleaveIO) | |
delayList :: Int -> [a] -> IO [a] | |
delayList _ [] = unsafeInterleaveIO $ return [] | |
delayList i (x:xs) | |
= unsafeInterleaveIO $ threadDelay i >> delayList i xs >>= return . (x:) |
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
$ sudo apt-get update | |
$ sudo apt-get upgrade |
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
deleteMin :: Ord a => [a] -> [a] | |
deleteMin xs@(x:_) = snd $ para f (x,[]) xs | |
where | |
f x (xs,(y,_)) | |
| x < y = (x,xs) | |
| otherwise = (y,x:xs) | |
para :: (a -> ([a],b) -> b) -> b -> [a] -> b | |
para _ z [] = z | |
para f z (x:xs) = f x (xs, para f z xs) |
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 Main where | |
import Data.List | |
main :: IO () | |
main = putStr | |
$ unlines | |
$ map (intercalate ".") | |
$ map (map reverse) -- 部分文字列反転 | |
$ unravels |
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
factorial :: Integer -> Integer | |
factorial (n+1) = (n+1) * factorial n | |
factorial 0 = 1 |
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
ghci> :set +s | |
ghci> patternIndex "abbbbcddddeefggg" "eagcdfbe" | |
5578864439 | |
(0.05 secs, 28983792 bytes) |
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 Main where | |
import Control.Applicative | |
import Data.Time | |
import Data.Time.Calendar.OrdinalDate | |
import Data.Time.Calendar.WeekDate | |
import System.Environment | |
main :: IO () | |
main = dispatch =<< getProgName |
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
data I a = I {unI :: a} | |
instance Functor I where | |
fmap f (I a) = I (f a) | |
instance Monad I where | |
return = I | |
I x >>= f = f x | |
foo :: [I a] -> I [a] |