[Haskell-cafe] basic field questions

jamin1001 jamin1001 at yahoo.com
Wed Jan 24 09:09:00 EST 2007


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 to automating some of this machinery?


-Jamin



Ketil Malde-2 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 Props
> 
> or:
> 
> data Chair = Chair Int Int
> data Table = Table Int Int
> 
> class Furniture a where
>    pos :: a -> Int
>    color :: a -> Int
> 
> instance Furniture Chair where
>    pos (Chair x _) = x
>    color (Chair _ c) = c
> 
> instance Furniture Table where ...
>>
>> 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'
>>   
> A is a data constructor, and not a type.  Try:
> 
>    data Test2 = C { c :: Test }
>> Is there a way to qualify identical field names?  What are some standard
>> practices for dealing with this?
>>   
> The record system is somewhat wartish, and there have been
> several proposals to remedy it.  I'm not sure if any consensus
> has emerged yet.
> 
> -k
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 

-- 
View this message in context: http://www.nabble.com/basic-field-questions-tf3080392.html#a8561038
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list