<?xml version="1.0" encoding="utf-8"?><!-- generator="wordpress/1.5" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Haskell is nicer than Scheme</title>
	<link>http://jeffrey.yasskin.info/blog/archives/2005/02/09/haskell-vs-scheme/</link>
	<description>questions and comments on the world</description>
	<pubDate>Sat, 04 Feb 2012 19:29:18 +0000</pubDate>
	<generator>http://wordpress.org/?v=1.5</generator>

	<item>
		<title>by: Alex</title>
		<link>http://jeffrey.yasskin.info/blog/archives/2005/02/09/haskell-vs-scheme/#comment-897</link>
		<pubDate>Fri, 27 May 2005 11:58:58 -0700</pubDate>
		<guid>http://jeffrey.yasskin.info/blog/archives/2005/02/09/haskell-vs-scheme/#comment-897</guid>
					<description>One advantage of Scheme is the sexpr syntax. This isn't just useful for macros: it allows you to give a concise representation of just about any kind of data you can imagine. For example, a nice trick in Lispy languages is to write a simple procedure for converting lists such as '(p ((class . &quot;foo&quot;)) &quot;Blah blah&quot;) into nicely formatted HTML. This makes it really easy to generate HTML content. In Haskell you have to take a more direct approach, writing a combinator library which allows you to combine HTML generating functions. The combinator library approach often works very well, but sometimes it's nice to have a real solid data structure to manipulate. Especially if you want to store this data in a file rather than hard-coding it into your program. Of course, you could define a datatype for HTML in Haskell, but it would have a rather less pleasing syntax and there would be no pre-defined functions with which to manipulate it.

There's an interesting relationship between Scheme's type system (or lack thereof) and its eager evaluation strategy. You'd think that Scheme (having no static type system) ought to be able to express any function expressible in lambda calculus, and therefore have something of an advantage over Haskell. However, this often is not the case in practice. For example, the Y combinator cannot be given its standard lambda calculus definition in Haskell because it has an infinite type, but in Scheme the standard definition leads to nontermination.
</description>
		<content:encoded><![CDATA[	<p>One advantage of Scheme is the sexpr syntax. This isn&#8217;t just useful for macros: it allows you to give a concise representation of just about any kind of data you can imagine. For example, a nice trick in Lispy languages is to write a simple procedure for converting lists such as &#8216;(p ((class . &#8220;foo&#8221;)) &#8220;Blah blah&#8221;) into nicely formatted <acronym title="HyperText Markup Language">HTML</acronym>. This makes it really easy to generate <acronym title="HyperText Markup Language">HTML</acronym> content. In Haskell you have to take a more direct approach, writing a combinator library which allows you to combine <acronym title="HyperText Markup Language">HTML</acronym> generating functions. The combinator library approach often works very well, but sometimes it&#8217;s nice to have a real solid data structure to manipulate. Especially if you want to store this data in a file rather than hard-coding it into your program. Of course, you could define a datatype for <acronym title="HyperText Markup Language">HTML</acronym> in Haskell, but it would have a rather less pleasing syntax and there would be no pre-defined functions with which to manipulate it.</p>
	<p>There&#8217;s an interesting relationship between Scheme&#8217;s type system (or lack thereof) and its eager evaluation strategy. You&#8217;d think that Scheme (having no static type system) ought to be able to express any function expressible in lambda calculus, and therefore have something of an advantage over Haskell. However, this often is not the case in practice. For example, the Y combinator cannot be given its standard lambda calculus definition in Haskell because it has an infinite type, but in Scheme the standard definition leads to nontermination.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jeffrey Yasskin</title>
		<link>http://jeffrey.yasskin.info/blog/archives/2005/02/09/haskell-vs-scheme/#comment-898</link>
		<pubDate>Fri, 27 May 2005 15:56:59 -0700</pubDate>
		<guid>http://jeffrey.yasskin.info/blog/archives/2005/02/09/haskell-vs-scheme/#comment-898</guid>
					<description>If we want to follow the sexpr style in Haskell, we can write your example as &lt;code&gt;(&quot;p&quot;, [(&quot;class&quot;,&quot;foo&quot;)], &quot;Blah blah&quot;)&lt;/code&gt;. The only advantage Scheme gives us now is the &lt;code&gt;symbol&lt;/code&gt; type, which lets us drop some quotation marks. If we translate it to more idiomatic (and type-safe) Haskell, we could get &lt;code&gt;p [class &quot;foo&quot;] &quot;Blah blah&quot;&lt;/code&gt;, given &lt;code&gt;p&lt;/code&gt; and &lt;code&gt;class&lt;/code&gt; as helper functions. The helper functions could generate the HTML datatype just as easily as raw HTML. The lack of pre-defined functions is a problem, but the &lt;a href=&quot;http://www.cs.vu.nl/boilerplate/&quot; rel=&quot;nofollow&quot;&gt;Scrap Your Boilerplate&lt;/a&gt; project is working on it.

In summary, Haskell can handle s-expressions, using tuples to handle non-uniform lists, but it allows you to go beyond them when you want.</description>
		<content:encoded><![CDATA[	<p>If we want to follow the sexpr style in Haskell, we can write your example as <code>("p", [("class","foo")], "Blah blah")</code>. The only advantage Scheme gives us now is the <code>symbol</code> type, which lets us drop some quotation marks. If we translate it to more idiomatic (and type-safe) Haskell, we could get <code>p [class "foo"] "Blah blah"</code>, given <code>p</code> and <code>class</code> as helper functions. The helper functions could generate the <acronym title="HyperText Markup Language">HTML</acronym> datatype just as easily as raw <acronym title="HyperText Markup Language">HTML</acronym>. The lack of pre-defined functions is a problem, but the <a href="http://www.cs.vu.nl/boilerplate/" rel="nofollow">Scrap Your Boilerplate</a> project is working on it.</p>
	<p>In summary, Haskell can handle s-expressions, using tuples to handle non-uniform lists, but it allows you to go beyond them when you want.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Alex</title>
		<link>http://jeffrey.yasskin.info/blog/archives/2005/02/09/haskell-vs-scheme/#comment-899</link>
		<pubDate>Fri, 27 May 2005 16:32:31 -0700</pubDate>
		<guid>http://jeffrey.yasskin.info/blog/archives/2005/02/09/haskell-vs-scheme/#comment-899</guid>
					<description>Your first suggestion doesn't really work. If you use tuples to handle the nesting, you have no way of iterating over the elements of a tuple (and this is pretty much essential if you want to actually do something with the data). You can't use nested tuples as a replacement for nested lists.

As I said, you can create a custom HTML datatype, and if you like you can create helper functions for creating instances of this type. However, under this approach you either need to have lots of quoting and other line noise (e.g. (makeTag &quot;foo&quot; [(&quot;class&quot;, &quot;foo&quot;)])), or you have to define separate functions for each tag, which  is rather a waste of time (although I suppose you could just do it for 10 or 20 of the most common tags). Still, the bolierplate thingy you link to is very interesting and would certainly make things easier.

</description>
		<content:encoded><![CDATA[	<p>Your first suggestion doesn&#8217;t really work. If you use tuples to handle the nesting, you have no way of iterating over the elements of a tuple (and this is pretty much essential if you want to actually do something with the data). You can&#8217;t use nested tuples as a replacement for nested lists.</p>
	<p>As I said, you can create a custom <acronym title="HyperText Markup Language">HTML</acronym> datatype, and if you like you can create helper functions for creating instances of this type. However, under this approach you either need to have lots of quoting and other line noise (e.g. (makeTag &#8220;foo&#8221; [(&#8221;class&#8221;, &#8220;foo&#8221;)])), or you have to define separate functions for each tag, which  is rather a waste of time (although I suppose you could just do it for 10 or 20 of the most common tags). Still, the bolierplate thingy you link to is very interesting and would certainly make things easier.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Alex</title>
		<link>http://jeffrey.yasskin.info/blog/archives/2005/02/09/haskell-vs-scheme/#comment-900</link>
		<pubDate>Fri, 27 May 2005 16:36:20 -0700</pubDate>
		<guid>http://jeffrey.yasskin.info/blog/archives/2005/02/09/haskell-vs-scheme/#comment-900</guid>
					<description>Hmm, reading through my last comment it sounds a bit stronger than I meant it to. I basically take your point that there are pretty good Haskell alternatives to s-expr syntax.</description>
		<content:encoded><![CDATA[	<p>Hmm, reading through my last comment it sounds a bit stronger than I meant it to. I basically take your point that there are pretty good Haskell alternatives to s-expr syntax.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Stefan Holdermans</title>
		<link>http://jeffrey.yasskin.info/blog/archives/2005/02/09/haskell-vs-scheme/#comment-1222</link>
		<pubDate>Thu, 29 Sep 2005 02:06:58 -0700</pubDate>
		<guid>http://jeffrey.yasskin.info/blog/archives/2005/02/09/haskell-vs-scheme/#comment-1222</guid>
					<description>It could be argued that this Scheme version of zip is actually just a heterogeneous transpose. And, of course, transpose can easily be defined in Haskell as well, albeit homogeneously. (Generalizing it to work on hetereogeneous list as well, may very well be possible, but, admittedly, this will surely take some type class trickery. Extensions that add support for generic programming, for instance through structural polymorphism, like Generic Haskell, allow you to write binary zips that operate on a variety of types, not just lists and pairs.)</description>
		<content:encoded><![CDATA[	<p>It could be argued that this Scheme version of zip is actually just a heterogeneous transpose. And, of course, transpose can easily be defined in Haskell as well, albeit homogeneously. (Generalizing it to work on hetereogeneous list as well, may very well be possible, but, admittedly, this will surely take some type class trickery. Extensions that add support for generic programming, for instance through structural polymorphism, like Generic Haskell, allow you to write binary zips that operate on a variety of types, not just lists and pairs.)
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Bob</title>
		<link>http://jeffrey.yasskin.info/blog/archives/2005/02/09/haskell-vs-scheme/#comment-6343</link>
		<pubDate>Tue, 25 Jul 2006 18:31:20 -0700</pubDate>
		<guid>http://jeffrey.yasskin.info/blog/archives/2005/02/09/haskell-vs-scheme/#comment-6343</guid>
					<description>I don't think this comparison of guile's map1 to haskell's map is entirely fair, since in scheme I would just directly convert the purely functional map primitive into a tail recursive version without using set-car! and such.  

eg. using
&lt;pre&gt;(define (map f lst)
   (let loop ((lst lst)
              (res '()))
     (if (null? lst)
       (reverse res)
       (loop (cdr lst)
             (cons (f (car lst)) res)))))&lt;/pre&gt;

instead of:

&lt;pre&gt;(define (map f lst)
   (if (null? lst)
     lst
     (cons (f (car lst))
           (map f (cdr lst)))))&lt;/pre&gt;

I know it's non idiomatic, but I would also consider defining lazy-map in scheme, (I use a purely functional implementation of delay and force) and I would be open to using foldr to implement map, one of those would be preferable.

I would be interested to learn more about sexpr-like prefix syntax in haskell, maybe I am crazy but I really don't care for complex syntaxes.</description>
		<content:encoded><![CDATA[	<p>I don&#8217;t think this comparison of guile&#8217;s map1 to haskell&#8217;s map is entirely fair, since in scheme I would just directly convert the purely functional map primitive into a tail recursive version without using set-car! and such.  </p>
	<p>eg. using</p>
	<pre>(define (map f lst)
   (let loop ((lst lst)
              (res '()))
     (if (null? lst)
       (reverse res)
       (loop (cdr lst)
             (cons (f (car lst)) res)))))</pre>
	<p>instead of:</p>
	<pre>(define (map f lst)
   (if (null? lst)
     lst
     (cons (f (car lst))
           (map f (cdr lst)))))</pre>
	<p>I know it&#8217;s non idiomatic, but I would also consider defining lazy-map in scheme, (I use a purely functional implementation of delay and force) and I would be open to using foldr to implement map, one of those would be preferable.</p>
	<p>I would be interested to learn more about sexpr-like prefix syntax in haskell, maybe I am crazy but I really don&#8217;t care for complex syntaxes.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>

