2009-08-06から1日間の記事一覧

大文字・小文字の反転(その2)

[id:mzp:20090804#maybe]Maybeで繋げるなら,こんな感じかな. import Control.Monad import Data.Char import Data.Maybe affect :: (MonadPlus m, Eq a) => (a -> a) -> a -> m a f `affect` x = if fx == x then mzero else return fx where fx = f x inv…

大文字・小文字の反転(その1)

[id:mzp:20090804#invert]変換関数を直接作るなら,こんな感じかな. import Control.Arrow lowers = ['a'..'z'] uppers = ['A'..'Z'] exFun :: Eq a => (a,b) -> (a -> b) -> a -> b exFun (x,y) f x' = if x == x' then y else f x' invertChar :: Char ->…