DDC/FieldProjections
Jump to navigation
Jump to search
Data Fields
When data types are defined using field names, we can use the projection operator (.)
to select the fields.
data Vector
= Vector { x :: Float; y :: Float; }
instance Out Vector where
out vec = println $ parens (show x % "," % show y)
main ()
= do vec = Vector 3.0 4.0
out vec -- prints '(3.0, 4.0)'
out vec.x -- prints '3.0'
out vec.y -- prints '4.0'