hlint
[htalkat.git] / Mundanities.hs
blob20ceae1085623621e664fad66b7429320b5473ea
1 -- This file is part of htalkat
2 -- Copyright (C) 2021 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/.
11 {-# LANGUAGE Safe #-}
13 module Mundanities where
15 import Control.Applicative (Alternative, empty)
16 import Control.Monad.Catch (MonadMask, handle)
17 import Control.Monad.IO.Class (MonadIO, liftIO)
18 import System.Directory
19 import System.FilePath
21 -- |returns true iff path is contained within the directory dir
22 isSubPath :: FilePath -> FilePath -> IO Bool
23 isSubPath dir path = isRelative . makeRelative dir <$> canonicalizePath path
25 ignoreIOErr :: (MonadIO m, MonadMask m, Monoid a) => m a -> m a
26 ignoreIOErr = handle ((\_ -> return mempty) :: (Monad m, Monoid a) => IOError -> m a)
28 warnIOErr :: (MonadIO m, MonadMask m, Monoid a) => m a -> m a
29 warnIOErr = handle ((\e -> liftIO (print e) >> return mempty) :: (MonadIO m, Monoid a) => IOError -> m a)
31 ignoreIOErrAlt :: (MonadIO m, MonadMask m, Alternative f) => m (f a) -> m (f a)
32 ignoreIOErrAlt = handle ((\_ -> return empty) :: (Monad m, Alternative f) => IOError -> m (f a))
34 warnIOErrAlt :: (MonadIO m, MonadMask m, Alternative f) => m (f a) -> m (f a)
35 warnIOErrAlt = handle ((\e -> liftIO (print e) >> return empty) :: (MonadIO m, Alternative f) => IOError -> m (f a))