aboutsummaryrefslogtreecommitdiff
path: root/hypsrc-test/src/Records.hs
diff options
context:
space:
mode:
Diffstat (limited to 'hypsrc-test/src/Records.hs')
-rw-r--r--hypsrc-test/src/Records.hs34
1 files changed, 34 insertions, 0 deletions
diff --git a/hypsrc-test/src/Records.hs b/hypsrc-test/src/Records.hs
new file mode 100644
index 00000000..40a01121
--- /dev/null
+++ b/hypsrc-test/src/Records.hs
@@ -0,0 +1,34 @@
+{-# LANGUAGE NamedFieldPuns #-}
+{-# LANGUAGE RecordWildCards #-}
+
+
+module Records where
+
+
+data Point = Point
+ { x :: !Int
+ , y :: !Int
+ }
+
+
+point :: Int -> Int -> Point
+point x y = Point { x = x, y = y }
+
+
+lengthSqr :: Point -> Int
+lengthSqr (Point { x = x, y = y }) = x * x + y * y
+
+lengthSqr' :: Point -> Int
+lengthSqr' (Point { x, y }) = y * y + x * x
+
+
+translateX, translateY :: Point -> Int -> Point
+translateX p d = p { x = x p + d }
+translateY p d = p { y = y p + d }
+
+translate :: Int -> Int -> Point -> Point
+translate x y p =
+ aux p
+ where
+ (dx, dy) = (x, y)
+ aux Point{..} = p { x = x + dx, y = y + dy }