[Haskell-cafe] DSL for data definition (e.g. compiling Haskell type defs into Google's protocol buffers type defs)

Ryan Newton rrnewton at gmail.com
Tue Oct 4 18:15:55 CEST 2011


An interesting and semi-related project was just presented at ICFP by
Kathleen Fisher.  It's called "Forest" and uses template haskell to create
schema's for "FileStores" from Haskell definitions.  But they're not
plain-old-haskell type definitions...

  -Ryan


On Tue, Oct 4, 2011 at 12:11 PM, Edward Z. Yang <ezyang at mit.edu> wrote:

> Just making sure: have you looked at the Data.Data module yet?
>
> Edward
>
> Excerpts from Karel Gardas's message of Tue Oct 04 12:02:34 -0400 2011:
> >
> > Hello,
> >
> > I'm trying to find out if it's possible to use Haskell data type
> > definition capability to define types and compile defined types into
> > other languages, for example into Google's protocol buffers data
> > definition language. So basically speaking I'm thinking about using
> > Haskell sub-set as a data-definition DSL together with some functions
> > which will generate some code based on supplied defined data types. My
> > idea is:
> >
> > data Person = Person {
> >          id :: Int
> >          , name :: String
> >          , email :: Maybe String
> >          }
> >          deriving (Show, Data, Typeable)
> >
> > emit_proto Person 1
> >
> > where emit_proto is function which will translate Person data type
> > definition into Google's proto language (the 1 is index from which start
> > to index type's fields) by traversing data type definition and
> > translating all its children plus do some header/footer generation etc:
> >
> > message Person {
> >    required int32 id = 1;
> >    required string name = 2;
> >    optional string email = 3;
> > }
> >
> > I've looked for something like that and found SYB papers which works on
> > top of data instance (i.e. actual data, not data type). I also found
> > JSON lib which again works on top of data and not data type. I've tried
> > to look into Data.Typetable etc, but have not found function which will
> > print data type's field name and field type name (although JSON lib
> > seems to use field name for JSON generation so I'll need to investigate
> > this more). I've tested `typeOf' function and it's quite useful, but its
> > limitation is that it's not working on ADT name:
> >
> > data Color = RED|GREEN|BLUE
> >
> > *Main> typeOf Color
> >
> > <interactive>:1:8: Not in scope: data constructor `Color'
> >
> > *Main> typeOf RED
> > Main.Color
> >
> > and I would need that in order to translate Color defined above into
> > enum like:
> >
> > enum Color {
> >    RED = 0;
> >    GREEN = 1;
> >    BLUE = 2;
> > }
> >
> >
> > My question is: do you think I'm looking into good direction (i.e.
> > Data/Typeable) or do you think I'll need to use something different for
> > data definition DSL (Template Haskell?, or impossible in Haskell so
> > write my own language with full parser? etc?)
> >
> > Thanks for any idea or opinion on this!
> > Karel
> >
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111004/5c62709b/attachment.htm>


More information about the Haskell-Cafe mailing list