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 TemplateHaskell #-} | |
module Main where | |
import Control.Monad.State | |
import Control.Lens | |
type StateIO s a = StateT s IO a | |
data Hoge a = Hoge | |
{ _foo :: a | |
, _bar :: String |
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 :: Maybe Int | |
f = do | |
x <- return 5 | |
y <- return 3 | |
return $ x + y | |
f' :: Maybe Int | |
f' = do | |
x <- return 5 |
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.Monad.State | |
main :: IO () | |
main = print $ runState f 1000 --状態の初期値を1000にしてfを実行 | |
f :: State Int () | |
f = do | |
x <- sub1 | |
sub2 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
module Main where | |
import Control.Monad | |
type Season = String | |
type Fruit = String | |
type SeasonalFruits = [(Season, Fruit)] | |
dt :: SeasonalFruits | |
dt = | |
[ ("春", "いちご") |
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 #-} | |
{-# LANGUAGE RankNTypes #-} | |
module Main where | |
---- | |
-- Coyoneda | |
data CoYoneda f x = forall b. CoYoneda (b -> x) (f b) | |
instance Functor (CoYoneda f) 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
{-# LANGUAGE TemplateHaskell #-} | |
module Main where | |
import Control.Monad.State | |
import Control.Lens | |
data Point = Point | |
{ _pointX :: Int | |
, _pointY :: Int | |
} deriving Show |
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 RankNTypes #-} | |
module Main where | |
type Bool' = forall a. a -> a -> a | |
true :: Bool' | |
true = const | |
false :: Bool' | |
false = const id |
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 TemplateHaskell, RankNTypes #-} | |
module Main where | |
import Control.Lens | |
import Control.Monad.State | |
import Data.List | |
sample :: [String] | |
sample = | |
[ "hoge" | |
, "piyo" |
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
モナド則: (m >>= g) >>= h == m >>= (\x -> g x >>= h) | |
定義: f >=> g == \x -> f x >>= g | |
命題:(f >=> g) >=> h == f >=> (g >=> h) | |
(f >=> g) >=> h | |
== (\x -> f x >>= g) >=> h -- (>=>)の定義 | |
== \y -> (\x -> f x >>= g) y >>= h -- (>=>)の定義 | |
== \y -> (f y >>= g) >>= h | |
== \y -> f y >>= (\z -> g z >>= h) -- モナド則 | |
== \y -> f y >>= (g >=> h) -- (>=>)の定義 |
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
var move_rand_pos = function (obj) { | |
obj.x = rand(SCREEN_WIDTH - CHARACTER_WIDTH); | |
obj.y = rand(SCREEN_HEIGHT - CHARACTER_HEIGHT); | |
} |