<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ponton&#039;s site &#187; haskell</title>
	<atom:link href="http://www.ponton.srednikpe.org/tag/haskell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ponton.srednikpe.org</link>
	<description>blog głównie matematyczno-informatyczny (nie chce mi się pisać o życiu)</description>
	<lastBuildDate>Mon, 18 Jan 2010 22:23:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Programowanie literackie</title>
		<link>http://www.ponton.srednikpe.org/2009/01/10/programowanie-literackie/</link>
		<comments>http://www.ponton.srednikpe.org/2009/01/10/programowanie-literackie/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 01:57:52 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[Polskie]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[literate programming]]></category>
		<category><![CDATA[tex]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=183</guid>
		<description><![CDATA[Ostatnio miałem ponowną styczność z TeX-em, tym razem konkretnie z Beamerem (całkiem fajne narzędzie do tworzenia ładnych i profesjonalnych prezentacji; być może wrzucę tę, którą zrobiłem na zajęcia). Jest to jeden z programów, które są owiane dla mnie lekką tajemnicą&#8230; Już sam fakt że został napisany przez legendarnego Donalda Knutha, powoduje bojaźn i trwogę podczas [...]]]></description>
			<content:encoded><![CDATA[<p>Ostatnio miałem ponowną styczność z TeX-em, tym razem konkretnie z Beamerem (całkiem fajne narzędzie do tworzenia ładnych i profesjonalnych prezentacji; być może wrzucę tę, którą zrobiłem na zajęcia). Jest to jeden z programów, które są owiane dla mnie lekką tajemnicą&#8230; Już sam fakt że został napisany przez legendarnego Donalda Knutha, powoduje bojaźn i trwogę podczas używania. No dobra, przesadzam, ale TeX to program wyjątkowy. Nie dlatego, że jest bezbłędny (ma już ze 30 lat chyba, a ostatni błąd wykryto w nim kilkanaście lat temu), ale dlatego, że jest napisany&#8230; literacko.</p>
<p>Donald Knuth napisał książkę-program pod tytułem <em>TeX: The Program</em> (ISBN: 0201134373). Następnie (a może uprzednio?) napisał narzędzie, które nazwał WEB. WEB pozwalał mu automatycznie skonwertować książkę-program do poprawnego programu w Pascalu (w tamtych czasach był to bardzo popularny język), który po skompilowaniu robił to, co opisano w książkoprogramie. Oprócz tego, pozwalał też wygenerować&#8230; książkę. Z nagłówkami, sekcjami, stronami &#8212; ot, PDF lub PostScript, nadający się do wydrukowania.</p>
<p>Książkoprogram to tak naprawdę dokumentacja i kod w jednym. Programista pisze na przemian kod i tekst. Może przy pisaniu kodu korzystać ze wszystkich dobrodziejstw TeX-a do opisywania swojego kodu, tworzyć odnośniki do innych fragmentów kodu, etc. Lepiej to zobaczyć na przykładzie: <a href="http://srednikpe.org/src/kwadrat/kwadrat.w">kwadrat.w</a>. Użyłem wesji WEB dla C/C++, która nazywa się <a title="CWEB" href="http://www-cs-faculty.stanford.edu/~knuth/cweb.html">CWEB</a>. Aby otrzymać program C, wystarczy polecnie:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ctangle kwadrat
This is CTANGLE, Version <span style="color: #000000;">3.64</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>Web2C 7.5.6<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
Writing the output <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>kwadrat.c<span style="color: #7a0874; font-weight: bold;">&#41;</span>:
Done.
<span style="color: #7a0874; font-weight: bold;">&#40;</span>No errors were found.<span style="color: #7a0874; font-weight: bold;">&#41;</span>
$ <span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-o</span> kwadrat kwadrat.c <span style="color: #660033;">-lm</span>
$ .<span style="color: #000000; font-weight: bold;">/</span>kwadrat
Podaj a: <span style="color: #000000;">1</span>
Podaj b: <span style="color: #000000;">10</span>
Podaj c: <span style="color: #000000;">5</span>
x = -<span style="color: #000000;">9.472136</span>
x = -<span style="color: #000000;">0.527864</span></pre></div></div>

<p>Aby otrzymać dokument TeX-a, należy napisać:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ cweave kwadrat
This is CWEAVE, Version <span style="color: #000000;">3.64</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>Web2C 7.5.6<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
Writing the output file...
Writing the index...
Done.
<span style="color: #7a0874; font-weight: bold;">&#40;</span>No errors were found.<span style="color: #7a0874; font-weight: bold;">&#41;</span>
$ pdftex kwadrat.tex
This is pdfTeXk, Version <span style="color: #000000;">3.141592</span>-1.40.3 <span style="color: #7a0874; font-weight: bold;">&#40;</span>Web2C 7.5.6<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span>...<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Output written on kwadrat.pdf <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span> pages, <span style="color: #000000;">63651</span> bytes<span style="color: #7a0874; font-weight: bold;">&#41;</span>.
Transcript written on kwadrat.log.</pre></div></div>

<p>Oto wygenerowane pliki: <a href="http://srednikpe.org/src/kwadrat/kwadrat.tex">kwadrat.tex</a>, <a href="http://srednikpe.org/src/kwadrat/kwadrat.pdf">kwadrat.pdf</a> i <a href="http://srednikpe.org/src/kwadrat/kwadrat.c">kwadrat.c</a>. Niestety nie wiem jak zmusić czystego TeX-a do poprawnego czytania UTF-8, dlatego w PDF-ie nie ma polskich liter.</p>
<p>Szczerze mówiąc nie mam zdania na temat <em>literate programming</em>. Jeśli ktoś lubi tak pisać, to proszę bardzo &#8212; całkiem przyjemnie się czyta taki dokument. Jednak ja nie lubię się rozpisywać nad kodem, dla mnie sam kod (z komentarzami) stanowi wystarczającą dokumentację. ;)</p>
<p>Warto jeszcze dodać, że wsparcie dla <em>literate programming</em> jest zaimplementowane w Haskellu. Ale to już lepiej poczytać na <a title="Literate programming in Haskell" href="http://www.haskell.org/haskellwiki/Literate_programming">Haskell Wiki</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2009/01/10/programowanie-literackie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Program verification conditions</title>
		<link>http://www.ponton.srednikpe.org/2008/12/22/program-verification-conditions/</link>
		<comments>http://www.ponton.srednikpe.org/2008/12/22/program-verification-conditions/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 00:39:01 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[my code]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=159</guid>
		<description><![CDATA[Yay, another parser in Haskell! That was a Haskell week, but I&#8217;m glad I had an opportunity to recall this beautiful full-of-math language. This program reads an annotated program &#8212; a program with assertions. Assertions are just logic formulas. We use them to describe the program state between instructions, ie. variable x is equal to [...]]]></description>
			<content:encoded><![CDATA[<p>Yay, another parser in Haskell! That was a Haskell week, but I&#8217;m glad I had an opportunity to recall this beautiful full-of-math language.</p>
<p>This program reads an annotated program &#8212; a program with assertions. Assertions are just logic formulas. We use them to describe the program state between instructions, ie. variable x is equal to variable y squared. But assertions cannot be random, they must be derived from Hoare&#8217;s logic axioms and rules (which base on the formal semantic of the language). How do we know if there is an derivation of a program?</p>
<p>Here verification condicitions come. They are logic formulas too, but generated from annotated program. If all of them are true, then the program is derivable. More information here: <a href="http://www.macs.hw.ac.uk/~air/hic-hisd/">http://www.macs.hw.ac.uk/~air/hic-hisd/</a> and <a href="http://www.daimi.au.dk/~bra8130/Wiley_book/wiley.html">http://www.daimi.au.dk/~bra8130/Wiley_book/wiley.html</a>. The whole point is about formal verification of programs. Nowadays compiler can tell only whether given program has a syntax or type error. It doesn&#8217;t know anything about how this program should work and can&#8217;t  say something like: &#8220;This program certainly does not multiply matrices.&#8221;. Assertions are some way to tell the programmer&#8217;s intentions to the compiler: &#8220;This is my piece of code and it should multiply two matrices&#8221;, and thus, by generating verification conditions and using automated theorem proving it could say: &#8220;It does.&#8221;.</p>
<p>So after a boring digression&#8230; this program reads an annotated program in a simple imperative language and generates verification conditions. That&#8217;s all.</p>
<p>All files are here: <a href="http://srednikpe.org/src/vc/">http://srednikpe.org/src/vc/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2008/12/22/program-verification-conditions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reverse Polish notation calculator in Haskell</title>
		<link>http://www.ponton.srednikpe.org/2008/12/22/reverse-polish-notation-calculator-in-haskell/</link>
		<comments>http://www.ponton.srednikpe.org/2008/12/22/reverse-polish-notation-calculator-in-haskell/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 00:02:51 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[my code]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=155</guid>
		<description><![CDATA[Just a few lines of code, written when I was slightly bored. module Main where &#160; data Token = Plus &#124; Minus &#124; Divide &#124; Times &#124; Num Integer &#160; rpnEval :: &#91;Token&#93; -&#62; Integer rpnEval = rpnEval' &#91;&#93; where rpnEval' &#40;i:s&#41; &#91;&#93; = i rpnEval' s &#40;&#40;Num i&#41;:t&#41; = rpnEval' &#40;i:s&#41; t rpnEval' &#40;a:b:s&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>Just a few lines of code, written when I was slightly bored.</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">data</span> Token <span style="color: #339933; font-weight: bold;">=</span> Plus <span style="color: #339933; font-weight: bold;">|</span> Minus <span style="color: #339933; font-weight: bold;">|</span> Divide <span style="color: #339933; font-weight: bold;">|</span> Times <span style="color: #339933; font-weight: bold;">|</span> <span style="color: #cccc00; font-weight: bold;">Num</span> <span style="color: #cccc00; font-weight: bold;">Integer</span>
&nbsp;
rpnEval <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#91;</span>Token<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Integer</span>
rpnEval <span style="color: #339933; font-weight: bold;">=</span> rpnEval' <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #06c; font-weight: bold;">where</span>
		rpnEval' <span style="color: green;">&#40;</span>i:s<span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> i
		rpnEval' s <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Num</span> i<span style="color: green;">&#41;</span>:t<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> rpnEval' <span style="color: green;">&#40;</span>i:s<span style="color: green;">&#41;</span> t
		rpnEval' <span style="color: green;">&#40;</span>a:b:s<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>op:t<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> rpnEval' <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>evalOp op a b<span style="color: green;">&#41;</span>:s<span style="color: green;">&#41;</span> t
&nbsp;
		evalOp Plus <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">+</span><span style="color: green;">&#41;</span>
		evalOp Minus <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">-</span><span style="color: green;">&#41;</span>
		evalOp Times <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">*</span><span style="color: green;">&#41;</span>
		evalOp Divide <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">div</span>
&nbsp;
toToken <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> Token
toToken <span style="background-color: #3cb371;">&quot;+&quot;</span> <span style="color: #339933; font-weight: bold;">=</span> Plus
toToken <span style="background-color: #3cb371;">&quot;-&quot;</span> <span style="color: #339933; font-weight: bold;">=</span> Minus
toToken <span style="background-color: #3cb371;">&quot;*&quot;</span> <span style="color: #339933; font-weight: bold;">=</span> Times
toToken <span style="background-color: #3cb371;">&quot;/&quot;</span> <span style="color: #339933; font-weight: bold;">=</span> Divide
toToken s <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #cccc00; font-weight: bold;">Num</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">read</span> s<span style="color: green;">&#41;</span>
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
	l <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">getContents</span>
	<span style="font-weight: bold;">mapM</span> <span style="font-weight: bold;">print</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span>rpnEval <span style="color: #339933; font-weight: bold;">.</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">map</span> toToken<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">words</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">lines</span> l<span style="color: green;">&#41;</span></pre></div></div>

<p>Update: See comments for better solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2008/12/22/reverse-polish-notation-calculator-in-haskell/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>JZW Interpreter source and examples</title>
		<link>http://www.ponton.srednikpe.org/2007/09/09/jzw-interpreter-source-and-examples/</link>
		<comments>http://www.ponton.srednikpe.org/2007/09/09/jzw-interpreter-source-and-examples/#comments</comments>
		<pubDate>Sun, 09 Sep 2007 18:00:49 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[interpreter]]></category>
		<category><![CDATA[jzwi]]></category>
		<category><![CDATA[my code]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/2007/09/09/jzw-interpreter-source-and-examples/</guid>
		<description><![CDATA[All right. I said I&#8217;ll show my jzwi source and here it is: http://www.srednikpe.org/src/jzwi/ It is almost ended. It doesn&#8217;t only check local variable if they have unique names. I&#8217;m too lazy to do that. But after all it works fine and quite fast (compared to other interpreters written by my colleagues). To run jzwi [...]]]></description>
			<content:encoded><![CDATA[<p>All right. I said I&#8217;ll show my jzwi source and here it is: <a title="JZW interpreter source and examples" href="http://www.srednikpe.org/src/jzwi/">http://www.srednikpe.org/src/jzwi/</a></p>
<p>It is almost ended. It doesn&#8217;t only check local variable if they have unique names. I&#8217;m too lazy to do that. But after all it works fine and quite fast (compared to other interpreters written by my colleagues).</p>
<p>To run jzwi program just run  &#8220;jzwi program.jzw argument1 argument2 &#8230;&#8221;.</p>
<p>It&#8217;s all licensed on GPL (any version). There is no guarantee that it&#8217;ll work. ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2007/09/09/jzw-interpreter-source-and-examples/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JZWI</title>
		<link>http://www.ponton.srednikpe.org/2007/08/22/jzwi/</link>
		<comments>http://www.ponton.srednikpe.org/2007/08/22/jzwi/#comments</comments>
		<pubDate>Wed, 22 Aug 2007 21:44:03 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[jzwi]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=8</guid>
		<description><![CDATA[Uff&#8230; I have nearly finished my jzwi interpreter, just few minor fixes I will make in a week&#8230; JZWI means &#8220;Język z wykładu improved&#8221; (&#8220;Language from lecture improved&#8221;). On our programming language theory subject we defined syntax using BNF notation and then we define formal semantic of this language (which is quite simmilar to Pascal/ALGOL). It was our lab project to write a parser, converter to xHTML/LaTeX, an interpreter or full compiler in Haskell. It wasn&#8217;t as difficult as I thought, but I [...]]]></description>
			<content:encoded><![CDATA[<p>Uff&#8230; I have nearly finished my jzwi interpreter, just few minor fixes I will make in a week&#8230;</p>
<p>JZWI means &#8220;Język z wykładu improved&#8221; (&#8220;Language from lecture improved&#8221;). On our programming language theory subject we defined syntax using <a title="BNF syntax" href="http://en.wikipedia.org/wiki/Backus–Naur_form">BNF notation</a> and then we define formal semantic of this language (which is quite simmilar to Pascal/ALGOL).</p>
<p>It was our lab project to write a parser, converter to xHTML/LaTeX, an interpreter or full compiler in <a href="http://en.wikipedia.org/wiki/Haskell_(programming_language)">Haskell</a>. It wasn&#8217;t as difficult as I thought, but I had to rewrite many parts of the code, &#8217;cause firstly I wrote only simply parser, then simply converter and then I decided to try interpreter.</p>
<p>It costed me few nights and days, but I am very happy, when I see how beautifully it runs insertion sort. ;) Full source will be uploaded within few days. I have to lay off from vim and ghc. ;)</p>
<p>Uff&#8230; maybe I&#8217;ll check insertion sort once more. :&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2007/08/22/jzwi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
