------------------------------------------------------------------------------
-- String output
------------------------------------------------------------------------------

-- | Hexadecimal representation of an RGB value
rgbToHex :: RealFrac t => RGB t -> String
rgbToHex (RGB r g b) = ('#':) . showHex' r . showHex' g . showHex' b $ ""
  where showHex' f
          | i <= 15   = ('0':) . showHex i
          | otherwise = showHex i
          where
          i :: Int
          i = max 0 (min 255 (floor (256 * f)))

-- | Hexadecimal representation of an HSV value; i.e., of its corresponding RGB
-- value.
rgbToHex :: RealFrac t => RGB t -> String
rgbToHex (RGB r g b) = ('#':) . showHex' r . showHex' g . showHex' b $ ""
  where showHex' f
          | i <= 15   = ('0':) . showHex i
          | otherwise = showHex i
          where
          i :: Int
          i = max 0 (min 255 (floor (256 * f)))

-- | Hexadecimal representation of an HSV value; i.e., of its corresponding RGB
-- value.
rgbToHex (RGB r g b) = ('#':) . showHex' r . showHex' g . showHex' b $ ""
  where showHex' f
          | i <= 15   = ('0':) . showHex i
          | otherwise = showHex i
          where
          i :: Int
          i = max 0 (min 255 (floor (256 * f)))

-- | Hexadecimal representation of an HSV value; i.e., of its corresponding RGB
-- value.