{- |
Handling of warnings.
-}
module Sound.MIDI.Parser.Warning where

import qualified Sound.MIDI.Parser.Report as Report

import qualified Control.Monad.Exception.Synchronous as Sync
import qualified Control.Monad.Trans.Writer as Writer


type T m = Writer.WriterT [Report.UserMessage] m


run :: Monad m =>
   T m (Sync.Exceptional Report.UserMessage a) -> m (Report.T a)
run :: forall (m :: * -> *) a.
Monad m =>
T m (Exceptional UserMessage a) -> m (T a)
run T m (Exceptional UserMessage a)
act =
   do (Exceptional UserMessage a
exc,[UserMessage]
warns) <- forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
Writer.runWriterT T m (Exceptional UserMessage a)
act
      forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. [UserMessage] -> Either UserMessage a -> T a
Report.Cons [UserMessage]
warns (forall e a. Exceptional e a -> Either e a
Sync.toEither Exceptional UserMessage a
exc)

{-
run :: Monad m =>
   T m a -> m (a, [Report.UserMessage])
run = Writer.runWriterT
-}

warn :: Monad m => String -> T m ()
warn :: forall (m :: * -> *). Monad m => UserMessage -> T m ()
warn UserMessage
text = forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
Writer.tell [UserMessage
text]