From fa830ef310d7a14601851ec34a67f65fc6efbc1d Mon Sep 17 00:00:00 2001 From: Charlie Gerhardus Date: Fri, 11 Sep 2015 23:00:52 +0200 Subject: [PATCH] W preview --- W/examples/StdEnv.wdef | 76 ++++++++++++++++++++++++++++++++++++++++++ W/examples/sample.w | 36 ++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100755 W/examples/StdEnv.wdef create mode 100755 W/examples/sample.w diff --git a/W/examples/StdEnv.wdef b/W/examples/StdEnv.wdef new file mode 100755 index 0000000..8e1070d --- /dev/null +++ b/W/examples/StdEnv.wdef @@ -0,0 +1,76 @@ +># StdEnv.wdef + # + # builtin operator definitions + #< + +prototype op prefix ~ a b : a -> b +overload op prefix ~ N Z +overload op prefix ~ Z Z +overload op prefix ~ R R + +prototype op prefix ! a : a -> B + +prototype op infix AND a : a a -> a +overload op infix AND N +overload op infix AND Z + +prototype op infix OR a : a a -> a +overload op infix OR N +overload op infix OR Z + +prototype op infix XOR a : a a -> a +overload op infix XOR N +overload op infix XOR Z + +prototype op infix + a : a a -> a +overload op infix + N +overload op infix + Z +overload op infix + R + +prototype op infix - a : a a -> a +overload op infix - N +overload op infix - Z +overload op infix - R + +prototype op infix * a : a a -> a +overload op infix * N +overload op infix * Z +overload op infix * R + +prototype op infix / a : a a -> a +overload op infix / N +overload op infix / Z +overload op infix / R + +prototype op infix % a : a a -> a +overload op infix % N +overload op infix % Z + +prototype op infix > a : a a -> B +overload op infix > N +overload op infix > Z +overload op infix > R + +prototype op infix < a : a a -> B +overload op infix < N +overload op infix < Z +overload op infix < R + +prototype op infix == a : a a -> B +overload op infix == B +overload op infix == N +overload op infix == Z +overload op infix == R +overload op infix == Char +overload op infix == String + +prototype op infix != a : a a -> B +overload op infix != B +overload op infix != N +overload op infix != Z +overload op infix != R +overload op infix != Char +overload op infix != String + +op infix && : B B -> B +op infix || : B B -> B diff --git a/W/examples/sample.w b/W/examples/sample.w new file mode 100755 index 0000000..3e24184 --- /dev/null +++ b/W/examples/sample.w @@ -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 + -- 2.20.1