David Menendez dave at zednenem.com
Fri Oct 30 13:32:59 EDT 2009

```On Fri, Oct 30, 2009 at 12:59 PM, Luke Palmer <lrpalmer at gmail.com> wrote:
> On Fri, Oct 30, 2009 at 10:39 AM, Tom Davie <tom.davie at gmail.com> wrote:
>> Of note, there is a sensible monad instance for zip lists which I *think*
>> agrees with the Applicative one, I don't know why they're not monads:
>> instance Monad (ZipList a) where
>>   return = Ziplist . return
>>   join (ZipList []) = ZipList []
>>   join (ZipList (a:as)) = zlHead a `zlCons` join (map zlTail as)
>
> IIRC, that doesn't satisfy the associativity law, particularly when
> you are joining a list of lists of different lengths.  2 minutes of
> experimenting failed to find me the counterexample though.

This works fine for infinite lists, since an infinite list is
equivalent to Nat -> a.

With finite lists, this implementation hits problems with calling head
on empty lists. If I rewrite it to avoid that problem, the
associativity law fails.

tail' [] = []
tail' (_:as) = as

diag ((a:_):bs) = a : diag (map tail' bs)
diag _ = []

bind :: [Int] -> (Int -> [Int]) -> [Int]  -- monomorphic for QuickCheck
bind m f = diag (map f m)

Prelude Test.QuickCheck Test.QuickCheck.Function> quickCheck \$ \m
(Function _ f) (Function _ g) -> bind (bind m f) g == bind m (\x ->
bind (f x) g)
*** Failed! Falsifiable (after 16 tests and 23 shrinks):
[1,0]
{0 -> [-13,0], 1 -> }
{-13 -> [], 0 -> [0,0]}

The left side is [0,0], the right side is .

--
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.78025347,"math_prob":0.83552176,"size":1635,"snap":"2020-24-2020-29","text_gpt3_token_len":509,"char_repetition_ratio":0.083384424,"word_repetition_ratio":0.013793103,"special_character_ratio":0.34250763,"punctuation_ratio":0.163142,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9670838,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-06-04T12:31:29Z\",\"WARC-Record-ID\":\"<urn:uuid:6334b690-4f4d-44d1-a492-5c1d799878b5>\",\"Content-Length\":\"4678\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:735f2d3e-06a1-4615-b4fc-01402a300246>\",\"WARC-Concurrent-To\":\"<urn:uuid:00681a22-2ffa-4bb3-bbca-a3b0c6d05975>\",\"WARC-IP-Address\":\"23.253.242.70\",\"WARC-Target-URI\":\"https://mail.haskell.org/pipermail/haskell-cafe/2009-October/068347.html\",\"WARC-Payload-Digest\":\"sha1:PITO3WGB2CDXEX7NBOHQCHYBFZCPGZLX\",\"WARC-Block-Digest\":\"sha1:FMFU2XJKAYUI3F23NJ367FFUFHB7P6RL\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-24/CC-MAIN-2020-24_segments_1590347439928.61_warc_CC-MAIN-20200604094848-20200604124848-00177.warc.gz\"}"}