Re: [Haskell-cafe] basic field questions

2007-01-25 Thread jamin1001
Well, it seems this approach doesn't allow you to group some fields together like colour and weight, but instead you need to relist them piecemeal for each new data constructor. Also, you get a run-time error (rather than compile-time) if you happen to reference a field that didn't happen to

Re: [Haskell-cafe] basic field questions

2007-01-25 Thread Neil Mitchell
Hi sq = squishiness $ Table {colour = Black, weight=1, height= 2} main = putStr $ show sq squishiness is just translated to: squishiness :: Furniture - Double squishiness (Chair _ _ x) = x squishiness _ = error doh main: No match in record selector Main.squishiness Hence this is a

[Haskell-cafe] basic field questions

2007-01-24 Thread jamin1001
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

Re: [Haskell-cafe] basic field questions

2007-01-24 Thread Alex Queiroz
Hallo, On 1/24/07, jamin1001 [EMAIL PROTECTED] wrote: 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} data Chair = Chair { chairPos :: Int, chairColor :: Int } Also, could

Re: [Haskell-cafe] basic field questions

2007-01-24 Thread Ketil Malde
jamin1001 wrote: What if I want to do something like data Chair = Chair {pos:: Int, color :: Int} data Table = Table {pos:: Int, color :: Int} data Properties = Props { pos, color :: Int } data Chair = Chair Props data Table = Table Props or: data Chair = Chair Int Int data Table =

Re: [Haskell-cafe] basic field questions

2007-01-24 Thread Alex Queiroz
Hallo, On 1/24/07, Ketil Malde [EMAIL PROTECTED] wrote: jamin1001 wrote: What if I want to do something like data Chair = Chair {pos:: Int, color :: Int} data Table = Table {pos:: Int, color :: Int} data Properties = Props { pos, color :: Int } data Chair = Chair Props data Table = Table

Re: [Haskell-cafe] basic field questions

2007-01-24 Thread Brian Hulley
jamin1001 wrote: Hi, I am new at Haskell and have some basic questions. 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} Unfortunately you have to think up different names for all

Re: [Haskell-cafe] basic field questions

2007-01-24 Thread Lennart Augustsson
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

Re: [Haskell-cafe] basic field questions

2007-01-24 Thread jamin1001
Thanks, that's much clearer now. Following this further, it seems that this could get monotonous/verbose if you have more than a handful of classes. I looked into deriving but it seems that is only useful for a set of builtin Haskell types (Eq, Ord, Show, etc.). Is Template Haskell the answer

Re: [Haskell-cafe] basic field questions

2007-01-24 Thread jamin1001
This is what I mean by machinery: -- CASE 1 data Furniture = Furniture { pos, color :: Int } data Chair = Chair Furniture data Table = Table Furniture data Wooden = Wooden { grain :: Int } data WoodenFurniture = WoodenFurniture Wooden Furniture data WoodenTable = WoodenTable Wooden Table