English

Maximum Segment Sum, Monadically (distilled tutorial, with solutions)

Data Structures and Algorithms 2011-11-21 v2 Discrete Mathematics Programming Languages

Abstract

The maximum segment sum problem is to compute, given a list of integers, the largest of the sums of the contiguous segments of that list. This problem specification maps directly onto a cubic-time algorithm; however, there is a very elegant linear-time solution too. The problem is a classic exercise in the mathematics of program construction, illustrating important principles such as calculational development, pointfree reasoning, algebraic structure, and datatype-genericity. Here, we take a sideways look at the datatype-generic version of the problem in terms of monadic functional programming, instead of the traditional relational approach; the presentation is tutorial in style, and leavened with exercises for the reader.

Keywords

Cite

@article{arxiv.1109.0782,
  title  = {Maximum Segment Sum, Monadically (distilled tutorial, with solutions)},
  author = {Jeremy Gibbons},
  journal= {arXiv preprint arXiv:1109.0782},
  year   = {2011}
}

Comments

Revision of the article in Proceedings DSL 2011, EPTCS 66, arXiv:1109.0323, to provide solutions to the exercises

R2 v1 2026-06-21T18:59:36.880Z