## Asymptotic Improvement of Computations over Free Monads (2008)

### Cached

### Download Links

- [wwwtcs.inf.tu-dresden.de]
- [www.iai.uni-bonn.de]
- DBLP

### Other Repositories/Bibliography

Venue: | In Proceedings, Mathematics of Program Construction |

Citations: | 9 - 0 self |

### BibTeX

@INPROCEEDINGS{Voigtländer08asymptoticimprovement,

author = {Janis Voigtländer and Technische Universität Dresden},

title = {Asymptotic Improvement of Computations over Free Monads},

booktitle = {In Proceedings, Mathematics of Program Construction},

year = {2008},

pages = {388--403}

}

### OpenURL

### Abstract

Abstract. We present a low-effort program transformation to improve the efficiency of computations over free monads in Haskell. The development is calculational and carried out in a generic setting, thus applying to a variety of datatypes. An important aspect of our approach is the utilisation of type class mechanisms to make the transformation as transparent as possible, requiring no restructuring of code at all. There is also no extra support necessary from the compiler (apart from an up-to-date type checker). Despite this simplicity of use, our technique is able to achieve true asymptotic runtime improvements. We demonstrate this by examples for which the complexity is reduced from quadratic to linear. 1

### Citations

1384 | The essence of functional programming
- Wadler
- 1992
(Show Context)
Citation Context ...c to linear. 1 Introduction Monads [1] have become everyday structures for Haskell programmers to work with. Not only do monads allow to safely encapsulate impure features of the programming language =-=[2,3]-=-, but they are also used in pure code to separate concerns and provide modular design [4,5]. But, as usual in software construction, modularity comes at a cost, typically with respect to program effic... |

779 | Notions of computation and monads
- Moggi
- 1991
(Show Context)
Citation Context ...city of use, our technique is able to achieve true asymptotic runtime improvements. We demonstrate this by examples for which the complexity is reduced from quadratic to linear. 1 Introduction Monads =-=[1]-=- have become everyday structures for Haskell programmers to work with. Not only do monads allow to safely encapsulate impure features of the programming language [2,3], but they are also used in pure ... |

394 |
Types, abstraction, and parametric polymorphism
- Reynolds
- 1983
(Show Context)
Citation Context ... rep distributes over all of these by (11)–(13), we have rep (m :: FREE φ α) = (m :: C (FREE φ) α) A more formal proof would require techniques akin to those used for deriving so-called free theorems =-=[9,10]-=-. 4. In the fourth line, m still has the type FREE φ α. The essence of all the above is that improve m can be used wherever a value of type FREE φ α is expected, but that m itself must (also) have the... |

353 | QuickCheck: a lightweight tool for random testing of Haskell programs
- Claessen, Hughes
- 2000
(Show Context)
Citation Context ...cs = FINISH a run (WRAP (GETCHAR f )) cs = READ (run (f (hd cs)) (tl cs)) run (WRAP (PUTCHAR c p)) cs = PRINT c (run p cs) Simulating a run of revEcho on some input stream, or indeed using QuickCheck =-=[12]-=- to analyse many such runs, takes the following form: run revEcho stream . It turns out that this requires runtime quadratic in the number of characters in stream before the first occurrence of a spac... |

347 | Theorems for free
- Wadler
- 1989
(Show Context)
Citation Context ... rep distributes over all of these by (11)–(13), we have rep (m :: FREE φ α) = (m :: C (FREE φ) α) A more formal proof would require techniques akin to those used for deriving so-called free theorems =-=[9,10]-=-. 4. In the fourth line, m still has the type FREE φ α. The essence of all the above is that improve m can be used wherever a value of type FREE φ α is expected, but that m itself must (also) have the... |

253 | Monad transformers and modular interpreters
- Liang, Hudak, et al.
- 1995
(Show Context)
Citation Context ...ers to work with. Not only do monads allow to safely encapsulate impure features of the programming language [2,3], but they are also used in pure code to separate concerns and provide modular design =-=[4,5]-=-. But, as usual in software construction, modularity comes at a cost, typically with respect to program efficiency. We propose a method to improve the efficiency of code over a large variety of monads... |

75 | Functional Programming with Overloading and Higherorder
- Jones
- 1995
(Show Context)
Citation Context ...ke apparent why the runtime is now only of linear complexity. 3 The Generic Setting To deal with a variety of different datatypes in one stroke, we use the by now folklore approach of two-level types =-=[7,8]-=-. A functor is an instance of the following type constructor class: class FUNCTOR φ where fmap :: (α → β) → φ α → φ β satisfying the following two laws: fmap id t = t (8) fmap f (fmap g t) = fmap (f ◦... |

70 | Cheap Deforestation for Non-strict Functional Languages
- Gill
- 1996
(Show Context)
Citation Context ...istributed) arrays, and should reap the same benefits there. 5.2 Short Cut Fusion for Monadic Computations Ghani et al. [15,16] observe that the augment combinator known from work on short cut fusion =-=[17,18]-=- has a monadic interpretation, and thus enables fusion for programs on certain monadic datatypes. This strand of work is thus the one most closely related to ours, since it also aims to improve the ef... |

56 |
The essence of functional programming (invited talk
- Wadler
- 1992
(Show Context)
Citation Context ...ers to work with. Not only do monads allow to safely encapsulate impure features of the programming language [2,3], but they are also used in pure code to separate concerns and provide modular design =-=[4,5]-=-. But, as usual in software construction, modularity comes at a cost, typically with respect to program efficiency. We propose a method to improve the efficiency of code over a large variety of monads... |

52 |
A novel representation of lists and its application to the function \reverse
- Hughes
- 1986
(Show Context)
Citation Context ...tively nested appends cause quadratic runtime. And in fact there is a similar cure. We can create an alternative representation of trees somewhat akin to the “novel representation of lists” of Hughes =-=[6]-=-, alsoknown as difference lists. Just as the latter abstract over the end of a list, we abstract over the leaves of a tree as follows: newtype CTREE α = CTREE (∀β. (α → TREE β) → TREE β) The connecti... |

43 | Data types à la carte
- Swierstra
- 2008
(Show Context)
Citation Context ...finition of >>= for the instance MONAD (FREE φ) C (λh → WRAP (fmap (>>= h) t)) = by definition of wrap for the instance FREELIKE φ (FREE φ) C (λh → wrap (fmap (>>= h) t)) = as above wrap (fmap rep t) =-=(13)-=-Our “magic function” is again the same as abs up to typing: improve :: FUNCTOR φ ⇒ (∀µ. FREELIKE φ µ ⇒ µ α) → FREE φ α improve m = abs m In fact, comparing their types should be instructive. Recall t... |

17 |
A generalization of short-cut fusion and its correctness proof
- Johann
(Show Context)
Citation Context ...istributed) arrays, and should reap the same benefits there. 5.2 Short Cut Fusion for Monadic Computations Ghani et al. [15,16] observe that the augment combinator known from work on short cut fusion =-=[17,18]-=- has a monadic interpretation, and thus enables fusion for programs on certain monadic datatypes. This strand of work is thus the one most closely related to ours, since it also aims to improve the ef... |

16 |
Beauty in the beast: A functional semantics of the awkward squad
- Swierstra, Altenkirch
- 2007
(Show Context)
Citation Context ...ic definition of improve is similarly covering the earlier more specific one. In the next sections we will benefit from this genericity repeatedly. 4 A More Realistic Example Swierstra and Altenkirch =-=[11]-=- build a pure model of Haskell’s teletype IO, with the aim of enabling equational reasoning and automated testing. The monad they use for this corresponds to FREE F_IO for the following functor: data ... |

16 | Monadic augment and generalised short cut fusion
- Ghani, Johann, et al.
- 2005
(Show Context)
Citation Context ...ply to the models Swierstra and Altenkirch provide in [14] for computation on (distributed) arrays, and should reap the same benefits there. 5.2 Short Cut Fusion for Monadic Computations Ghani et al. =-=[15,16]-=- observe that the augment combinator known from work on short cut fusion [17,18] has a monadic interpretation, and thus enables fusion for programs on certain monadic datatypes. This strand of work is... |

14 |
Type-inference based deforestation of functional programs
- Chitil
- 2000
(Show Context)
Citation Context ...ny of the earlier examples in this paper. Maybe it is possible to bring it to bear on such examples by inventing a suitable worker/wrapper scheme in the spirit of that applied by Gill [17] and Chitil =-=[19]-=- to achieve asymptotic improvements via short cut fusion. If that can be achieved at all for monadic short cut fusion, which is somewhat doubtful due to complications involving polymorphic recursion a... |

9 | Two-level types and parameterized modules
- Sheard, Pasalic
- 2004
(Show Context)
Citation Context ...ke apparent why the runtime is now only of linear complexity. 3 The Generic Setting To deal with a variety of different datatypes in one stroke, we use the by now folklore approach of two-level types =-=[7,8]-=-. A functor is an instance of the following type constructor class: class FUNCTOR φ where fmap :: (α → β) → φ α → φ β satisfying the following two laws: fmap id t = t (8) fmap f (fmap g t) = fmap (f ◦... |

6 | Dependent types for distributed arrays
- Swierstra, Altenkirch
(Show Context)
Citation Context ...cases of Swierstra’s approach, such as his calculator example in Sect. 6. Up to compatibility with Agda’s dependent type system, it should also apply to the models Swierstra and Altenkirch provide in =-=[14]-=- for computation on (distributed) arrays, and should reap the same benefits there. 5.2 Short Cut Fusion for Monadic Computations Ghani et al. [15,16] observe that the augment combinator known from wor... |