08/09/24 18:03:09
>>773 は Control.Applicative を使って
soumeFunc <$> getArgs <*> getContents <*> getClockTime
や
return sumFunc <*> getArgs <*> getContents <*> getClockTime
って書ける。infixl 4 # ; (#)=(<*>) とすればあのままいける。
っていうのは
(return soumeFunc) #getArgs #getContents #getClockTime
じゃなくて
return (soumeFunc #getArgs #getContents #getClockTime)
のつもりだろうから嘘だけど。
ただ、IO は Applicative のインスタンスになってるけど、
一般のモナドは WrappedMonad って型が用意されてるだけなので、ちょっと面倒。
でも Control.Monad に <*> と同じ意味の ap ってのがあってこれはどのモナドにも使える。
<$> とかの Control.Applicative にあるいろいろな関数がないけど。
あと Control.Applicative には f (a -> b) -> a -> f b な関数が無いけど
それを f *$ x = f <*> pure x とか定義すれば
liftM3 otherFunc getArgs (return True) getContents は
otherFunc <$> getArgs *$ True <*> getContents と書ける。さすがにキモイ。