[Haskell-cafe] How to build a generic spreadsheet?

Sebastian Sylvan sebastian.sylvan at gmail.com
Fri Feb 23 18:01:46 EST 2007


On 2/23/07, Sebastian Sylvan <sebastian.sylvan at gmail.com> wrote:
> On 2/23/07, Sebastian Sylvan <sebastian.sylvan at gmail.com> wrote:
> > On 2/23/07, Greg Fitzgerald <garious at gmail.com> wrote:
> > > I want to write a program where a user would update a bunch of variables,
> > > and everything that depends on those variables (and nothing else) are
> > > recalculated.  Basically, a spreadsheet, but generalized for any
> > > computation.  Could someone recommend an elegant way to do it or some good
> > > reading material?
> >
> > Off the top of my head, one cool way of doing it would be to have each
> > variable be a separate thread (they're lightweight, so it's okay!
> > :-)), and you would have a list of input connections and output
> > connections, in the form of TVars.
> >
> > In its resting state you would have a transaction which simply reads
> > all of the input variables, and returns the new list of inputs if and
> > only if either of them are changed, something like:
> >
> > -- not compiled, consider it pseudocode :-)
> > getInputs :: (Eq a ) => [( a, TVar a)] -> STM [a]
> > getInputs inp = do
> >   let (vals, vars) = unzip inp
> >   newVals <- mapM readTVar vars
> >   when ( newVals /= vals ) retry -- at least one input must've been changed
>
> Bah, this should be:
>
> when ( newVals == vals ) retry
>
> Of course...
>

*sigh* and you should return "newVals" not "vals"..  It's too late :-)


-- 
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862


More information about the Haskell-Cafe mailing list