Proposal for a generic showIntAtBase

Vikas Menon menonvikas at gmail.com
Sun Apr 5 16:46:39 UTC 2015


Hi,

The current implementation of showIntAtBase in Numeric is limited to Chars
currently.

*showIntAtBase*
*  :: (Integral a, Show a) => a -> (Int -> Char) -> a -> ShowS*

The 2 reasons for this constraint is:
    a) We only accept functions of the form (Int -> Char)
    b) An implicit concatenation using  (:)

I'd like to propose a new function showIntAtBaseGeneric that removes the
(Int -> Char) function constraint and takes an additional function to
replace the implicit (:) operator.

*showIntAtBaseGeneric*
*  :: (Integral a1, Num b, Show a1) =>*
*     a1 -> (b -> a) -> (a -> s -> s) -> a1 -> s -> s*

Now showIntAtBase may be implemented as:

*showIntAtBase :: (Integral a, Show a) => a -> (Int -> Char) -> a -> ShowS*
*showIntAtBase base toChr n0 r0 = showIntAtBaseGeneric base toChr (:) n0 r0*

The API and behavior of showIntAtBase remains unchanged while allowing for
generic conversions not limited to Chars alone.

*Example: *
*λ>  showIntAtBaseGeneric 26 id (:) 500 [] -- convert 500 to base26 and
provide output as a list.*
*[19,6]*

Please let me know thoughts/concerns if any to this proposal.

Cheers,
Vikas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20150405/e7e8341e/attachment.html>


More information about the Libraries mailing list