[Haskell-cafe] basic field questions

Lennart Augustsson lennart at augustsson.net
Wed Jan 24 08:30:34 EST 2007


There is no good solution to your problem.  But one way to have
both the type A and the type B as you define them is to put them
in separate modules and then use qualified names for the `test'
function.

	-- Lennart

On Jan 24, 2007, at 06:12 , jamin1001 wrote:

>
> Hi, I am new at Haskell and have some basic questions.
>
> Is there any way to do this more effectively? This causes the GHC
> compile error "Multiple declarations of Main.test":
>
> data A = A {test :: Int}
> data B = B {test :: Int}
>
>
> The Haskell 98 report in 4.2.1 under Labelled Fields says
> "A label cannot be shared by more than one type in scope. Field names
> share the top level namespace with ordinary variables and class  
> methods
> and must not conflict with other top level names in scope."
>
>
> So then how should this be done?  What if I want to do something like
>
> data Chair = Chair {pos:: Int, color :: Int}
> data Table = Table {pos:: Int, color :: Int}
>
>
> Also, could someone tell me why this doesn't compile in GHC:
>
> data Test = A {a::Int} | B {a::Int, b::Int}
> data Test2 = C {c::A}
>
> (Test2 line): Not in scope: type constructor or class 'A'
>
>
> Is there a way to qualify identical field names?  What are some  
> standard
> practices for dealing with this?
>
>
>
> Thanks,
>
> Jamin Ohmoto-Frederick
> -- 
> View this message in context: http://www.nabble.com/basic-field- 
> questions-tf3080392.html#a8558522
> Sent from the Haskell - Haskell-Cafe mailing list archive at  
> Nabble.com.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list