ATS Pointers and References

Run Settings
LanguageATS
Language Version
Run Command
#include "share/atspre_staload.hats" datatype point = | Point of (ref int) %{ int deref (int addr) { return *((int *)addr); } %} implement main0 () = () where { fun debug (x: point): void = () where { val _ = $extfcall (void, "printf", "Address of struct: %p\n", x) val Point i = x val _ = $extfcall (void, "printf", "Content of ref itself: %p\n", $UNSAFE.cast{int} i) val c = $extfcall (int, "deref", $UNSAFE.cast{int} i) val _ = $extfcall (void, "printf", "Content of ref cell: %d\n", c) } val x = Point (ref<int> 10) val _ = debug x fun change (p: point, i: int): void = () where { val Point c = p val _ = !c := i } val _ = change (x, 100) val _ = debug x }
Editor Settings
Theme
Key bindings
Full width
Lines