[Haskell-cafe] How Albus Dumbledore would sell Haskell
isaacdupree at charter.net
Fri Apr 20 12:22:51 EDT 2007
-----BEGIN PGP SIGNED MESSAGE-----
ajb at spamcop.net wrote:
> 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 know, (but if you got it from somewhere, the code could really be
improved where it came from? >:) or did I misunderstand?)
> 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.
Admittedly. Haddock standardizes what bit of the code a comment is
meant to refer to, though, so I like using its syntax anyway. (And all
code might be part of a library someday... Haskell lets you think of
almost all your code as libraries! it is an excellent way to think
about modularity that is far too cumbersome in many other languages!)
>> 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.
Ah, I see now.
>> 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.
Tuples are always a bit risky though (every tuple matches every other
tuple you introduce, as well as libraries using them) -- but undoubtedly
convenient syntax (and certainly worth showing off to those whose
languages don't contain native tuples)
>> 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.
Hmm, reasonable. (I hope haskell just uses '\n' in-program everywhere..)
You could return a list of lines instead (and mapM_ putStrLn the
result). Is there any way to make IO be an instance of MonadWriter? Not
in a reasonable way, I think, given 'listen' etc... possibly a different
class interface would be more useful, but we're certainly not into
trying that here!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
More information about the Haskell-Cafe