[Haskell-cafe] "record" types and unique names
Aaron Gray
aaronngray.lists at gmail.com
Thu Dec 30 18:26:25 CET 2010
On 30 December 2010 17:23, Markus Läll <markus.l2ll at gmail.com> wrote:
> 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 <aaronngray.lists at gmail.com>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 at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20101230/2ef596f2/attachment.htm>
More information about the Haskell-Cafe
mailing list