W preview
authorCharlie Gerhardus <charlie.gerhardus@somedomain.something>
Fri, 11 Sep 2015 21:00:52 +0000 (23:00 +0200)
committerCharlie Gerhardus <charlie.gerhardus@somedomain.something>
Fri, 11 Sep 2015 21:00:52 +0000 (23:00 +0200)
W/examples/StdEnv.wdef [new file with mode: 0755]
W/examples/sample.w [new file with mode: 0755]

diff --git a/W/examples/StdEnv.wdef b/W/examples/StdEnv.wdef
new file mode 100755 (executable)
index 0000000..8e1070d
--- /dev/null
@@ -0,0 +1,76 @@
+># StdEnv.wdef\r
+ #\r
+ # builtin operator definitions\r
+ #<\r
+\r
+prototype op prefix ~ a b : a -> b\r
+overload op prefix ~ N Z\r
+overload op prefix ~ Z Z\r
+overload op prefix ~ R R\r
+\r
+prototype op prefix ! a : a -> B\r
+\r
+prototype op infix AND a : a a -> a\r
+overload op infix AND N\r
+overload op infix AND Z\r
+\r
+prototype op infix OR a : a a -> a\r
+overload op infix OR N\r
+overload op infix OR Z\r
+\r
+prototype op infix XOR a : a a -> a\r
+overload op infix XOR N\r
+overload op infix XOR Z\r
+\r
+prototype op infix + a : a a -> a\r
+overload op infix + N\r
+overload op infix + Z\r
+overload op infix + R\r
+\r
+prototype op infix - a : a a -> a\r
+overload op infix - N\r
+overload op infix - Z\r
+overload op infix - R\r
+\r
+prototype op infix * a : a a -> a\r
+overload op infix * N\r
+overload op infix * Z\r
+overload op infix * R\r
+\r
+prototype op infix / a : a a -> a\r
+overload op infix / N\r
+overload op infix / Z\r
+overload op infix / R\r
+\r
+prototype op infix % a : a a -> a\r
+overload op infix % N\r
+overload op infix % Z\r
+\r
+prototype op infix > a : a a -> B\r
+overload op infix > N\r
+overload op infix > Z\r
+overload op infix > R\r
+\r
+prototype op infix < a : a a -> B\r
+overload op infix < N\r
+overload op infix < Z\r
+overload op infix < R\r
+\r
+prototype op infix == a : a a -> B\r
+overload op infix == B\r
+overload op infix == N\r
+overload op infix == Z\r
+overload op infix == R\r
+overload op infix == Char\r
+overload op infix == String\r
+\r
+prototype op infix != a : a a -> B\r
+overload op infix != B\r
+overload op infix != N\r
+overload op infix != Z\r
+overload op infix != R\r
+overload op infix != Char\r
+overload op infix != String\r
+\r
+op infix && : B B -> B\r
+op infix || : B B -> B\r
diff --git a/W/examples/sample.w b/W/examples/sample.w
new file mode 100755 (executable)
index 0000000..3e24184
--- /dev/null
@@ -0,0 +1,36 @@
+># sample.w
+ #
+ # sneek preview for the world!
+ #<
+
+import StdEnv
+
+typedef Tree a := Tip | Bin a (Tree a) (Tree a)
+
+# functions are invoked as 'insert(x, y)'
+func insert : a (Tree a) -> (Tree a)
+insert(x, Tip) = Bin x Tip Tip
+insert(x, Bin y l r) | x < y = Bin y insert(x, l) r
+                     | otherwise = Bin y l insert(x, r)
+
+# prefix operators work like normal functional functions
+op prefix contains : a (Tree a) -> B
+contains x Tip = False
+contains x (Bin y l r) | x == y = True
+                       | x < y = contains x l
+                                          | otherwise = contains x r
+
+op prefix len : [a] -> N
+len [] = 0
+len [_:xs] = 1 + (len xs)
+
+# currently no way to specify binding strenght
+op infix -- : N N -> B
+-- x y | x < y = True
+       | otherwise = False
+
+func max : N N -> N
+max(x, y) | x -- y = y
+          | y -- x = x
+                 | otherwise = y # equals
+