"record" types and unique names

Given a Haskell "record type" :- data Test = Test { name :: String, value :: Int } test = Test { name = "test", value = 1 } main :: IO () main = do putStrLn (name test) Are "name" and "value" in the global name space, as the following gives an error "Multiple declarations of `name'" :- name :: String -> String name s = s Is there any way round this ? Many thanks in advance, Aaron

Take a look at the record field disambiguation [1] extension to GHC.
It sounds like what you're looking for.
-deech
[1] http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/syntax-extns.html#di...
On Thu, Dec 30, 2010 at 11:01 AM, Aaron Gray
Given a Haskell "record type" :- data Test = Test { name :: String, value :: Int } test = Test { name = "test", value = 1 } main :: IO () main = do putStrLn (name test) Are "name" and "value" in the global name space, as the following gives an error "Multiple declarations of `name'" :- name :: String -> String name s = s Is there any way round this ? Many thanks in advance, Aaron
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

I don't think record field disambiguation what you're after. My apologies.
-deech
On Thu, Dec 30, 2010 at 11:20 AM, aditya siram
Take a look at the record field disambiguation [1] extension to GHC. It sounds like what you're looking for. -deech [1] http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/syntax-extns.html#di...
On Thu, Dec 30, 2010 at 11:01 AM, Aaron Gray
wrote: Given a Haskell "record type" :- data Test = Test { name :: String, value :: Int } test = Test { name = "test", value = 1 } main :: IO () main = do putStrLn (name test) Are "name" and "value" in the global name space, as the following gives an error "Multiple declarations of `name'" :- name :: String -> String name s = s Is there any way round this ? Many thanks in advance, Aaron
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 30 December 2010 17:29, aditya siram
I don't think record field disambiguation what you're after. My apologies. -deech
Interesting never the less. Thanks, Aaron
On Thu, Dec 30, 2010 at 11:20 AM, aditya siram
wrote: Take a look at the record field disambiguation [1] extension to GHC. It sounds like what you're looking for. -deech [1] http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/syntax-extns.html#di...
On Thu, Dec 30, 2010 at 11:01 AM, Aaron Gray
wrote: Given a Haskell "record type" :- data Test = Test { name :: String, value :: Int } test = Test { name = "test", value = 1 } main :: IO () main = do putStrLn (name test) Are "name" and "value" in the global name space, as the following gives an error "Multiple declarations of `name'" :- name :: String -> String name s = s Is there any way round this ? Many thanks in advance, Aaron
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Yes, they are in the global scope, and from what I gather: they are just
regular functions, created by special syntax.
There are a few obvious solutions (some of which you might have thought
yourself :-):
- rename the accessor or the other function, or
- put the data declaration or the other function in another module and
import qualified, or
- write a typeclass with a 'name' function and fit the non-accessor
function 'name' somehow into that...
I think the best approach is the modular one, but this really depends on
what you are doing.
--
Markus Läll
On Thu, Dec 30, 2010 at 7:01 PM, Aaron Gray
Given a Haskell "record type" :-
data Test = Test { name :: String, value :: Int }
test = Test { name = "test", value = 1 }
main :: IO () main = do putStrLn (name test)
Are "name" and "value" in the global name space, as the following gives an error "Multiple declarations of `name'" :-
name :: String -> String name s = s
Is there any way round this ?
Many thanks in advance,
Aaron
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 30 December 2010 17:23, Markus Läll
Yes, they are in the global scope, and from what I gather: they are just regular functions, created by special syntax.
There are a few obvious solutions (some of which you might have thought yourself :-): - rename the accessor or the other function, or - put the data declaration or the other function in another module and import qualified, or - write a typeclass with a 'name' function and fit the non-accessor function 'name' somehow into that...
I think the best approach is the modular one, but this really depends on what you are doing.
Okay looks like name mangling with the datatypes name is in order then. Something like :- data Test = Test { testName :: String, testValue :: Int } Thanks, Aaron --
Markus Läll
On Thu, Dec 30, 2010 at 7:01 PM, Aaron Gray
wrote: Given a Haskell "record type" :-
data Test = Test { name :: String, value :: Int }
test = Test { name = "test", value = 1 }
main :: IO () main = do putStrLn (name test)
Are "name" and "value" in the global name space, as the following gives an error "Multiple declarations of `name'" :-
name :: String -> String name s = s
Is there any way round this ?
Many thanks in advance,
Aaron
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Aaron Gray
-
aditya siram
-
Markus Läll