[mercury-users] Destructive list operations

Michael Day mikeday at yeslogic.com
Tue Jan 6 10:33:37 AEDT 2009

Hi Mark,

> It is indeed possible to do this in Mercury using the store module.  Below
> are two functions that destructively update the head/tail of a non-empty
> list, re-using the cons cell of the original.  These could be used to
> implement destructively updating versions of list.append and list.map,
> among other things.

That's clever, but is it an improvement on the equivalent C procs?

The use of unsafe_promise_unique detracts somewhat from the elegance of 
keeping all the code in Mercury.

> Note that this still has the problem with static data that you mentioned
> earlier.

Right. Seems like update_head and update_tail could be written in C just 
as clearly, if not more so, and then used in Mercury predicates.

Ultimately though making anything but the IO state unique opens up all 
the unsolved issues with nested unique modes, and simple things suddenly 
become difficult things. Perhaps time to consider uniqueness types, as 
in Clean, instead? Given that the mode system is the core innovation of 
Mercury it gets surprisingly little use :)



Print XML with Prince!
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au

More information about the users mailing list