Reputation: 1832
In Haskell I can use the quasiquoter to produce a custom AST using concrete syntax defined by custom parser, as described here: https://wiki.haskell.org/Quasiquotation
Is this possible in F#?
Upvotes: 0
Views: 119
Reputation: 12687
The closest thing I can think of is F#'s TypeProviders. It allows provider code to be part of the compiler pipeline, and constructs types to be injected.
For example, there's the XML type provider:
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
For more, see the FSharp.Data project.
Upvotes: 4