AW: container for different types, avoiding boiler plate

2003-08-22 Thread Markus . Schnell
As you can see, functions ggender and gnumber are so trivial that hardly need to be declared at all. You can just use fetch directly. There is no need for Maybe. In fact, if you attempt to fetch a type that you didn't put into the attrs, you get a _compile-time_ error. Before I use your

AW: container for different types, avoiding boiler plate

2003-08-22 Thread oleg
There is no need for Maybe. In fact, if you attempt to fetch a type that you didn't put into the attrs, you get a _compile-time_ error. But I'm not sure if it's suitable for what I'm doing, as the attributes get inserted at run time, and not all of them appear everywhere. So Maybe is

Re: container for different types, avoiding boiler plate

2003-08-21 Thread Markus . Schnell
After taking a look at Data.Dynamic I came up with: data Gender = Masc | Fem | Neutr deriving (Typeable, Show) data Number = First | Second | Third deriving (Typeable, Show) type Attrs = [Dynamic] attrs = [toDyn Masc, toDyn Second] gattr :: (Typeable a) = Attrs - Maybe a

RE: container for different types, avoiding boiler plate

2003-08-21 Thread Hal Daume
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, August 21, 2003 1:58 AM To: [EMAIL PROTECTED] Cc: Hal Daume; [EMAIL PROTECTED] Subject: Re: container for different types, avoiding boiler plate After taking a look at Data.Dynamic I came up

Re: container for different types, avoiding boiler plate

2003-08-21 Thread oleg
You might also wish to look at the typed heaps, which have been discussed here on many occasions. Given the constant piece of code in the appendix (which does *not* depend on user types and can be put into a separate, constant module) you can write data Gender = Masc | Fem | Neutr deriving

container for different types, avoiding boiler plate

2003-08-20 Thread Markus . Schnell
I think similar things have been asked before, but I couldn't find anything specific. I have a data type with attributes. These attributes have different types. Right now I'm using a lot of boilerplate like that: data Gender = Masc | Fem | Neutr ... data Attr= Gender Gender | Cat Cat |

RE: container for different types, avoiding boiler plate

2003-08-20 Thread Hal Daume
: Wednesday, August 20, 2003 5:01 AM To: [EMAIL PROTECTED] Subject: container for different types, avoiding boiler plate I think similar things have been asked before, but I couldn't find anything specific. I have a data type with attributes. These attributes have different types. Right now

Re: container for different types, avoiding boiler plate

2003-08-20 Thread Derek Elkins
On Wed, 20 Aug 2003 08:25:39 -0700 Hal Daume [EMAIL PROTECTED] wrote: I use my 'DynamicMap' type to handle this sort of thing. However, I don't really recommend this approach unless you're very careful. You basically lose out on all nice type checking properties and enter a world of dynamic