aboutsummaryrefslogtreecommitdiff
path: root/hypsrc-test/src/Records.hs
blob: 4118e2969897102ab6b05eac3f0ae7d44f9e1779 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{-# LANGUAGE NamedFieldPuns #-}

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 }