Proposition: accessory functions which are local to type.

What I don't like about current accessory functions is that they pollute namespace. data Coordinate2D = Coordinate2D { x :: Double, y :: Double} will make x and y not available for other types: data Coordinate3D = Coordinate3D { x :: Double, y :: Double, z :: Double} What I am proposing is something like this: data Coordinate = Coordinate where { x :: Double, y :: Double} By using "where" (or other keyword) we mark those accesor functions as local to type. This means, that function can only be used in a context of a type, like this: coord <- getRandomCoordinate For modifying (same as current): let newCoord = coord {x = 3, y = 4} For accessing part of a type: let x = coord.x Current form "x coord" will generate error, as there is no standalone function "x". "x" can only be accessed in context of any function application that returns needed type. Meaning, it is valid to write something like this: let plus (Coordinate2D x1 y1) (Coordinate2D x2 y2) = Coordinate2D (x1+x2) (y1+y2) x = (plus coord coord).x Yes, that means that function composition will need to use another symbol, but I think it is a great trade-off, as it will reduce namespace pollution and will make use of notation familiar to mainstram programmers (Java, C#, C, C++, etc). _________________________________________________________________ Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmail®. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/soc...

Hello Evgenij, the TDNR proposal seems related to yours: http://hackage.haskell.org/trac/haskell-prime/wiki/TypeDirectedNameResolutio... It would be useful to highlight and motivate the differences to help others judge your proposal. Cheers, Sebastian -- Underestimating the novelty of the future is a time-honored tradition. (D.G.)

Hello Evgenij,
the TDNR proposal seems related to yours:
It looks my proposal is almost a duplicate of TNDR. If I understand correctly, TNDR still uses a global function scope with some sort of Ad-Hoc, while I suggested that you can create a function which scope is local to a specified type, meaning - function is in scope only if "someLeftHandExpressionReturnsNeededType.access" The name "access" is completely free for a global scope decalaration and it is localy defined in cassess if there is a correct type on left side. prime/wiki/TypeDirectedNameResolut
ion
It would be useful to highlight and motivate the differences to help others judge your proposal.
Cheers, Sebastian
participants (3)
-
Evgenij
-
Evgenij Merenkov
-
Sebastian Fischer