Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Showing a value, when there are many approaches?
      (Chris Schneider)
   2. Re:  Showing a value,     when there are many approaches?
      (David McBride)
   3.  Looking for judges for haskell competition (Mike Meyer)
   4.  Enterprise-quality XML library? (Mike Meyer)
   5. Re:  Showing a value,     when there are many approaches?
      (Brandon Allbery)
   6. Re:  How to construct complex string (Brent Yorgey)


----------------------------------------------------------------------

Message: 1
Date: Wed, 7 Aug 2013 11:04:15 -0600
From: Chris Schneider <ch...@christopher-schneider.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Showing a value, when there are many
        approaches?
Message-ID:
        <caghc4uhaprk-gmyejtw0y+gbcvbt8wwpcxw97mhwtmvu9wo...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

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-0001.html>

------------------------------

Message: 2
Date: Wed, 7 Aug 2013 13:35:03 -0400
From: David McBride <toa...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Showing a value,       when there are many
        approaches?
Message-ID:
        <CAN+Tr42FTawo12GwmK5hCxw29OZaJP3a8M6Am5oWOj8zS5=3...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

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 <
ch...@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@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-0001.html>

------------------------------

Message: 3
Date: Wed, 7 Aug 2013 13:02:39 -0500
From: Mike Meyer <m...@fpcomplete.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Looking for judges for haskell
        competition
Message-ID:
        <cad272pb7az7g3rd6tlpaicl4uqgtswwdj1csgrpsqmfxdet...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

In order to foster commercial use of Haskell, FP Complete is running a
competition for monthly cash prizes (details
https://www.fpcomplete.com/blog/2013/07/competition-announcement).

We are looking for judges from the community. People helping beginners
would seem to be a good fit for this. If you're interested, could you
please drop me a note along with pertinent information?

Thanks,
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130807/1970cc32/attachment-0001.html>

------------------------------

Message: 4
Date: Wed, 7 Aug 2013 13:16:44 -0500
From: Mike Meyer <m...@fpcomplete.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Enterprise-quality XML library?
Message-ID:
        <cad272pd3dxxucdwmudeygpfu-x3zsqr4+oa-rgtbwy2fi+8...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I've been looking for an enterprise-grade XML library. My standard for
comparison is Python's lxml library (a wrapper around libxml2 and libxslt).
The only thing I've found that's even close is hxt, and it falls a bit
short.

Specifically, when I feed it invalid XML, I get this error:

error: The content of element "school" must match ( "author"* ). Element
"author" expected, but element "auther" found.

error: Element "auther" not declared in DTD.

Whereas from lxml I get:

lxml.etree.XMLSyntaxError: No declaration for attribute name of element
auther, line 24, column 19

This is shorter and clearer, and identifies the location of the error. It
does have better error messages for ill-formed XML.

Is there a library with a validating parser that provides better quality
error messages?

It also seems like mapping an XML Schema into a collection of Haskell types
should be a function of the library. Is there on that does that, or is this
completely untenable?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130807/0ca4442a/attachment-0001.html>

------------------------------

Message: 5
Date: Wed, 7 Aug 2013 14:51:15 -0400
From: Brandon Allbery <allber...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Showing a value,       when there are many
        approaches?
Message-ID:
        <cakfcl4wy6ff68-toiwtsnsdjcaeyodrqzgjh7-ja9tze64y...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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

> I can't just use a `show` function directly to do this, since there are
> options I need to pass.
>

And you shouldn't use `show` for this, because if it prints your MacAddress
as anything other than an unambiguous representation of the Haskell
MacAddress type then it has lost information useful for debugging. More to
the point: if I cannot see the difference between your MacAddress and a
String, then it's an unacceptable `show`. `show` should reflect the Haskell
data structure so I can verify that my program is doing the right thing; if
it shows what looks like a String, but I'm expecting to see a MacAddress,
then I will suspect a type error somewhere.

`show` is like Perl's Data::Dumper or Python's repr. I don't want pretty, I
want accuracy.

-- 
brandon s allbery kf8nh                               sine nomine associates
allber...@gmail.com                                  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130807/70bbf78a/attachment-0001.html>

------------------------------

Message: 6
Date: Wed, 7 Aug 2013 15:15:12 -0400
From: Brent Yorgey <byor...@seas.upenn.edu>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] How to construct complex string
Message-ID: <20130807191512.ga7...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

On Mon, Aug 05, 2013 at 09:37:18PM +0200, martin wrote:
> Hello all,
> 
> recently I was working on a haskell program, which does some
> calculations and the produces a "plot", i.e. a set of Tikz (a LaTeX
> thing) commands.
> 
> While this was not a problem in itself, it lacked composability. While
> all my plots show a grid, a caption and some data points, some of them
> additionally show a line with a legend, some of them show two.
> 
> Now I clearly do not want to duplicate the entire function just to add
> another line. I'd rather construct the Tikz commands (which at the end
> of the day is just a String) in a stepwise fashion.
> 
> When constructing the set of Tikz commands, I cannot rely that
> additional commands are placed at the end. It is typically more an
> inside-out thing. The last thing I need to do is wrap the whole thing in
> \begin and \end directives.

Hi Martin,

I think the key thing you are missing is that a String is just a
particular concrete representation of a TikZ program.  That is not
what a TikZ program really *is*.  Instead, TikZ programs are trees.
String is nice for storing a program in a file, but it is a terrible
representation to use when working with programs, whether generating
them, type-checking them, or whatever.  As you have discovered, when
working with Strings you have to insert stuff at various arbitrary
places (at the beginning, the end, the middle), which is quite
annoying and difficult (especially the middle!), whereas those same
operations are simple on a tree representation of the program.

To do what you are trying to do in a nice way would require (1) making
an algebraic data type to represent the structure of TikZ programs (2)
changing your program so that it generates values of this type,
instead of Strings, and (3) making a single function to convert a
value of this type into a String.  This can be quite a bit of work up
front, but well worth it if you are going to do more than just a bit
of TikZ generation.

With that said, however, did you know there is a TikZ backend for
diagrams? [1] It should be possible for you to describe your plots
using diagrams and then output them to TikZ (or any other format for
which diagrams has a backend---SVG, PDF, PS, or PNG).  I have not
looked at it recently but would be happy to support it if you run into
any problems (I will probably want it myself sooner or later).

[1] http://hackage.haskell.org/package/diagrams%2Dtikz

-Brent

> 
> Additionally there may be "global" values (like the scale) which need to
> be known at more than one step. I had a brief look at the "Diagrams"
> package, which MUST have similar issues, and they "do everything with
> monoids", but I fail to see the light.
> 
> Could anyone point me in the right direction?
> 
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners



------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 62, Issue 5
****************************************

Reply via email to