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
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
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
-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
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
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 |
: 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
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