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
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
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
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
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 =
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
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
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
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
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
10 matches
Mail list logo