[Haskell-beginners] Showing a value, when there are many approaches?
Chris Schneider
chris at christopher-schneider.com
Wed Aug 7 19:04:15 CEST 2013
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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130807/dd309e2c/attachment.htm>
More information about the Beginners
mailing list