[Haskell-beginners] Struct-like syntax issues
Sergey Mironov
ierton at gmail.com
Sun Mar 14 12:07:31 EDT 2010
2010/3/14 Rahul Kapoor <rk at trie.org>:
> 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
>
Thanks to all!
>
> myData3 = (makeMyData my_a my_b) {x=x', z=z'} approach is not working..
I checked again - it works actually!
--
Thanks,
Sergey
More information about the Beginners
mailing list