aboutsummaryrefslogtreecommitdiff
path: root/hypsrc-test/src/Constructors.hs
diff options
context:
space:
mode:
Diffstat (limited to 'hypsrc-test/src/Constructors.hs')
-rw-r--r--hypsrc-test/src/Constructors.hs35
1 files changed, 35 insertions, 0 deletions
diff --git a/hypsrc-test/src/Constructors.hs b/hypsrc-test/src/Constructors.hs
new file mode 100644
index 00000000..8cb46535
--- /dev/null
+++ b/hypsrc-test/src/Constructors.hs
@@ -0,0 +1,35 @@
+module Constructors where
+
+
+data Foo
+ = Bar
+ | Baz
+ | Quux Foo Int
+
+newtype Norf = Norf (Foo, [Foo], Foo)
+
+
+bar, baz, quux :: Foo
+bar = Bar
+baz = Baz
+quux = Quux quux 0
+
+
+unfoo :: Foo -> Int
+unfoo Bar = 0
+unfoo Baz = 0
+unfoo (Quux foo n) = 42 * n + unfoo foo
+
+
+unnorf :: Norf -> [Foo]
+unnorf (Norf (Bar, xs, Bar)) = xs
+unnorf (Norf (Baz, xs, Baz)) = reverse xs
+unnorf _ = undefined
+
+
+unnorf' :: Norf -> Int
+unnorf' x@(Norf (f1@(Quux _ n), _, f2@(Quux f3 _))) =
+ x' + n * unfoo f1 + aux f3
+ where
+ aux fx = unfoo f2 * unfoo fx * unfoo f3
+ x' = sum . map unfoo . unnorf $ x