[Haskell-cafe] How Albus Dumbledore would sell Haskell

ajb at spamcop.net ajb at spamcop.net
Thu Apr 19 20:14:26 EDT 2007


G'day all.

Quoting Isaac Dupree <isaacdupree at charter.net>:

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

BTW, for the record, I didn't try too hard with this.  It is meant
to be illustrative of what you can do with Haskell and not too much
time to spare.

I didn't haddock-ise the comments because Diff isn't a library.  The
comments are meant to be more commentary (this is a tutorial, remember!)
than developer documentation.

> 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)

Fair point.

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

OK, this needs explanation.  A Match is a match _between_ the two
files being diffed.  So (a,b) means that line a in file 1 matches
line b in file 2.  I'll note that, thanks.

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

Yup.  They only have to be different enough to cause a type error if
you accidentally try to mix them.

> The only IO that displayDiff does is putStrLn. It should probably return
> a string instead [...]

Possibly, or even use a Writer monad.  I habitually use putStrLn,
though, because I regularly program in multiple languages, and this
way I don't have to remember how Haskell handles line termination on
different platforms.

Cheers,
Andrew Bromage


More information about the Haskell-Cafe mailing list