]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/scl/Lens.scl
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Lens.scl
diff --git a/bundles/org.simantics.scl.runtime/scl/Lens.scl b/bundles/org.simantics.scl.runtime/scl/Lens.scl
new file mode 100644 (file)
index 0000000..0be176f
--- /dev/null
@@ -0,0 +1,21 @@
+/// Lens ///
+
+"""
+Laws:
+  set l (get l a) a) = a
+  get l (set l b a) = b
+  set l c (set l b a) = set l c a
+"""
+data Lens a b = Lens (a -> b) (b -> a -> a)
+
+get :: Lens a b -> a -> b
+get (Lens f _) = f
+
+set :: Lens a b -> b -> a -> a
+set (Lens _ g) = g
+
+/*instance Category Lens where
+    id = Lens id const
+    f . g = Lens (get f . get g)
+                 (\x y -> set g (set f x (get g y)) y)
+*/