[Haskell-cafe] relational data representation in memory using haskell?

Salvatore Insalaco kirby81 at gmail.com
Thu May 22 05:01:01 EDT 2008

> Consider
> let x = Cd ...
> forkIO $ ( do something with x } -- (1)
> print x -- (2)
> How can ghc know when running line (2) that (1) hasen't changed the
> record? I see two solutions:
> a) give the forked process a copy (Then my design will collapse)
>   but this is expensive to copy data without knowing you ned to
> b) use pointers and replace x ony on updating. Thus if (1) changes the
>   title a new struct wil be created poiting to the old list but a new
>   title String. line (2) doesn't have to care at all.

GHC knows that because in Haskell isn't possible to "update" x. x is
not a variable, it's a binding.
To put it simply: with IORefs (and STRefs, MVars, ...) you have
references to values that you can change (inside their respective
monads), much like variables, but data declarations are values, not
references to values (even if GHC stores them as pointers you cannot
treat them as such), so you cannot update it.

So, in your example, you have more or less a relation (CD) where all
the "columns" are part of primary key (and so they are not mutable).


More information about the Haskell-Cafe mailing list