Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- NestedInstantiationsBasedOnPreviousRecords.hs
- -- Inspired by: http://langexplr.blogspot.com/2012/01/quick-look-at-haskell-records.html
- data Vector2D = Vector2D {
- x :: Double,
- y :: Double
- } deriving Show
- data Animated = Animated {
- position :: Vector2D,
- movement :: Vector2D
- } deriving Show
- animated0 = Animated {
- position = Vector2D { x = 10, y = 5 },
- movement = Vector2D { x = 1, y = (-1) }
- }
- animated1 = animated0 {
- position = (position animated0) { x = (y . position $ animated0) }
- }
- main = print animated0 >> print animated1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement