6 research outputs found
Maximum Segment Sum, Monadically (distilled tutorial, with solutions)
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.Comment: Revision of the article in Proceedings DSL 2011, EPTCS 66,
arXiv:1109.0323, to provide solutions to the exercise
Generic functional programming with types and relations
A generic functional program is one which is parameterised by datatype. By installing specific
choices, for example Iists or trees, different programs are obtained that are, nevertheless,
abstractly the same. The purpose of this paper is to explore the possibility of deriving generic
programs. Part of the theory of lists that deals with segments is recast as a theory about
'segments' in a wide class of datatypes, and then used to pose and solve a generic version of
a well-known problem
Generic Functional Programming with Types and Relations
A generic functional program is one which is parameterised by datatype. By installing specific
choices, for example Iists or trees, different programs are obtained that are, nevertheless,
abstractly the same. The purpose of this paper is to explore the possibility of deriving generic
programs. Part of the theory of lists that deals with segments is recast as a theory about
'segments' in a wide class of datatypes, and then used to pose and solve a generic version of
a well-known problem