aboutsummaryrefslogtreecommitdiff
path: root/hypsrc-test/src/Constructors.hs
diff options
context:
space:
mode:
authoridontgetoutmuch <dominic@steinitz.org>2015-12-20 21:01:47 +0000
committeridontgetoutmuch <dominic@steinitz.org>2015-12-20 21:01:47 +0000
commit2bdfda1fb2e0de696ca8c6f7a152b2f85a541be9 (patch)
treecc29895f7d69f051cfec172bb0f8c2ef03552789 /hypsrc-test/src/Constructors.hs
parent5a57a24c44e06e964c4ea2276c842c722c4e93d9 (diff)
parentfa03f80d76f1511a811a0209ea7a6a8b6c58704f (diff)
Merge pull request #1 from haskell/ghc-head
Ghc head
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