[Template-haskell] splicing types

Marc Weber marco-oweber at gmx.de
Tue Jul 1 11:24:11 EDT 2008


Hi Robert,

Funny to see that you have had quite much the same ideas as me.
I've been trying to find a way to encode some meta information
describing relations between database tables. My first idea was using
phantom types as well and I started coding and implement a lot of pattern matching ..
Suddenly I noticed that I don't have to encode / decode the whole stuff
when simply creating my own representation (see my other post. There is
an example)..

Do in your case it could look like this:

$(
        let myData = MyData [ MyCon { 
                                name = "Bar",
                                types = [ ("val1", 'String, DoSerialize), ("val1", 'String, NoSerialization) ] 
                        } ]
        in createSerializationAndDataTypes myData
)

Drawback: You need to learn this different syntax (That was one reason to introduce Quasi-quoting, correct?)
                It's not as easy to read as 
                        Omitted Type
Benefits: You only have to write an encoder to create the data type
        which should be easy. And you'll need some kind of representation
        anyway, do you? If you have this you can experiment with many more
        things such as extending haskell-src, DrIft to support real annotations (you
        can invent your very own syntax then ..) etc.

        Haskell doesn't have to box unbox the Omitted data type which
        maybe can be a speed penalty ? (Not sure about this)

        It could look like this then (maybe I'm abusing quasi-quoting here, I haven't used it yet)
[:defineDataAndSerialization |
        data Bar {
                val1 :: String,
                val2 :: Int (@ OmitDefault [|20|]) -- omit this in serialization
            }
]

Marc Weber


More information about the template-haskell mailing list