-- | Similar to @Show@, this module provides a string via @info@. This string gives convenient
-- user-information on objects.

module Data.Info where

import Data.List (concat,intersperse)
import qualified Data.Vector.Unboxed as VU



class Info c where
  -- | The string returned by 'info' should be around 60 chars per line, and one line if possible.
  info :: c -> String

instance (Info a, Info b, Info c) => Info (a,b,c) where
  info :: (a, b, c) -> String
info (a
a,b
b,c
c) = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse String
" " [a -> String
forall c. Info c => c -> String
info a
a, b -> String
forall c. Info c => c -> String
info b
b, c -> String
forall c. Info c => c -> String
info c
c]

instance (VU.Unbox a, Info a) => Info (VU.Vector a) where
  info :: Vector a -> String
info = (a -> String) -> [a] -> String
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap a -> String
forall c. Info c => c -> String
info ([a] -> String) -> (Vector a -> [a]) -> Vector a -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> [a]
forall a. Unbox a => Vector a -> [a]
VU.toList

instance Info Int where
  info :: Int -> String
info = Int -> String
forall a. Show a => a -> String
show