[Haskell-cafe] "record" types and unique names

Markus Läll markus.l2ll at gmail.com
Thu Dec 30 18:23:15 CET 2010


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 <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/5f7a99b3/attachment.htm>


More information about the Haskell-Cafe mailing list