[Haskell-cafe] How Albus Dumbledore would sell Haskell

Isaac Dupree isaacdupree at charter.net
Thu Apr 19 07:15:55 EDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ajb at spamcop.net wrote:
> I updated the diff example a bit:
> 
>     http://andrew.bromage.org/darcs/diff/
> 
> It now features TWO newtype synonyms.  This illustrates a crucial feature
> of Haskell: Abstractions are cheap.

Okay, looking at that code:
The comments before the type definitions are mostly good...
now it looks like I'm going into critique mode :)

Range (that is, the comment describing it) needs to say whether it's
inclusive of its first and/or its last endpoint (in fact it is
inclusive, I can determine by looking at the definition of rangeDist)

I suppose Match is the same (inclusive), but I can't tell. And
personally I don't know what the significance/meaning of a "found match" is.

Comparing "data Range = Range Line Line" and "type Match = (Line,Line)",
they are isomorphic, but declared differently (which is fine IMO)

With just a little modification, it could use haddock syntax for the
comments!

I got a little lost reading the code. I think all the data/type
definitions should be moved together, to the top. And the comments on
the types enhanced a little to make it clearer how the algorithm goes.
Or if diff is a weird confusing algorithm even in Haskell, put a more
thorough description of why/how it uses those types and/or a reference
to a paper on the subject, I would personally like :).  Maybe that
doesn't show off how clear Haskell itself is, or maybe it gives the
reader a better chance of understanding it at all and thereby seeing how
straightforward it is.  I don't know, are there QuickCheck-style
properties we can say about diff? (they are another valuable tool for
understanding in detail what the code is supposed to do)

The only IO that displayDiff does is putStrLn. It should probably return
a string instead (and be called showDiff? would it be necessary to
replace the putStrLn IO with some sort of writer monad to keep the
code's clarity? or the ShowS-style sequencing/concatenation is (.) and
output is (str++) (or, showLn: (\s -> str ++ '\n' : s)) -- that can be
abstracted so it's not so ugly...)  Then,
displayDiff = putStr . showDiff



Isaac
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGJ09qHgcxvIWYTTURAhqrAJ9SFYmIifl5Ahf0umg0SnImGKr3tgCgwLze
bZdTYUzmy+C2uXwFOkJOcdU=
=KfVH
-----END PGP SIGNATURE-----


More information about the Haskell-Cafe mailing list