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 (tails) | |
rots :: String -> [String] | |
rots s = take n $ map (take n) $ tails $ cycle s | |
where | |
n = length s | |
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
permNth :: [a] -> Int -> [a] |
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
perms :: [a] -> [[a]] |
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
perms :: [a] -> [[a]] |
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 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') |
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
sumUsingFold :: Num a => [a] -> a | |
sumUsingFold = foldr (+) 0 | |
sumUsingFold' :: Num a => [a] -> a | |
sumUsingFold' = foldl' (+) 0 |
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 Environment where | |
import Value | |
-- | | |
-- 環境 | |
-- | |
type Env = [(String, Value)] | |
emptyEnv :: Env |
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 EnvironmentClos where | |
import AbstractSyntax | |
-- | | |
-- 環境 | |
type Env = [(String, Value)] | |
emptyEnv :: Env | |
emptyEnv = [] |
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 AbstractSyntax where | |
-- | | |
-- 構文 | |
-- | |
data Exp = Int Integer | |
| Var String | |
| Sub Exp Exp | |
| If Exp Exp Exp Exp | |
| Fun String Exp |
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
f . g $ x ≡ f $ g $ x -- (1) |