
On Thu, Sep 29, 2016 at 4:28 PM, Jake
I think this may have something to do with the default definition of many in the definition of Alternative http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#Alter...:
many :: f http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local... a http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local... -> f http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local... [a http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local...]many http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#many v http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local... = many_v http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local... where many_v http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local... = some_v http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local... <|> http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#%3C%7... pure http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#pure [] some_v http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local... = (fmap http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#fmap (:) v http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local...) <*> http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#%3C%2... many_v http://hackage.haskell.org/package/base-4.9.0.0/docs/src/GHC.Base.html#local...
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)
The problem is that many is creating an infinite sum that’s nested to the
left. So you’re trying to compute
(((… <|> Just [1,1,1]) <|> Just [1,1]) <|> Just [1]) <|> Just 1
which will never terminate because Maybe is strict in the first argument to
<|>.
As a practical matter, the Alternative instance for Maybe should probably
be changed to either call error or return Just (repeat v).
Similarly, we should probably flip the order for many in the instance for
[].
--
Dave Menendez