Initialize and every other tentative distance to infinity. The Bellman-Ford algorithm repeatedly relaxes every directed edge:
for v in V: d[v] = infinity; parent[v] = none
d[s] = 0
repeat |V|-1 times:
    changed = false
    for each edge (u,v) of weight w:
        if d[u] != infinity and d[u] + w < d[v]:
            d[v] = d[u] + w
            parent[v] = u
            changed = true
    if not changed: break
for each edge (u,v) of weight w:
    if d[u] != infinity and d[u] + w < d[v]:
        report a reachable negative-weight cycle
An unreachable vertex retains infinity. A reachable negative-weight cycle prevents finite shortest-walk distances for vertices reachable from that cycle, so the detection case must not be reported as an ordinary finite answer. With edge-list scans the worst-case work is , conventionally stated as , and the auxiliary storage is beyond the graph.
Arrange that each state already begins with the next passing element, or is empty:
filter p = unfold null head next . seek
  where
    seek = dropWhile (not . p)
    next = seek . tail
The initial seek skips the rejected prefix. After an element is emitted, next removes it and skips the following rejected run. Thus null guards both partial list operations and the filtering a list by unfolding invariant is preserved.
For a finite input of length and constant-cost predicate evaluation, each input element is tested once and each list cell is passed a bounded number of times: the total work is , as for the usual recursive list filter. This version may have different constant overhead. Recomputing dropWhile independently in the stopping, output and transition expressions could repeat scans; keeping the already-filtered suffix as state avoids that. On an infinite rejected tail, finding another output diverges, just as the standard lazy filter does.
Store two consecutive Fibonacci numbers as the state:
fibs :: [Integer]
fibs = unfold (const False) fst step (0,1)
  where
    step (a,b) = (b,a+b)
The invariant is that the state is , with . Emitting its first component and updating the pair therefore produces . Integer avoids fixed-width overflow; the bit cost of adding increasingly large integers is separate from the number of unfold steps.
Using the specified list unfold, the definitions are
map f     = unfold null (f . head) tail
iterate f = unfold (const False) id f
For map, the current state is the remaining input list. null prevents head and tail from being evaluated on an empty list. For iterate, the stop predicate is always false and the output is the current state itself. Its transition is f, so the original seed is emitted before the first application of f.
The required function composition is
unfold p f g = map f . takeWhile (not . p) . iterate g
iterate g supplies the successive states, takeWhile (not . p) retains precisely those before the first stopping state, and map f produces their outputs. If the initial state satisfies the stopping predicate, both sides return the empty list. Otherwise both emit the same head and repeat from g x; the same argument applies to every demanded finite prefix of an infinite result.
The standard Haskell definition and principal type are
iterate :: (a -> a) -> a -> [a]
iterate f x = x : iterate f (f x)
Under lazy evaluation, this produces successive states as demanded. An infinite spine does not require all elements to be evaluated at once; productivity still depends on the demanded computations terminating.
The most general polymorphic type is
unfold :: (s -> Bool) -> (s -> a) -> (s -> s) -> s -> [a]
The stopping predicate consumes a state, the output function turns that state into one list element, and the transition function supplies another state of the same type. The state type and output type need not coincide. This is a list unfold with separate stopping, output and transition arguments.

Pinned article: Introduction to the OurBigBook Project

Welcome to the OurBigBook Project! Our goal is to create the perfect publishing platform for STEM subjects, and get university-level students to write the best free STEM tutorials ever.
Everyone is welcome to create an account and play with the site: ourbigbook.com/go/register. We belive that students themselves can write amazing tutorials, but teachers are welcome too. You can write about anything you want, it doesn't have to be STEM or even educational. Silly test content is very welcome and you won't be penalized in any way. Just keep it legal!
We have two killer features:
  1. topics: topics group articles by different users with the same title, e.g. here is the topic for the "Fundamental Theorem of Calculus" ourbigbook.com/go/topic/fundamental-theorem-of-calculus
    Articles of different users are sorted by upvote within each article page. This feature is a bit like:
    • a Wikipedia where each user can have their own version of each article
    • a Q&A website like Stack Overflow, where multiple people can give their views on a given topic, and the best ones are sorted by upvote. Except you don't need to wait for someone to ask first, and any topic goes, no matter how narrow or broad
    This feature makes it possible for readers to find better explanations of any topic created by other writers. And it allows writers to create an explanation in a place that readers might actually find it.
    Figure 1.
    Screenshot of the "Derivative" topic page
    . View it live at: ourbigbook.com/go/topic/derivative
  2. local editing: you can store all your personal knowledge base content locally in a plaintext markup format that can be edited locally and published either:
    This way you can be sure that even if OurBigBook.com were to go down one day (which we have no plans to do as it is quite cheap to host!), your content will still be perfectly readable as a static site.
    Figure 5. . You can also edit articles on the Web editor without installing anything locally.
    Video 3.
    Edit locally and publish demo
    . Source. This shows editing OurBigBook Markup and publishing it using the Visual Studio Code extension.
  3. https://raw.githubusercontent.com/ourbigbook/ourbigbook-media/master/feature/x/hilbert-space-arrow.png
  4. Infinitely deep tables of contents:
    Figure 6.
    Dynamic article tree with infinitely deep table of contents
    .
    Descendant pages can also show up as toplevel e.g.: ourbigbook.com/cirosantilli/chordate-subclade
All our software is open source and hosted at: github.com/ourbigbook/ourbigbook
Further documentation can be found at: docs.ourbigbook.com
Feel free to reach our to us for any help or suggestions: docs.ourbigbook.com/#contact