This is our yield from the Haskell treasure hunt.

## Special forms

1. Haskell has no mutation of bindings (or data structures, i.e. set-car!).
2. Haskell knows the type of everything at compile-time. (Caveat: contravariance, as discussed in the Sather Treasure.)
3. `begin` is used in Scheme to evaluate statements for side-effect. Haskell has no side-effects. (However, Haskell 1.3 does have a `do` form, used for sequentialization.)
4. Lazy evaluation is the default in Haskell. Haskell does however have the opposite of `delay`, called
5. `if` does not need to be a special form in Haskell, because of lazy evaluation.

## Flattening

Here is one attempt, using the declarative style:
```flatten :: [[a]] -> [a]
flatten [[]] = []
flatten ([]:ys) = flatten ys
flatten ((x:xs):ys) = x : (flatten (xs:ys))
```
However, the last two lines are just the append operator `++`:
```flatten :: [[a]] -> [a]
flatten [] = []
flatten (y:ys) = y ++ (flatten ys)
```
But this is just a fold:
```flatten :: [[a]] -> [a]
flatten = foldl (++) []
```
Higher-order functions have allowed us to shorten the code. Whether or not it is clearer is up to you.

Alas, we cannot implement `superflatten`, because it must have only one type. Lists of different depths have different types:

```[1, 2] :: [Int]
[[1,2], [3,4]] :: [[Int]]
[[[1,2],[3,4]], [[5,6],[7,8]]] :: [[[Int]]]
```
And these types cannot be unified by a type-variable.

However, we can implement `superflatten`, aka `fringe`, on binary trees. See the Haskell tutorial.

## List comprehension

List comprehensions are handy, as demonstrated here, but they are just sugar. See SICP for a desugaring, called "collect".

Array comprehensions, however, are much more important. Otherwise we would have to use the inefficient incremental-update operators.

## Higher-order functions

```hash :: [Char] -> Int
hash = (foldl (+) 0) . (map ord)

hash "MSDOS 6.000"    -- prints 666
hash "SYSTEM 7.0"     -- prints 666
```
Coincidence? We think not.
{"ft_lang_label":"__label__en","ft_lang_prob":0.842165,"math_prob":0.9467379,"size":1322,"snap":"2021-43-2021-49","text_gpt3_token_len":378,"char_repetition_ratio":0.12670714,"word_repetition_ratio":0.027149322,"special_character_ratio":0.33585477,"punctuation_ratio":0.23104693,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97289425,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-20T06:00:53Z\",\"WARC-Record-ID\":\"<urn:uuid:4f72b2cf-d192-4929-85c9-a69c4ef03e21>\",\"Content-Length\":\"2959\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9769cbad-a293-4ea0-b9df-d1ac6b135a01>\",\"WARC-Concurrent-To\":\"<urn:uuid:4c7b17ba-dcd9-4b9c-83b3-e4982fac032a>\",\"WARC-IP-Address\":\"18.27.72.48\",\"WARC-Target-URI\":\"http://alumni.media.mit.edu/~tpminka/PLE/haskell/haskell-sol.html\",\"WARC-Payload-Digest\":\"sha1:VCJS5ANAWVL6JPQDIK2HW4QFAD6CWQNN\",\"WARC-Block-Digest\":\"sha1:EQZBVS57YQR33RSTPXHT4JZGO75L44TL\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585302.91_warc_CC-MAIN-20211020055136-20211020085136-00300.warc.gz\"}"}