[Haskell-beginners] Showing a value, when there are many approaches?

David McBride toad3k at gmail.com
Wed Aug 7 19:35:03 CEST 2013


Show is not meant to necessarily be human readable.  It is meant to be the
exact opposite of Read.  You show it, then you read it back in and it is
unambiguous.  Having different ways to show it kind of defeats the purpose
of show.

Most people just make a custom function that takes a macaddress and some
other parameter to determine which format you want it to be output as and
then just use that.


On Wed, Aug 7, 2013 at 1:04 PM, Chris Schneider <
chris at christopher-schneider.com> wrote:

> Hi, I'm writing a module that contains a data type for a MacAddress.
>
> Given that, I can do things like validate and format.
>
> But there are several ways you can display a MacAddress:
>
> 'aabbccddeeff' or '00:11:22:33:AA:BB' or 'aa:bb:cc:00:11:22'.
>
> Different external systems want the mac addresses in different formats,
> and I'd like to centralize that logic.
>
> ** So the design question:
>
> I can't just use a `show` function directly to do this, since there are
> options I need to pass.
>
> I could use separate functions that return a string.
>
> I could use newtype to wrap each display style of mac address in a type
> that has a specific `show` instance that spits out the right format. So a
> `Pretty` and `Lower` and similar types.
>
>  ---
>
> Is there a best-practice here? Am I totally missing a better way to model
> this idea?
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130807/50c1a2c0/attachment.htm>


More information about the Beginners mailing list