content: {-
  Copyright (c) 2015, Dan Rosén
  Copyright (c) 2016, Nick Smallbone
  
  All rights reserved.
  
  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:
  
      * Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
  
      * Redistributions in binary form must reproduce the above
        copyright notice, this list of conditions and the following
        disclaimer in the documentation and/or other materials provided
        with the distribution.
  
      * Neither the name of the copyright holder nor the names of other
        contributors may be used to endorse or promote products derived
        from this software without specific prior written permission.
  
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -}
  -- File generated by the BNF Converter (bnfc 2.9.4).
  
  {-# LANGUAGE CPP #-}
  
  #if __GLASGOW_HASKELL__ >= 708
  ---------------------------------------------------------------------------
  -- Pattern synonyms exist since ghc 7.8.
  
  -- | BNF Converter: Error Monad.
  --
  -- Module for backwards compatibility.
  --
  -- The generated parser now uses @'Either' String@ as error monad.
  -- This module defines a type synonym 'Err' and pattern synonyms
  -- 'Bad' and 'Ok' for 'Left' and 'Right'.
  
  {-# LANGUAGE PatternSynonyms #-}
  {-# LANGUAGE FlexibleInstances #-}
  
  module TIP.ErrM where
  
  import Prelude             (id, const, Either(..), String)
  
  import Control.Monad       (MonadPlus(..))
  import Control.Applicative (Alternative(..))
  #if __GLASGOW_HASKELL__ >= 808
  import Control.Monad       (MonadFail(..))
  #endif
  
  -- | Error monad with 'String' error messages.
  type Err = Either String
  
  pattern Bad msg = Left msg
  pattern Ok  a   = Right a
  
  #if __GLASGOW_HASKELL__ >= 808
  instance MonadFail Err where
    fail = Bad
  #endif
  
  instance Alternative Err where
    empty           = Left "Err.empty"
    (<|>) Left{}    = id
    (<|>) x@Right{} = const x
  
  instance MonadPlus Err where
    mzero = empty
    mplus = (<|>)
  
  #else
  ---------------------------------------------------------------------------
  -- ghc 7.6 and before: use old definition as data type.
  
  -- | BNF Converter: Error Monad
  
  -- Copyright (C) 2004  Author:  Aarne Ranta
  -- This file comes with NO WARRANTY and may be used FOR ANY PURPOSE.
  
  module TIP.ErrM where
  
  -- the Error monad: like Maybe type with error msgs
  
  import Control.Applicative (Applicative(..), Alternative(..))
  import Control.Monad       (MonadPlus(..), liftM)
  
  data Err a = Ok a | Bad String
    deriving (Read, Show, Eq, Ord)
  
  instance Monad Err where
    return      = Ok
    Ok a  >>= f = f a
    Bad s >>= _ = Bad s
  
  instance Applicative Err where
    pure = Ok
    (Bad s) <*> _ = Bad s
    (Ok f) <*> o  = liftM f o
  
  instance Functor Err where
    fmap = liftM
  
  instance MonadPlus Err where
    mzero = Bad "Err.mzero"
    mplus (Bad _) y = y
    mplus x       _ = x
  
  instance Alternative Err where
    empty = mzero
    (<|>) = mplus
  
  #endif
  