Functional option and safer operations

Provided a separate library (memory-operations-functional.xqy) for use with with the core that does things in a more functional way. ML 7+

Add in more checks and back off on some of the strong typing, leaving less for the user of the library to check for.