2009-07-01から1ヶ月間の記事一覧

モナド則1(左単位元)を満たさない偽リストモナド

import Monad(liftM) data MyList a = My { unMy :: [a] } deriving (Show,Eq) instance Monad MyList where return x = My [x,x] (My xs) >>= k = My $ xs >>= (unMy.k) -- sample f x = My [x,x+1] とすると > return 2 >>= f My {unMy = [2,3,2,3]} > f 2…

モナド則3(結合律)を満たさない偽リストモナド

bind [] _ = [] bind [x] k = k x bind xs@(x:_) k = case k x of [_] -> xs >>= k otherwise -> reverse $ xs >>= k data MyList a = My { unMy :: [a] } deriving (Show,Eq) instance Monad MyList where return x = My [x] (My xs) >>= k = My $ xs `bind…