Difference between revisions of "Lucid"

From HaskellWiki
Jump to navigation Jump to search
m (grammatic correction (German word order corrected) and some words on the Lucid code example)
(A table explaining the concept of ``running average'' by an example)
Line 26: Line 26:
 
card = 1 '''`fby`''' succ card
 
card = 1 '''`fby`''' succ card
 
</code>
 
</code>
This programm counts the ''moving average'' of the input stream.
+
This program counts the ''moving average'' of the input stream:
  +
<center>
  +
{| border=1 cellspacing=0 cellpadding=5
  +
| '''Snapshot'''
  +
| '''Input'''
  +
| '''Ouput'''
  +
|-
  +
| 0
  +
| <code>&nbsp;</code>
  +
| <code> </code>
  +
|-
  +
| 1
  +
| <code>1.0</code>
  +
| <code>1.0</code>
  +
|-
  +
| 2
  +
| <code>1.0</code>, <code>2.0</code>
  +
| <code>1.0</code>, <code>1.5</code>
  +
|-
  +
| 3
  +
| <code>1.0</code>, <code>2.0</code>, <code>3.0</code>, <code>4.0</code>
  +
| <code>1.0</code>, <code>1.5</code>, <code>2.0</code>, <code>2.5</code>
  +
|-
  +
| 4
  +
| <code>1.0</code>, <code>2.0</code>, <code>3.0</code>, <code>4.0</code>, <code>5.0</code>
  +
| <code>1.0</code>, <code>1.5</code>, <code>2.0</code>, <code>2.5</code>, <code>5.0</code>
  +
|}
  +
</center>
 
In fact, <code>first</code>, <code>next</code>, <code>fby</code> are not necessarily primitives in Lucid, but this fast-food implementation treats them as primitives.
 
In fact, <code>first</code>, <code>next</code>, <code>fby</code> are not necessarily primitives in Lucid, but this fast-food implementation treats them as primitives.
   

Revision as of 21:15, 11 June 2006

Introduction

Weblogs Forum: Fluid Programming in Lucid -- good examples, and very good links.

Lucid page written by Bill Wadge, including an excerpt from Lucid Primer book.

Wikipedia article (yet a stub, but useful links).

Details

The most detailed online material on the details of this language I could find: Raganswamy Jagannathan, Chris Dodd. GLU programmer's guide (downloadable as the 4th paper of GIPSY Publications). The first pages seem to discuss other problems, but it is worth of reading further, because a detailed description of Lucid's syntax and semantics is hiding inside this paper (section 3.1.2 on pages 22--38). This paper is part of the Gipsy Project Home Page (GIPSY: A General Intensional Programming System).

Implementation

Fast-food

A fast-food implementation:

written to mimick and test the following Lucid example (I have made it a little Haskell-like):

average n = sum n / card
sum n = first n `fby` (sum n + next n)
card = 1 `fby` succ card

This program counts the moving average of the input stream:

Snapshot Input Ouput
0  
1 1.0 1.0
2 1.0, 2.0 1.0, 1.5
3 1.0, 2.0, 3.0, 4.0 1.0, 1.5, 2.0, 2.5
4 1.0, 2.0, 3.0, 4.0, 5.0 1.0, 1.5, 2.0, 2.5, 5.0

In fact, first, next, fby are not necessarily primitives in Lucid, but this fast-food implementation treats them as primitives.

Arrow

A better implementation could be written using the arrow library available at the Downloads page of Arrows: A General Interface to Computation written by Antony Courtney, Henrik Nilsson and Ross Paterson.

Comonad

A professional approach based on comonads: see The Essence of Dataflow Programming paper written by Tarmo Uustalu. Comments on this paper can be found on Lambda the Ultimate (but the link to the mentioned given there seems to be broken, I have given an updated one here). The links to pages introducing the concept of comonad are Comonads and Haskell written by Einar Karttunen.