reorganized examples directory
[coq-hetmet.git] / examples / ImmutableHeap.hs
diff --git a/examples/ImmutableHeap.hs b/examples/ImmutableHeap.hs
new file mode 100644 (file)
index 0000000..56ff12c
--- /dev/null
@@ -0,0 +1,23 @@
+{-# OPTIONS_GHC -XModalTypes -XScopedTypeVariables -ddump-types -XNoMonoPatBinds #-}
+module ImmutableHeap
+where
+import IsomorphismForCodeTypes
+import Prelude hiding ( id, (.) )
+
+
+class GuestLanguageHeap c where
+  alloc  :: <[ (Integer,Integer) ->  Integer      ]>@c
+  lookup :: <[ Integer       -> (Integer,Integer) ]>@c
+
+--
+-- Here's nice example of Sheard's observation that it's often easier
+-- to write two-stage programs by applying "back" to some function rather than
+-- writing the final result directly
+--
+onetwocycle = back onetwocycle'
+ where
+  onetwocycle' xy = <[ let (x,y) = ~~xy 
+                       in let x' = ~~alloc (1,x)
+                       in let y' = ~~alloc (2,y)
+                       in (x',y')
+                     ]>