A second year course on data structures based on functional programming

Author(s):  
Manuel Núñez ◽  
Pedro Palao ◽  
Ricardo Peña
2004 ◽  
Vol 14 (4) ◽  
pp. 429-472 ◽  
Author(s):  
BRIAN MCNAMARA ◽  
YANNIS SMARAGDAKIS

We describe the FC++ library, a rich library supporting functional programming in C++. Prior approaches to encoding higher order functions in C++ have suffered with respect to polymorphic functions from either lack of expressiveness or high complexity. In contrast, FC++ offers full and concise support for higher-order polymorphic functions through a novel use of C++ type inference. The FC++ library has a number of useful features, including a generalized mechanism to implement currying in C++, a “lazy list” class which enables the creation of “infinite data structures”, a subtype polymorphism facility, and an extensive library of useful functions, including a large part of the Haskell Standard Prelude. The FC++ library has an efficient implementation. We show the results of a number of experiments which demonstrate the value of optimizations we have implemented. These optimizations have improved the run-time performance by about an order of magnitude for some benchmark programs that make heavy use of FC++ lazy lists. We also make an informal performance comparison with similar programs written in Haskell.


2014 ◽  
Vol 6 (2) ◽  
pp. 147-157
Author(s):  
Konrad Grzanek

Abstract Directed acyclic graphs and trees in particular belong to the most extensively used data structures. Visualizing them properly is a key to a success when developing complex algorithms that make use of them. Textual visualizations a la UNIX tree command is essential when the urge is to deal with large trees. Our aim was to design a library that would exploit this approach and to make an implementation of it for a purely functional programming language. The library uses monads to print directly into an output stream or to generate immutable Strings. This paper gives a detailed overview of the solution.


2013 ◽  
Vol 23 (2) ◽  
pp. 145-160
Author(s):  
MARK P. JONES

AbstractWe describe a concise and elegant functional program, written in Haskell, that computes solutions for a classic puzzle known as the “snake cube.” The program reflects some of the fundamental characteristics of the functional style, identifying key abstractions, and defining a small collection of operators for manipulating and working with the associated values. Well-suited for an introductory course on functional programming, this example highlights the use of visualization tools to explain and demonstrate the choices of data structures and algorithms that are used in the development.


1996 ◽  
Vol 3 (56) ◽  
Author(s):  
Zine-El-Abidine Benaissa ◽  
Pierre Lescanne ◽  
Kristoffer H. Rose

<p>We present the lambda sigma^a_w calculus, a formal synthesis of the concepts of<br />sharing and explicit substitution for weak reduction. We show how<br />lambda sigma^a_w can be used as a foundation of implementations of functional<br />programming languages by modelling the essential ingredients of such<br />implementations, namely weak reduction strategies, recursion, space<br />leaks, recursive data structures, and parallel evaluation, in a uniform way.<br />First, we give a precise account of the major reduction strategies<br />used in functional programming and the consequences of choosing <br /> lambda-graph-reduction vs. environment-based evaluation. Second, we show<br />how to add constructors and explicit recursion to give a precise account<br />of recursive functions and data structures even with respect to<br />space complexity. Third, we formalize the notion of space leaks in lambda sigma^a_w<br />and use this to define a space leak free calculus; this suggests optimisations<br />for call-by-need reduction that prevent space leaking and enables<br />us to prove that the "trimming" performed by the STG machine does<br />not leak space.<br />In summary we give a formal account of several implementation<br />techniques used by state of the art implementations of functional programming<br />languages.</p><p>Keywords. Implementation of functional programming, lambda<br />calculus, weak reduction, explicit substitution, sharing, recursion, space<br />leaks.</p>


2021 ◽  
Vol 5 (ICFP) ◽  
pp. 1-30
Author(s):  
Joshua Yanovski ◽  
Hoang-Hai Dang ◽  
Ralf Jung ◽  
Derek Dreyer

The Rust language offers a promising approach to safe systems programming based on the principle of aliasing XOR mutability : a value may be either aliased or mutable, but not both at the same time. However, to implement pointer-based data structures with internal sharing, such as graphs or doubly-linked lists, we need to be able to mutate aliased state. To support such data structures, Rust provides a number of APIs that offer so-called interior mutability : the ability to mutate data via method calls on a shared reference. Unfortunately, the existing APIs sacrifice flexibility, concurrent access, and/or performance, in exchange for safety. In this paper, we propose a new Rust API called GhostCell which avoids such sacrifices by separating permissions from data : it enables the user to safely synchronize access to a collection of data via a single permission. GhostCell repurposes an old trick from typed functional programming: branded types (as exemplified by Haskell’s ST monad), which combine phantom types and rank-2 polymorphism to simulate a lightweight form of state-dependent types. We have formally proven the soundness of GhostCell by adapting and extending RustBelt, a semantic soundness proof for a representative subset of Rust, mechanized in Coq.


1999 ◽  
Vol 9 (1) ◽  
pp. 93-104 ◽  
Author(s):  
RALF HINZE

Functional programming languages are an excellent tool for teaching algorithms and data structures. This paper explains binomial heaps, a beautiful data structure for priority queues, using the functional programming language Haskell (Peterson and Hammond, 1997). We largely follow a deductive approach: using the metaphor of a tennis tournament we show that binomial heaps arise naturally through a number of logical steps. Haskell supports the deductive style of presentation very well: new types are introduced at ease, algorithms can be expressed clearly and succinctly, and Haskell's type classes allow to capture common algorithmic patterns. The paper aims at the level of an undergraduate student who has experience in reading and writing Haskell programs, and who is familiar with the concept of a priority queue.


2001 ◽  
Vol 11 (4) ◽  
pp. 425-432 ◽  
Author(s):  
STEFAN KAHRS

Chris Okasaki showed how to implement red-black trees in a functional programming language. Ralf Hinze incorporated even the invariants of such data structures into their types, using higher-order nested datatypes. We show how one can achieve something very similar without the usual performance penalty of such types, by combining the features of nested datatypes, phantom types and existential type variables.


2020 ◽  
Vol 15 ◽  
pp. 202-205
Author(s):  
Monika Kaczorowska

The research paper contains a review and analysis of common programming mistakes made by first and second year students of Computer Science. The data were collected during the courses entitled “Algorithmics and Data Structures” and “Numerical Methods”, where students have to write programs in the C++ language. The article includes examples of three selected mistake types. A comparison of mistakes made by first and second year students is presented. The analysis carried out shows that the percentage of mistakes made decreases when the students are in the second year, but three types of mistakes demonstrate the opposite trend. It can be concluded that those three types of mistakes are related to the course of Numerical Methods, where students have to deal with a significant amount of mathematical expressions. The results show that the students have the most significant problems with memory management.


Sign in / Sign up

Export Citation Format

Share Document