[Haskell-cafe] Re: Literate programming
On Sat, 12 Jun 2010 17:10:07 -0400 aditya == aditya siram aditya.si...@gmail.com wrote: aditya Unfortunately literate programming doesn't really have the tool aditya support yet. I use emacs for Haskell development and loading aditya Haskell code in to the REPL will be an issue if you're editing aditya a noweb file. Currently this is the only thing keeping me from aditya starting a large ( 2000 LOC) literate project Nobody mentioned Leo (http://webpages.charter.net/edreamleo/front.html) editor which works as stand-alon editor or one can use it with Emacs/Vim... I plan to use it for my project... Sincerely, Gour -- Gour | Hlapicina, Croatia | GPG key: F96FF5F6 signature.asc Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Literate Programming in Haskell?
Hello Haskell Community, Probably somebody else has already brought this issue up already. Why can't we have some kind of integrated literate programming model where I can I can have hyperlinks in comments to documents represented in XML?? In other words, a kind of seamless literate progarmming environment in Haskell with XML, i.e. Haskell and XML are seamless?? E.g. here is a step in the right direction by writing in Literate Haskell in HTML!: http://www.numeric-quest.com/haskell/ The stuff at this URL is pretty cool, i.e. "Haskell" scripts written in HTML. I want to also see hyperlinks to XML docs in Literate Haskell comments or maybe even to Haskell code! Regards, Bill Halchin From: "Erik Meijer" [EMAIL PROTECTED] To: "Patrik Jansson" [EMAIL PROTECTED], [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: Literate Programming in Haskell? Date: Mon, 19 Feb 2001 22:00:47 -0800 You also might take a look at Maarten Fokkinga's mira.sty http://www.cse.ogi.edu/~mbs/src/textools/ and Mark Shileds' abbrev.sty which was derived from that http://www.cse.ogi.edu/~mbs/src/textools/. Erik - Original Message - From: "Patrik Jansson" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Monday, February 19, 2001 6:07 AM Subject: Re: Literate Programming in Haskell? On Mon, 19 Feb 2001, Bostjan Slivnik wrote: I'm also very interested in this, but ideally I would want the output to be in some proportional font, with symbols like =, -, - replaced with arrows, etc. Also, it would be very nice to have the code automatically column aligned (using heuristics). So am I. Is anybody willing to cooperate on the desing of such tool? A tool I am using is Ralf Hinze's lhs2tex http://www.informatik.uni-bonn.de/~ralf/Literate.tar.gz http://www.informatik.uni-bonn.de/~ralf/Guide.ps.gz It transforms .lhs files (with some formatting commands in LaTeX-style comments) to LaTeX. Development based on this idea is something I would be willing to participate in as I already have a fair amount of Haskell code/articles (read: my PhD thesis;-) in this format. Maybe Ralf can say something about his views on further development of lhs2tex (copyright etc.) by other people (us?). /Patrik Jansson PS. I have made some small improvements to lhs2tex locally and I seem to remember that one or two of those were actually needed to get it to run with my ghc version. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe _ Get your FREE download of MSN Explorer at http://explorer.msn.com ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Literate Programming in Haskell?
In the Haskell community is there a generally accepted best way to approach Literate Programming? The language has support for literate comments, but it seems that many common LP tools don't respect it. I'm also very interested in this, but ideally I would want the output to be in some proportional font, with symbols like =, -, - replaced with arrows, etc. Also, it would be very nice to have the code automatically column aligned (using heuristics). So am I. Is anybody willing to cooperate on the desing of such tool? The solution based on the package `listings' is really nice (especially because of its simplicity). However, if different proportional fonts are used for different lexical categories and the indentation is preserved (as it should be in Haskell), the package does not produce the best results. I saw something that looks like this in Mark P. Jones's paper `Typing Haskell in Haskell', but don't know how he did it. Perhaps he used ``Haskell Style for LaTeX2e'' (written by Manuel Chakravarty); just a guess. Or did it manually. Bo"stjan Slivnik ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Literate Programming in Haskell?
Hi, I'm no expert, but I've found a solution that works for me. I use the \begin{code} ... \end{code} delimiters (rather than ). Since these aren't standard Latex, I threw together a style file that called the listings package to handle this. The result is a file that ghc and hugs can compile directly, but which latex can also process. No need for weaving and tangling, while line numbers in error messages are correct. On the other hand, I'm not doing anything very sophisticated - no labelling of blocks or anything like that. I needed to update to the version of tetex in the "testing" Debian release to get this to work - the listing package in the standard distribution doesn't support Haskell (not that I really use that support), so if you get an error message about being unable to load something, that may be the problem. (Warning: I wouldn't recommend moving to Debian testing at the moment; when I last tried the X support had changed significantly and failed to install, so don't upgraed anything apart from tetex). I've included the style file. I don't have a public example yet (hopefully later this week), but I can email you a postscript file directly if you want. Haskell is the first language where I've managed to work happily with literate programming - partly because of the direct integration and partly because the order isn't critical and the code is compact. Cheers, Andrew PS The style file includes lots of stuff unrelated to literate programming - delete everything but the first block, if you like. On Sun, Feb 18, 2001 at 01:53:41AM -0500, Tom Moertel wrote: In the Haskell community is there a generally accepted best way to approach Literate Programming? The language has support for literate comments, but it seems that many common LP tools don't respect it. For example, in order to convert some .lhs code into LaTeX via the noweb LP tools, I had to write a preprocessor to convert the "" code blocks into something that noweb would respect. (The preprocessor actually does a bit more and, in conjunection with noweb, gives pretty good results for little effort. For an example, see: http://www.ellium.com/~thor/hangman/cheating-hangman.lhs http://www.ellium.com/~thor/hangman/cheating-hangman.pdf ) Yet somehow, I don't think that my homebrew approach is optimal. Can anybody recommend a particularly elegant LP setup for Haskell programming? Or if you have an approach that works well for you, would you mind sharing it? Cheers, Tom ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe -- http://www.andrewcooke.free-online.co.uk/index.html \ProvidesPackage{haskell} % % Code support % % stop warning from listings when used in article mode \newcounter{chapter} \usepackage{listings} \lstloadlanguages{Haskell} \lstnewenvironment{code} {\lstset{}% \csname lst@SetFirstLabel\endcsname} {\csname lst@SaveFirstLabel\endcsname} \lstset{ % basicstyle=\small, basicstyle=\small\ttfamily, % keywordstyle=\underbar, % identifierstyle=\slshape, % commentstyle=\underbar flexiblecolumns=false, basewidth={0.5em,0.45em}, literate={-}{{$-$}}1 {+}{{$+$}}1 {/}{{$/$}}1 {*}{{$*$}}1 {=}{{$=$}}1 {}{{$$}}1 {}{{$$}}1 {-}{{$\rightarrow$}}2 {=}{{$\geq$}}2 {-}{{$\leftarrow$}}2 {=}{{$\leq$}}2 {=}{{$\Rightarrow$}}2 {\ .}{{ $\circ$}}2 } % % Page size % \usepackage[hmargin={6cm,3cm},vmargin={3cm,1cm},offset=0pt,nohead]{geometry} % % Titles, layout etc % \usepackage{titlesec} \titleformat{\part}[frame] {\normalfont} {\filright\footnotesize\enspace Andrew Cooke \enspace} {8pt} {\Large\bfseries\sffamily\filcenter} \titlespacing{\part} {-3cm}{-0.5cm}{5ex} \titleformat{\section}[leftmargin] {\large\bfseries\sffamily\filleft} {}{0pt}{} \titlespacing{\section} {3cm}{2.5ex plus .1ex minus .2ex}{1pc} \titleformat{\subsection}[leftmargin] {\normalfont\bfseries\sffamily\filleft} {}{0pt}{} \titlespacing{\subsection} {3cm}{1.5ex plus .1ex minus .2ex}{1pc} \setlength{\parindent 0pt} \setlength{\parskip 1.5ex plus 0.5ex minus 0.2ex} % % eps images % \usepackage{graphicx}
Re: Literate Programming in Haskell?
On Sun, 18 Feb 2001, Tom Moertel wrote: In the Haskell community is there a generally accepted best way to approach Literate Programming? The language has support for literate comments, but it seems that many common LP tools don't respect it. I'm also very interested in this, but ideally I would want the output to be in some proportional font, with symbols like =, -, - replaced with arrows, etc. Also, it would be very nice to have the code automatically column aligned (using heuristics). I saw something that looks like this in Mark P. Jones's paper `Typing Haskell in Haskell', but don't know how he did it. Cheers, Andreas. Andreas Gruenbacher [EMAIL PROTECTED] Research Assistant Phone +43(1)58801-12723 Institute for Geoinformation Fax+43(1)58801-12799 Technical University of Vienna Cell phone +43(664)4064789 ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Literate Programming
Koen Claessen [EMAIL PROTECTED] writes: Take a look at the following "program snippet" (a very popular word at last week's ICFP :-): PRE bfReplace :: [b] - Tree a - Tree b bfReplace xs = deQ . bfReplaceQ xs . singletonQ /PRE Now we just have to define BbfReplaceQ/B. If the goal is to conserve lines, might I suggest: Take a look at the following "program snippet" (a very popular word at last week's ICFP :-): PRE bfReplace :: [b] - Tree a - Tree b bfReplace xs = deQ . bfReplaceQ xs . singletonQ /PRENow we just have to define BbfReplaceQ/B. -kzm -- If I haven't seen further, it is by standing in the footprints of giants
RE: Literate Programming
this is addressed to Mark, but others may be interested in my lament against papers available only in "paper-oriented" formats (dvi, ps, pdf). Mark P. Jones writes: I use exactly the kind of techniques described here in my work. For example, I use literate programming for the "Typing Haskell in Haskell" project (http://www.cse.ogi.edu/~mpj/thih). From a single source, I generate LaTeX source (from which dvi, ps, and pdf forms can be obtained) as well as two different executable versions (a single file version and a multiple file version). It all works pretty well. this single source is not available at the URL: only printables (dvi, ps, pdf) and compilables (source without explanatory comments) derived from it are available. for almost a year now, it has been on my list of things to do to read thih. for reasons too detailed to get into now, except to say that I still use a 486 computer (sans printer) at home, I find reading dvi, ps and pdf inconvenient and tend to postpone reading them whereas I tend to read text and html docs right away. if I had access to the thih "master source", I definitely would have looked at it almost a year ago, and even if it is hard to decipher, there is a good chance that it would have told me enough about the paper to convince me to go through the inconvenience of obtaining a proper printout a long time ago. but maybe I'm just totally atypical: eg, I do not mind reading lengthy docs from the monitor.
Typing Haskell in Haskell in HTML (was RE: Literate Programming)
Richard, | for almost a year now, it has been on my list of things to do to read | thih. for reasons too detailed to get into now, except to say that I | still use a 486 computer (sans printer) at home, I find reading dvi, ps | and pdf inconvenient and tend to postpone reading them whereas I tend to | read text and html docs right away. So why didn't you ask almost a year ago instead of waiting all this time to complain? I haven't provided an HTML version before because I didn't think that it would be useful, and nobody ever wrote to tell me otherwise ... until now. For you, and for anyone else who would like an HTML version, please make your way to the thih web page (http://www.cse.ogi.edu/~mpj/thih/) where you'll find a freshly generated version of thih in HTML. (Be aware that the conversion to HTML may have introduced errors; I found and fixed one, but perhaps there are more. The pdf file is still the most strongly recommended version for reading or printing.) All the best, Mark
Re: Literate Programming
I agree with Mark that literate programming is messed up in Haskell. I think that it is even worse than he says and hence I don't use it anymore at all. Mark P Jones wrote: The literate programming conventions using leading ''s (also known as "Bird tracks" or the "inverted comment convention") go back to Orwell, ... This was the only commenting convention in Orwell. It is very interesting that using ''s was the *only* commenting convention in Orwell. In contrast Haskell has ''s and begin{code}...\end{code}, but also the more conventional -- and {- ... -}. As Mark pointed out so clearly, the idea of literate programming is to have program and documentation in one file and be able to generate various forms of output from it. You can do this from Haskell programs that use -- and/or {- ... -} just as well. The only slight advantages of the inverted commenting conventions are that they are easier to parse and that they stress the importance of the comments. Personally I prefer braces such as begin{code}...\end{code} and {- ... -} for longer program/comment snippets. So I end up using mostly {- ... -}. (Markup is often required for text too; use whatever seems appropriate (and sufficiently general) for the application you have in mind.) Here is a problem. Which markup language should you use? Latex, because you want to generate latex documents? A markup language that your generator tool translates into any other language like latex, html,...? Cheers, Olaf -- OLAF CHITIL, Dept. of Computer Science, University of York, York YO10 5DD, UK. URL: http://www.cs.york.ac.uk/~olaf/ Tel: +44 1904 434756; Fax: +44 1904 432767
Re: Literate Programming
"D. Tweed" [EMAIL PROTECTED] writes: Unfortunately the last time I looked at CWEB it still had the same idea about identifiers as WEB itself, namely that if they match textually they are the same, which makes the automatic indexes produced less useful for C++: I've got twelve classes all with a `read()' method plus any in [...] (Of course, the indexes only matter if like me you prefer reading hardcopy or work on trains, etc.) It would equally hurt cross-referencing, wouldn't it? Emacs' haskell-mode seems to have hard coded a few type signatures from the Prelude, and while probably useful, it'd be much more neat if it could work out what functions actually were referenced. (And not try to deduce types in comments!) Anyway, my problem with literate programming is that I don't really know what to put in there with the source code. Usage documentation? Explanations about implementation details? Tutorial and examples? I guess one reason the Perl documentation works so well, is that the target is clearly defined: man pages. -kzm -- If I haven't seen further, it is by standing in the footprints of giants
Re: Literate Programming
D. Tweed writes: I guess it's arguable; as mentioned I masacre loads of trees due to my habit of working on printed out source code and I could argue that: supposing I'm reading a program where == is defined for a particular instance of class with the comment that `note the care taken to ensure transitivity', then I may very well want to find out if == is actually used anywhere for this type _under the assumption that it is transitive_ without having to wade through lots of == on different classes. (From memory, I believe there's no H98 requirement == be transitive, but this is just a contrived example anyway.) Just because type class methods _ought_ to be semantically related doesn't mean they necessarily will be. First, the `semantic relation' I was thinking of was the equivalence class of types for each class method. In this sense they are always semantically related. Second, I guess you could try to do a conservative type analysis to pick up method uses whose instance is statically determined (as is often the case with arithmetic operators) but I don't think that is something that should be treated in a literate programming tool. For one thing, it means that the reader of the documentation needs to know the algorithm used for the type analysis if he wants to use the indexing to make the sort of informed decision you suggested (because he needs to know which method uses will and won't be caught by the analysis). Personally, I think literate programming is all about syntax, so I would avoid trying to make the tool do any sort of semantic analysis. OTOH, one useful thing might be for it to partition indices of identifers according to provable-isomorphism classes of types. I think such a tool was written for Ocaml, although it was interactive. Here is a page on type isomorphisms: http://www.dmi.ens.fr/users/dicosmo/ResearchThemes/ISOS/ISOShomepage.html At the very bottom of the page it even mentions something about Haskell source code. Now I think about it, there's a problem even if you trust the programmer to ensure type class instance methods are semantically related: suppose I've got class Clothing where wear x = class Abraidable where wear x = I wouldn't want those two to be in the same index group (or is that what you meant by scoping -- I initially thought you meant things like let bindings?) I had in mind both, and all other kinds of scoping as well, e.g., module imports. -- Frank Atanassow, Dept. of Computer Science, Utrecht University Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands Tel +31 (030) 253-1012, Fax +31 (030) 251-3791
Re: Literate Programming
Huh?!? Is this a bug in Hugs? Is it confused by the `' and `' in the HTML code? No! It is just doing what the Haskell98 report says: C Literate comments [...] To capture some cases where one omits an "" by mistake, it is an error for a program line to appear adjacent to a non-blank comment line, where a line is taken as blank if it consists only of whitespace. What the rationale is for this, is a big mystery to me. Look at "to capture some cases"; what cases are captured by this? And what cases are not captured by this? And why does this silly restriction capture any of these cases? I believe the "common case" is the following: data Foo a = A a | B a | C foo (A x) = f x foo (B x) = g x foo _ = error "unimplemented" or possibly bar x = case e x of Just a - a Nothing - b Both of these are caught by the rule. I agree that with additional block markers, this is extremely annoying - but remember that unlit has no idea they are there. --KW 8-)
Re: Literate Programming
This one of the reasons why I never use literate programming. I always forget the blank lines, and then after being puzzled by the error, I remember it, and get completely turned off. C Literate comments [...] To capture some cases where one omits an "" by mistake, it is an error for a program line to appear adjacent to a non-blank comment line, where a line is taken as blank if it consists only of whitespace.
RE: Literate Programming
Hi Koen, I think that literate programming is a great idea, but I don't think Haskell does it justice. I'll suggest a simple solution to your problem at the end of this message. You can skip there now if you want ... or else read on while I rant about this some more and describe what seems to me to be a better solution to your problem. The literate programming conventions using leading ''s (also known as "Bird tracks" or the "inverted comment convention") go back to Orwell, a delightfully elegant language that I had the privilege to use in my own introduction to functional programming. (Alas, it was never widely distributed.) The requirement that there be a blank line between text and code served two purposes. The first was to catch errors that (really do) occur when the leading "" on a line of code has been forgotten. The second was to introduce some visible space between code and text that made the document easier to read on a terminal screen. This was the only commenting convention in Orwell. It was simple, elegant, and quite different to anything that I had seen before. Some folks were not open to new ways of doing things (one of the same reasons that FP does not get more widely used perhaps?), but those of us who were found that it worked very well. The joys of literate programming were greatly diluted in Haskell and its kitchen sink of commenting conventions. And the later addition of \begin{code}...\end{code}, for the benefit of LaTeX hackers, was a further mistake based on a misunderstanding of literate programming. In particular, the goal is not to have a single document that *does* everything, serving simultaneously as plain text, LaTeX source, html, postscript(!), etc. The real goal is to have a single source document that contains both program text and comments, and from which any of the other forms that you want can be *generated*. We do not (normally) write executable files directly, but instead use a compiler or assembler to generate them from higher-level sources. In the same way, I would prefer not to clutter my Haskell programs with html or LaTeX junk that makes it harder to read, while also limiting its portability. I think you should write code as a clean, simple, literate script. And then write, as a separate but more general tool, a utility that will convert those literate scripts into whatever form you need. For example, Such a tool might replace the blank line preceding a "" line with a single "pre" tag, while a blank line after a "" line would be replaced with "/pre". Perhaps it trims out the leading ""s too, because they're not needed now that you've moved to multiple fonts. You write: You get: +-+ +--+ | Blah blah blah | | Blah blah blah | | | | pre| | foo = bar + zub | | foo = bar + zub| | | | /pre | | and so on. | | and so on. | +-+ +--+ (Markup is often required for text too; use whatever seems appropriate (and sufficiently general) for the application you have in mind.) There was never any need whatsoever for \begin{code}...\end{code}; a simple preprocessor would have served just as well for those who needed it, without cluttering language specifications and implementations with unnecessary junk! Tools like this are not difficult to write. Indeed, they make great exercises for introductory functional programming classes. Previous versions of the Haskell report used to include the code for one such tool in an appendix. It was dropped in later versions, perhaps so that it could be set as an exercise in FP classes (that was my only non-serious comment in this email; in truth, I think it might have had more to do with switching to monadic I/O and with reducing the length of the report). I use exactly the kind of techniques described here in my work. For example, I use literate programming for the "Typing Haskell in Haskell" project (http://www.cse.ogi.edu/~mpj/thih). From a single source, I generate LaTeX source (from which dvi, ps, and pdf forms can be obtained) as well as two different executable versions (a single file version and a multiple file version). It all works pretty well. Oh yes, the simple solution that I promised: try the command line option -e, which turns off the test for non-blank lines next to program code. It's a short term hack, but it will do what you want. All the best, Mark [EMAIL PROTECTED] Pacific Software Research Center, Oregon Graduate Institute Long live literate programming!! \begin{code} ... \end{code}? Just say No!