[Haskell-cafe] Mutable arrays

Chaddaï Fouché chaddai.fouche at gmail.com
Wed Feb 6 14:56:00 EST 2008

2008/2/6, Jeff φ <jeff1.61803 at gmail.com>:
> I have solved both of these problems in Clean using a lazy list without
> resorting to unsafe operations.  So, it seems to me that uniqueness types
> are more general than monads.

 Are you aware that your code in Clean has some issues, like the lst
not being so lazy if you operate on ary2 before you operate on lst (it
is completely put in memory in this case) ? You've effectively created
a big uncertainty on the space taken by your function. Is this ok with
you ? The monadic fold (like I and some others proposed) guarantee you
a constant amount of memory consumed and is perfectly safe too, is the
Clean solution really so much better ?

Jonathan Cast :
> I'm confused --- does uToList_2D return the head of the list before or after it finishes reading
> the array?  If before, then I don't see how the type system prevents me from modifying the
> array before I finish examining the list, as you claim.  If after, then the list isn't truly lazy.

What happens here is that the array can't be modified without
evaluating ary2 and ary2 can't be evaluated without completely
evaluating the list before, so you effectively get the list lazily as
long as you don't touch ary2 before touching the list, and you can't
damage the list by modifying the array (because in this case, lst
would be completely evaluated in the first place). You can do the same
in Haskell in fact, but you'll need to discipline yourself to evaluate
the "witness" before modifying the array.

So uniqueness here seems to have an advantage over monads, still, the
monads look much cleaner (sic) than Clean code with all those unique
value passing around...


More information about the Haskell-Cafe mailing list