{-|
Copyright  :  (C) 2024     , QBayLogic B.V.
License    :  BSD2 (see the file LICENSE)
Maintainer :  QBayLogic B.V. <devops@qbaylogic.com>
-}

module Clash.Sized.Internal where

-- | Format a range of numbers for use in error messages
--
-- If the upper bound is below the lower bound, @"\<empty range\>"@ is returned.
-- If the bounds are equal, @"[n]"@ is returned (for bounds equal to /n/).
-- Otherwise, @formatRange n m@ returns @"[n..m]"@.
formatRange ::
  (Ord a, Show a) =>
  -- | Lower bound
  a ->
  -- | Upper bound
  a ->
  String
formatRange :: a -> a -> String
formatRange a
n a
m
  | a
m a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
n     = String
"<empty range>"
  | a
m a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
n    = Char
'[' Char -> String -> String
forall a. a -> [a] -> [a]
: a -> String -> String
forall a. Show a => a -> String -> String
shows a
n String
"]"
  | Bool
otherwise = Char
'[' Char -> String -> String
forall a. a -> [a] -> [a]
: a -> String
forall a. Show a => a -> String
show a
n String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
".." String -> String -> String
forall a. [a] -> [a] -> [a]
++ a -> String -> String
forall a. Show a => a -> String -> String
shows a
m String
"]"