- 日時
- 2014年5月5日(月)
- 集合
- うちにあるゲーム
- TOS リマスター
maybeApply :: Maybe a -> (a -> Maybe b) -> Maybe b | |
maybeApply Nothing _ = Nothing | |
maybeApply (Just x) f = f x | |
Just 3 `applyMaybe` \x -> Just (x+1) | |
Just "smile" `applyMaybe` \x -> Just (x ++ " :) ") | |
Nothing `applyMaybe` \x -> Just (x+1) |
class (Applicative m) => Monad m where | |
return :: a -> m a | |
(>>=) :: m a -> (a -> m b) -> m b | |
(>>) :: m a -> m b -> m b | |
x >> y = x >>= \_ -> y | |
fail :: String -> m a | |
fail msg = error msg |
type Birds = Int | |
type Pole = (Birds, Birds) | |
-- 左に鳥が止まる | |
landLeft :: Birds -> Pole -> Pole | |
landLeft n (left, right) = (left + n, right) | |
-- 右に鳥が止まる | |
landRight :: Birds -> Pole -> Pole | |
landRight n (left, right) = (left, right + n) |
type Birds = Int | |
type Pole = (Birds, Birds) | |
-- 左に鳥が止まる | |
landLeft :: Birds -> Pole -> Maybe Pole | |
landLeft n (left, right) | |
| abs ((left + n) - right) < 4 = Just (left + n, right) | |
| otherwise = Nothing | |
-- 右に鳥が止まる |
import Data.Maybe | |
data Term = TmVar Int Int {- deBruijn_index * term_length -} | |
| TmAbs String Term {- bound_var_name * partial_term -} | |
| TmApp Term Term {- arg_term * applying_term -} | |
| TmWrong String | |
deriving (Eq) | |
data Binding = NameBind |
module RunProcessSimple where | |
import Control.Concurrent | |
import System.Exit | |
import System.IO | |
import System.Posix.IO | |
import System.Posix.Process | |
import System.Posix.Types | |
import Control.Exception |
data Data = Data | |
{ dataID :: Int | |
, dataName :: String | |
, dataUrl :: String | |
} deriving (Show) | |
-- save :: Data -> (Data -> IO ()) -> IO () | |
-- save dat cont = do | |
-- print dat | |
-- cont (dat {dataID = 123, dataUrl = "/user/123"}) |
{-# LANGUAGE FlexibleInstances, FunctionalDependencies #-} | |
newtype MyState s a = MyState {runMyState :: s -> (a, s)} | |
instance Monad (MyState a) where | |
return a = MyState $ \s -> (a, s) | |
(MyState mys) >>= f = MyState $ \s -> let (a, s') = mys s in runMyState (f a) s' | |
class (Monad m) => MonadMyState s m | m -> s where | |
put :: s -> m () | |
get :: m s |