--------------------------------------------------------------------------------
-- |
-- Module      :  Data.SignedMultiset.Show
-- Copyright   :  (c) 2012 Stefan Holdermans
-- License     :  BSD-style
-- Maintainer  :  stefan@vectorfabrics.com
-- Stability   :  provisional
-- Portability :  portable
--
-- Pretty-print utilities for signed multisets.
--
--------------------------------------------------------------------------------

module Data.SignedMultiset.Show (

  showsMembers  -- :: Show a => [(a, Int)] -> ShowS

) where

showsMembers :: Show a => [(a, Int)] -> ShowS
showsMembers :: forall a. Show a => [(a, Int)] -> ShowS
showsMembers []       = (String
"{}" forall a. [a] -> [a] -> [a]
++)
showsMembers ((a, Int)
x : [(a, Int)]
xs) = forall a. a -> [a] -> [a]
cons Char
'{' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => (a, Int) -> ShowS
showsMember (a, Int)
x forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => [(a, Int)] -> ShowS
go [(a, Int)]
xs
  where
    go :: [(a, Int)] -> ShowS
go []       = forall a. a -> [a] -> [a]
cons Char
'}'
    go ((a, Int)
y : [(a, Int)]
ys) = forall a. a -> [a] -> [a]
cons Char
',' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => (a, Int) -> ShowS
showsMember (a, Int)
y forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(a, Int)] -> ShowS
go [(a, Int)]
ys

showsMember :: Show a => (a, Int) -> ShowS
showsMember :: forall a. Show a => (a, Int) -> ShowS
showsMember (a
x, Int
n) = forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 a
x forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> [a] -> [a]
cons Char
'(' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Int
n forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> [a] -> [a]
cons Char
')'

cons :: a -> [a] -> [a]
cons :: forall a. a -> [a] -> [a]
cons = (:)