takahashi icon indicating copy to clipboard operation
takahashi copied to clipboard

Maybe IntをNum型クラスのインスタンスにする

Open tokiwoousaka opened this issue 9 years ago • 0 comments

こんな感じ

instance Num a => Num (Maybe a) where
  l + r = (+) <$> l <*> r
  l * r = (*) <$> l <*> r
  l - r = (-) <$> l <*> r
  abs = fmap abs
  signum = fmap signum
  fromInteger = Just . fromInteger

Lensとの兼ね合いで便利になるぽよ。

tokiwoousaka avatar Mar 18 '15 18:03 tokiwoousaka