Advertisement
jckuri

NestedInstantiationsBasedOnPreviousRecords.hs

May 21st, 2014
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- NestedInstantiationsBasedOnPreviousRecords.hs
  2. -- Inspired by: http://langexplr.blogspot.com/2012/01/quick-look-at-haskell-records.html
  3.  
  4. data Vector2D = Vector2D {
  5.  x :: Double,
  6.  y :: Double
  7. } deriving Show
  8.  
  9. data Animated = Animated {
  10.  position :: Vector2D,
  11.  movement :: Vector2D
  12. } deriving Show
  13.  
  14. animated0 = Animated {
  15.  position = Vector2D { x = 10, y = 5 },
  16.  movement = Vector2D { x = 1, y = (-1) }
  17. }
  18.  
  19. animated1 = animated0 {
  20.  position = (position animated0) { x = (y . position $ animated0) }
  21. }
  22.  
  23. main = print animated0 >> print animated1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement