Haskell logo CIS 552: Advanced Programming

Fall 2021

  • Home
  • Schedule
  • Homework
  • Resources
  • Software
  • Style guide
Note: this is the stubbed version of module Queue. Try to figure out how to fill in all parts of this file marked undefined. CIS 552 students should be able to access this code through github. Eventually, the completed version will be available.

In class exercise: Purely Functional Queues

Today's technical challenge is to implement a persistent queue data structure.

> module Queue where

You should use quickcheck to test this module. If you want to use additional library operations to complete this exercise, you may import them here. (For example, our solution uses at least one function from the Data.Maybe library.)

> import Test.QuickCheck
  1. Define an interface for a purely functional Queue (FIFO). Your interface must (at least) define some data structure, called Q, include a representation of an empty queue (queue), a way to add an element to the end of the queue (enq) and a way to remove the element at the beginning of the queue (deq), if the queue is nonempty. The queue must be polymorphic over the type of elements that it stores. You may include additional operations in your interface, if you wish.
> -- replace these definitions with something more appropriate
> data Q = Q
> empty :: Q
> enq :: Q 
> deq :: Q
  1. Now define some properties that your queue should satisfy. (Note: if you want to add additional operations to your queue interface to help with stating these properties, you may.)
  1. Implement your interface.
> empty = undefined
> enq = undefined
> deq = undefined
  1. Make an arbitrary instance.
  1. Run your tests.
Design adapted from Minimalistic Design | Powered by Pandoc and Hakyll