1

Trying to convert an XML file (e.g. a list of sales record) to a list of type_sales in F#. but i don't want to write something like: xmlnode.product = typesales.product xmlnode.price = typesales.price ...etc

I want to have some code that just takes ("product", "price", ...etc) and do the mapping, similar to lisp macro

Can i do this in f#?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Thanks KVB for the link. Very new to F#, the question popped up while I was playing with this XML file in F#, but now I think my general question is: does F# have something like macro in lisp?

huirong
  • 51
  • 6
  • 2
    It's not clear to me exactly what you're looking for, but maybe http://tpetricek.github.com/FSharp.Data/docs/XmlProvider.html would be of interest? – kvb Jan 22 '13 at 22:58
  • possible duplicate of [F# Type Providers vs. Lisp macros](http://stackoverflow.com/questions/12116119/f-type-providers-vs-lisp-macros) – ildjarn Jan 22 '13 at 23:30
  • ildjarn: thx, ur link did answer my question. – huirong Jan 23 '13 at 15:37

1 Answers1

-1

There's an F# XML type-provider that might be of use:

http://fsharp.github.io/FSharp.Data/library/XmlProvider.html

Given an XML file at compile-time, it will generate the required types to access the document in a statically typed way.

type Author = XmlProvider<"""<author name="Paul Feyerabend" born="1924" />""">
let sample = Author.Parse("""<author name="Karl Popper" born="1902" />""")

printfn "%s (%d)" sample.Name sample.Born
Danny Tuppeny
  • 40,147
  • 24
  • 151
  • 275