data label overloading
Dear Haskellers, It is desirable to have shorter names for the data labels. Making a module out of a labeled data declaration does not look convenient. Providing the corresponding class operation is not always convenient. Maybe, future Haskell language could apprehend some special construct, like, say, in the following example data Foo1 = Foo1 {size :: Int ...} ... data Foo2 = Foo2 {size :: Int ...} ... f x y z = let size = Foo1..size in (size x) + (size y) + (Foo2..size z) ? "Foo.." is added when more than one type with the given label is visible in the scope. Copy, please, the answer to mechvel@botik.ru With kind regards, ----------------- Serge Mechveliani mechvel@botik.ru
data Foo1 = Foo1 {size :: Int ...} ... data Foo2 = Foo2 {size :: Int ...} ... f x y z = let size = Foo1..size in (size x) + (size y) + (Foo2..size z)
How does this save you typing over: data Foo1 = Foo1 { foo1_size :: Int } data Foo2 = Foo2 { foo2_size :: Int } f x y z = let size = foo1_size in (size x) + (size y) + (Foo2..size z) also, this would lead to highly ambiguous parses, i think. - hal -- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume
To my recent suggestion on the field label overloading
... data Foo1 = Foo1 {size :: Int ...} data Foo2 = Foo2 {size :: Int ...} ... f x y z = let size = Foo1..size in (size x)+(size y)+(Foo2..size z)
Hal Daume III wrote on Jan 13, 2004
How does this save you typing over:
data Foo1 = Foo1 { foo1_size :: Int } data Foo2 = Foo2 { foo2_size :: Int }
f x y z = let size = foo1_size in (size x) + (size y) + (Foo2..size z)
also, this would lead to highly ambiguous parses, i think.
Here is an example with improved suggestion: data Foo1 = Foo1 {size :: Int, ...} data Foo2 = Foo2 {size :: Int, ...} data Foo3 a b = Foo3 {size :: a, ...} f :: Foo1 -> Foo1 -> Foo2 -> Int f x y z = let n = (size x)+(size y)+(size z) in (g (x {size = n})) + 1 h v = v {size = 0} :: Foo3 _ _ g u = size (u :: Foo3 _ _) Very often the type or argument is clear. In such a case the compiler solves the label version. And in a dubious case the programmer adds the type denotation. Will this do? Copy, please, the answer to mechvel@botik.ru With kind regards, ----------------- Serge Mechveliani mechvel@botik.ru
participants (2)
-
Hal Daume III -
Serge D. Mechveliani