fix incomplete patterns warnings
[diohsc.git] / Util.hs
blobe79f0935efbd318537e16c2e4e62659ee7f87a35
1 -- This file is part of Diohsc
2 -- Copyright (C) 2020 Martin Bays <mbays@sdf.org>
3 --
4 -- This program is free software: you can redistribute it and/or modify
5 -- it under the terms of version 3 of the GNU General Public License as
6 -- published by the Free Software Foundation, or any later version.
7 --
8 -- You should have received a copy of the GNU General Public License
9 -- along with this program. If not, see http://www.gnu.org/licenses/.
12 {-# LANGUAGE Safe #-}
14 module Util where
15 import Control.Monad (unless, when)
17 -- nice tip from one joeyh:
18 whenM,unlessM,(>>?),(>>!) :: Monad m => m Bool -> m () -> m ()
19 whenM c a = c >>= flip when a
20 unlessM c a = c >>= flip unless a
21 (>>?) = whenM
22 (>>!) = unlessM
23 -- same precedence as ($), allowing e.g. foo bar >>! error $ "failed " ++ meep
24 infixr 0 >>?
25 infixr 0 >>!
27 maybeToEither :: e -> Maybe a -> Either e a
28 maybeToEither e = maybe (Left e) Right