Skip to content

Instantly share code, notes, and snippets.

@nobsun
nobsun / file0.txt
Last active July 1, 2019 21:52
Haskellプログラミングのコツのようなもの ref: https://qiita.com/nobsun/items/ed33c22203734e706e9b
main = interact gonyo
@nobsun
nobsun / excelColns.hs
Created August 8, 2014 00:23
Excelカラム名の生成(改) ref: http://qiita.com/nobsun/items/fbb9bcda0bf5c65b4e8d
import Control.Monad (liftM2)
excelColns :: [String]
excelColns = concat $ tail $ iterate (liftM2 (:) ['A'..'Z']) [""]
(foldr (⊕) z .) . zipWith (⊗)
foldr (⊛) (const z)
where
(x ⊛ k) [] = z
(x ⊛ k) (y:ys) = (x ⊗ y) ⊕ k ys
ssum :: Num a => [a] -> [a] -> a
ssum = foldr f (const 0)
where
f x g [] = 0
f x g (y:ys) = x * y + g ys
import Control.Parallel.Strategies
x,y :: Int
x = repeat 0 !! 1000000000
y = repeat 1 !! 1000000000
foo :: Eval Int
foo = do { rpar x; rpar y; return 2 }
{-
% ghci -v0 rpar.hs
@nobsun
nobsun / strictList.hs
Last active August 29, 2015 14:02
リストを(非)正格に構成する
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]
@nobsun
nobsun / today.hs
Created February 20, 2014 01:05
今日の日付をISO 8601形式で表示する ref: http://qiita.com/nobsun/items/a01b96cbf5775f7959b7
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
@nobsun
nobsun / file1.txt
Created February 13, 2014 11:35
ジェムストリング問題 ref: http://qiita.com/nobsun/items/efe6a8965f5a5bfe5d41
ghci> :set +s
ghci> patternIndex "abbbbcddddeefggg" "eagcdfbe"
5578864439
(0.05 secs, 28983792 bytes)
@nobsun
nobsun / file0.txt
Created December 24, 2013 07:12
Haskell コード片鑑賞:「再帰」編 ref: http://qiita.com/nobsun/items/6c2fa63f294dbd98d5cb
factorial :: Integer -> Integer
factorial (n+1) = (n+1) * factorial n
factorial 0 = 1
module Main where
import Data.List
main :: IO ()
main = putStr
$ unlines
$ map (intercalate ".")
$ map (map reverse) -- 部分文字列反転
$ unravels