lundi 12 décembre 2016

checking Code Quotation structure during compile time

can I define a quotation expression paramter such that not only the resulting type of the expression is compile time checked but also the call site expression.

lets see an example:

type A = {
    a : int
}

type Checker () =
     static member Check(e : Expr<int>) : ResultType = ...

The following obviously type check

let a = { a = 1 }
Checker.Check <@ a.a @>

Resulting in an actual Expression similar to PropertyGet( ..., PropertyGet (....), x).

And now some other way

let getInt (a:A) : int = a.a

The following also compiles

Checker.Check <@ getInt a @>

However how can I prevent that second example compiles and only allow for PropertyGets? (just as an example).
I know I can check the structure of the expression at run time - but I like to have an compile time check.





Aucun commentaire:

Enregistrer un commentaire