tags:

views:

60

answers:

1

Hello,

Could anyone explain how to work WebSharper translator in conjunction with the F#? Is it translate F# code to JS itself or using F# compiler for it?

In second case, what F# compiler are doing when finds [] attribute in source? Does compiler generate functions in any case and in runtime construct JS as reflection from compiled bytecode or there something other?

+3  A: 

Hi, I develop WebSharper. Good question!

Roughly the compilation looks like this:

a.dll: a.fs b.fs c.fs
    fsc ...

a.dll.js: a.dll
    WebSharper.exe ..

When functions are annotated with [<JavaScript>], which is an alias for [<ReflectedDefinition>], the F# compiler does not only compile these functions to .NET IL, but also stores the representation of their syntax in the DLL metadata. This representation has type Quotations.Expr and can be recovered by reflection. Have a look at Quotations.DerivedPatterns.MethodWithReflectedDefinition.

WebSharper is therefore a source to source translator, and it is pretty direct (preserves lambdas, for example). In WebSharper 2.0 we have an intermediate Scheme-like language, but that is only there to help optimize the generated code.

toyvo
Thanks for information
semicode