[Haskell-beginners] Struct-like syntax issues
Rahul Kapoor
rk at trie.org
Sun Mar 14 10:58:30 EDT 2010
Using the record update syntax might make it a little nicer,
also the record syntax already provides getters and setters.
data MyData = MyData {
a :: Int,
b :: Int,
c :: Int
} deriving (Show)
def = MyData 1 2 3
-- or
-- def = MyData {a = 1, b = 2, c = 3}
makeMyData :: Int -> Int -> MyData
makeMyData a' b' = def { a = a', b = b'}
myData1 = (makeMyData 9 10) {a = 1}
myData2 = (makeMyData 11 12) {c = 12}
With syntax highlighting: http://haskell.pastebin.com/LxtLZCtL
HTH,
Rahul
More information about the Beginners
mailing list