Top Level TWI's again was Re: [Haskell] Re: Parameterized Show

John Velman velman at cox.net
Mon Nov 22 18:34:03 EST 2004


On Mon, Nov 22, 2004 at 07:27:44PM +0100, Lennart Augustsson wrote:
> 
[snip]
> I admit there are proper uses of global variables, but they are very
> rare.  You have not convinced me you have one.
> 
> 	-- Lennart

It's with some trepidation I bring a problem as a total newbie, but I've
been obsessed with this and hung up on it ever since I decided a couple of
weeks ago to learn Haskell by using it.

Some brief background:

A while back I decided I wanted a simple 'concept mapping' program that
would work the way I work instead of the way someone else works.  I
envisioned a GUI with a canvas and an entry box (TK/tcl).  I type a
"concept name" into the entry box, and it shows up on the canvas (initially
in a slightly randomized position), in a box, with a unique sequenced
identifier.  The identifier is also used as a canvas tag for the item.
Similar input for relations between concepts.   I think that's enough
description for now.

Initially, I started programming this with PerlTK, but that effort was
interrupted for a few weeks.  When I got back to it, I decided to do it in
Python instead. But that effort also got interrupted for a few weeks.
Before I got back to it, I ran across some material on Haskell I've had in
my files for a few years, and decided that I'd use this as a vehicle to
actually learn Haskell.   (This all sounds a bit unfocused, and it is:  I'm
retired, sometimes describe myself as an ex mathematician or an ex-PhD
having spent years in the aerospace industry instead of academia.  Anyway,
I have both the luxury and lack of focus of no deadlines, no pressure to
publish.  I hope to use Haskell to further my main hobby of knowledge
representation.)

In perl, my labels/tags were very easy:

In the initialization code:

     my @taglist = ();
     my $nextag = "a";

and in the callback for the entry box:

    push(@taglist,$nextag);
    $nextag++;

(With the starting tag of "a"  this results in "a",...."z","aa","ab",...)

Also, ultimately, I want to be able to save  my work and restart
the next day (say) picking up the tags where I left off.

I'm darned if I can see how to do this in a callback without a global
variables (and references from other callbacks, by the way).

In looking for a method, I've discovered that Haskell is a lot richer than
I thought (or learned when I tinkered with it back in the late '90s ).
I've found out about (but don't know how to use properly) implicit
parameters, linear implicit parameters, unsafePerformIO, "safe and sound
implementation of polymorphic heap with references and updates (Oleg
Kiselyov, (http://www.haskell.org/pipermail/haskell/2003-June/011939.html),
implicit configurations, phantom types, ...

I've also found warnings against many of these.  I'm inclined to try the
unsafePerformIO route as being the simplest, and most commonly used, even
though perhaps the least haskell-ish.  I like implicit configurations, but
couldn't begin to say I understand them yet, and it's a bit heavy for a
novice.

In a nutshell:

   I want to use the old value of a tag to compute the new value, in a
   callback, 
   
   I want to access the tag from other callbacks, and
   
   I want to the value to a mutable list from within the callback.
   
I'd certainly be interested in doing without global variables, and would
appreciate any advice.

(By the way, I'm using Linux, and so far it looks like HTk is my choice for
the GUI interface.)

Best,

John Velman


More information about the Haskell mailing list