git @ Cat's Eye Technologies Dipple / master haskell / record.hs
master

Tree @master (Download .tar.gz)

record.hs @masterraw · history · blame

-- SPDX-FileCopyrightText: Chris Pressey, the original author of this work, has dedicated it to the public domain.
-- For more information, please refer to <https://unlicense.org/>
-- SPDX-License-Identifier: Unlicense

data Product = Product {
        desc :: String,
        sku :: String,
        qty :: Int,
        weight :: Float
    } deriving (Show)


doubleQty p@Product{ qty=x } = p { qty=x * 2 }

demo =
   let
       p = Product{ desc="White paint", sku="PW00", qty=1, weight=14.4 }
       p' = p { qty=100 }
       q = weight p'
   in
       show (p', q)