{-# LANGUAGE DefaultSignatures #-}

-- |
-- Module      : OAlg.Data.Show
-- Description : showing data
-- Copyright   : (c) Erich Gut
-- License     : BSD3
-- Maintainer  : zerich.gut@gmail.com
--
-- showing data with some auxiliary functions.
module OAlg.Data.Show
  (  -- * Show
    Show(..), tween, jtween, Show1(..), Show2(..)
  , String, Char
  
     -- * Read
  , Read, read
  )
  where

import Control.Monad (join)
import Data.Proxy

--------------------------------------------------------------------------------
-- tween -

-- | inserting the given value in between the elements of the given list.
--
--  __Examples__
--
-- >>> tween ',' "12345"
-- "1,2,3,4,5"
--
-- >>> tween ',' ""
-- ""
--
-- >>> tween ',' "1"
-- "1"
tween :: a -> [a] -> [a]
tween :: forall a. a -> [a] -> [a]
tween a
d (a
x:ys :: [a]
ys@(a
_:[a]
_)) = a
xforall a. a -> [a] -> [a]
:a
dforall a. a -> [a] -> [a]
:forall a. a -> [a] -> [a]
tween a
d [a]
ys
tween a
_ [a]
xs           = [a]
xs

--------------------------------------------------------------------------------
-- jtween

-- | inserting the given list in between the elements of the given list and joining the result.
--
-- __ Example__
--
-- >>> jtween ";" ["abcd","efg"]
-- "abcd;efg"
jtween :: [a] -> [[a]] -> [a]
jtween :: forall a. [a] -> [[a]] -> [a]
jtween [a]
ds [[a]]
xs = forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (forall a. a -> [a] -> [a]
tween [a]
ds [[a]]
xs)

--------------------------------------------------------------------------------
-- Show1 -

-- | showable for one parameterized types.
class Show1 p where
  show1 :: p x -> String
  default show1 :: Show (p x) => p x -> String
  show1 = forall a. Show a => a -> String
show

instance Show1 Proxy
--------------------------------------------------------------------------------
-- Show2 -

-- | showable for two parameterized types.
--
--  __Note__ We use this class mearly in the context of 'OAlg.Category.Path'.
class Show2 h where
  show2 :: h a b -> String
  default show2 :: Show (h a b) => h a b -> String
  show2 = forall a. Show a => a -> String
show