Skip to content

Instantly share code, notes, and snippets.

@nobsun
nobsun / file0.txt
Last active February 3, 2017 12:41
Haskellで「ひらけ!ポンキッキ」 (文字列の回転) ref: http://qiita.com/nobsun/items/0f453affdcdd45f2982a
module Main where
import Data.List (tails)
rots :: String -> [String]
rots s = take n $ map (take n) $ tails $ cycle s
where
n = length s
main :: IO ()
permNth :: [a] -> Int -> [a]
perms :: [a] -> [[a]]
@nobsun
nobsun / file0.txt
Last active August 29, 2015 14:26
順列列挙関数(素朴な実装) ref: http://qiita.com/nobsun/items/babd28fe81ba3b9f304f
perms :: [a] -> [[a]]
import Control.Applicative ((<*>))
import Control.Arrow (first,(***))
runlength :: (Eq a) => [a] -> [(a,Int)]
runlength = hylo ((:) . runlen) [] null (span' . (==) . head <*> id)
runlen :: ([a],Int) -> (a,Int)
runlen = first head
hylo f e p g x = if p x then e else f y (hylo f e p g x')
@nobsun
nobsun / prob1-sum-using-fold.hs
Last active August 29, 2015 14:24
Haskellでやってみた -- あのプログラミングの5つのお題 ref: http://qiita.com/nobsun/items/0e1da260dd315c7a80ea
sumUsingFold :: Num a => [a] -> a
sumUsingFold = foldr (+) 0
sumUsingFold' :: Num a => [a] -> a
sumUsingFold' = foldl' (+) 0
@nobsun
nobsun / Environment.hs
Last active August 29, 2015 14:14
「環境とクロージャを用いた、より効率的な関数型プログラミング言語の定義&実装の仕方の例」をHaskellで実装してみた(その2) ref: http://qiita.com/nobsun/items/9ef785f88aff3e2cce0d
module Environment where
import Value
-- |
-- 環境
--
type Env = [(String, Value)]
emptyEnv :: Env
@nobsun
nobsun / EnvironmetClos
Created January 31, 2015 15:08
「環境とクロージャを用いた、より効率的な関数型プログラミング言語の定義&実装の仕方の例」をHaskellで実装してみた ref: http://qiita.com/nobsun/items/cbb780ffb68634873639
module EnvironmentClos where
import AbstractSyntax
-- |
-- 環境
type Env = [(String, Value)]
emptyEnv :: Env
emptyEnv = []
@nobsun
nobsun / AbstractSyntax.hs
Last active August 29, 2015 14:14
「関数型プログラミング言語の定義&実装の仕方の例」をHaskellで実装してみた ref: http://qiita.com/nobsun/items/5a88d37745e8d89a154a
module AbstractSyntax where
-- |
-- 構文
--
data Exp = Int Integer
| Var String
| Sub Exp Exp
| If Exp Exp Exp Exp
| Fun String Exp
@nobsun
nobsun / file0.txt
Created August 11, 2014 06:53
Haskellプログラミングのコツのようなもの(その2) ref: http://qiita.com/nobsun/items/c16417fdecd7f5c2f9fa
f . g $ x ≡ f $ g $ x -- (1)