Lutz Donnerhacke <l...@iks-jena.de> wrote: >> liftM (take 3) $ mapM Just [1,2,3,undefined] > Just [1,2,3]
>> liftM (take 3) $ mapM Just [1,2 ..] > _|_ > Now the question arises, how to define sequence, to allow indefinite long > inputs?
If I understand you correctly, you would like the result Just [1,2,3] instead of _|_ in the last example.
But that's unlikely to work. If you look at it in terms of sequence,
liftM (take 3) $ sequence [Just 42, Just 13, Just 7, ....]
the result depends on the whole list, not just the initial segment: If there's a Nothing *anywhere* in the list, the result is Nothing, otherwise it's Just [42,13,7]. So the result can only be determined after inspecting *all* of the remaining list. If the list is infinite, this cannot happen in finite time.
* Dirk Thierbach wrote: > the result depends on the whole list, not just the initial segment: If > there's a Nothing *anywhere* in the list, the result is Nothing, otherwise > it's Just [42,13,7].
That was the point, I missed. And that is the reason why (bind) is strict in both arguments for the Monad Maybe. Thank you.