<div dir="ltr">On Thu, Sep 29, 2016 at 4:28 PM, Jake <span dir="ltr"><<a href="mailto:jake.waksbaum@gmail.com" target="_blank">jake.waksbaum@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><pre><font face="sans-serif">I think this may have something to do with t<span style="font-size:13px">he </span></font><span style="font-family:sans-serif;font-size:13px">default definition of many in the definition of </span><a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#Alternative" target="_blank" style="font-family:sans-serif;font-size:13px">Alternative</a><span style="font-family:sans-serif;font-size:13px">:</span><br></pre><div><pre><span style="color:rgb(7,54,66)">many</span> <span style="color:rgb(220,50,47)">::</span> <a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627395956" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(95,95,175)">f</span></a> <a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627395960" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(95,95,175)">a</span></a> <span style="color:rgb(220,50,47)">-></span> <a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627395956" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(95,95,175)">f</span></a> <span style="color:rgb(220,50,47)">[</span><a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627395960" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(95,95,175)">a</span></a><span style="color:rgb(220,50,47)">]</span>
<a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#many" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(7,54,66)">many</span></a> <a></a><a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627395964" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(7,54,66)">v</span></a> <span style="color:rgb(220,50,47)">=</span> <a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627395965" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(7,54,66)">many_v</span></a>
<a></a> <span style="color:rgb(175,0,95)">where</span>
<a></a> <a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627395965" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(7,54,66)">many_v</span></a> <span style="color:rgb(220,50,47)">=</span> <a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627395966" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(7,54,66)">some_v</span></a> <a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#%3C%7C%3E" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(211,54,130)"><|></span></a> <a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#pure" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(7,54,66)">pure</span></a> <span style="color:rgb(220,50,47)">[</span><span style="color:rgb(220,50,47)">]</span>
<a></a> <a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627395966" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(7,54,66)">some_v</span></a> <span style="color:rgb(220,50,47)">=</span> <span style="color:rgb(220,50,47)">(</span><a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#fmap" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(7,54,66)">fmap</span></a> <span style="color:rgb(220,50,47)">(</span><span style="color:rgb(220,50,47)">:</span><span style="color:rgb(220,50,47)">)</span> <a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627395964" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(7,54,66)">v</span></a><span style="color:rgb(220,50,47)">)</span> <a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#%3C%2A%3E" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(211,54,130)"><*></span></a> <a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local-1627395965" style="text-decoration:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span style="color:rgb(7,54,66)">many_v</span></a>
</pre>many_v and some_v are mutually recursive functions, and it may be that this prevents the thunks from being made available to take in some way. I'm really not sure though, this is just an idea about why this is not quite the same as (take $ repeat 1)</div></div></blockquote></div><div class="gmail_extra"><br></div><div class="gmail_extra">The problem is that many is creating an infinite sum that’s nested to the left. So you’re trying to compute</div><div class="gmail_extra"><br></div><div class="gmail_extra">(((… <|> Just [1,1,1]) <|> Just [1,1]) <|> Just [1]) <|> Just 1</div><div class="gmail_extra"><br></div><div class="gmail_extra">which will never terminate because Maybe is strict in the first argument to <|>.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">As a practical matter, the Alternative instance for Maybe should probably be changed to either call error or return Just (repeat v).</div><div class="gmail_extra"><br></div><div class="gmail_extra">Similarly, we should probably flip the order for many in the instance for [].</div><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Dave Menendez <<a href="mailto:dave@zednenem.com" target="_blank">dave@zednenem.com</a>><br><<a href="http://www.eyrie.org/~zednenem/" target="_blank">http://www.eyrie.org/~zednenem/</a>></div>
</div></div>