38 |
53 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | # Autodetect text or binary. Do not leave merge conflict markers in the files.
5 | * text=auto merge=union
6 |
7 | # Use LF in the working directory by default. Override with core.autocrlf=true.
8 | *.fs text eol=lf
9 | *.fsi text eol=lf
10 |
11 | # Visual Studio can read LF sln files, but it always writes them as CRLF.
12 | *.sln eol=crlf
13 |
14 | ###############################################################################
15 | # Set default behavior for command prompt diff.
16 | #
17 | # This is need for earlier builds of msysgit that does not have it on by
18 | # default for csharp files.
19 | # Note: This is only used by command line
20 | ###############################################################################
21 | #*.cs diff=csharp
22 |
23 | ###############################################################################
24 | # Set the merge driver for project and solution files
25 | #
26 | # Merging from the command prompt will add diff markers to the files if there
27 | # are conflicts (Merging from VS is not affected by the settings below, in VS
28 | # the diff markers are never inserted). Diff markers may cause the following
29 | # file extensions to fail to load in VS. An alternative would be to treat
30 | # these files as binary and thus will always conflict and require user
31 | # intervention with every merge. To do so, just uncomment the entries below
32 | ###############################################################################
33 | #*.sln merge=binary
34 | #*.csproj merge=binary
35 | #*.vbproj merge=binary
36 | #*.vcxproj merge=binary
37 | #*.vcproj merge=binary
38 | #*.dbproj merge=binary
39 | #*.fsproj merge=binary
40 | #*.lsproj merge=binary
41 | #*.wixproj merge=binary
42 | #*.modelproj merge=binary
43 | #*.sqlproj merge=binary
44 | #*.wwaproj merge=binary
45 |
46 | ###############################################################################
47 | # behavior for image files
48 | #
49 | # image files are treated as binary by default.
50 | ###############################################################################
51 | #*.jpg binary
52 | #*.png binary
53 | #*.gif binary
54 |
55 | ###############################################################################
56 | # diff behavior for common document formats
57 | #
58 | # Convert binary document formats to text before diffing them. This feature
59 | # is only available from the command line. Turn it on by uncommenting the
60 | # entries below.
61 | ###############################################################################
62 | #*.doc diff=astextplain
63 | #*.DOC diff=astextplain
64 | #*.docx diff=astextplain
65 | #*.DOCX diff=astextplain
66 | #*.dot diff=astextplain
67 | #*.DOT diff=astextplain
68 | #*.pdf diff=astextplain
69 | #*.PDF diff=astextplain
70 | #*.rtf diff=astextplain
71 | #*.RTF diff=astextplain
72 |
73 | *.sh text eol=lf
74 |
--------------------------------------------------------------------------------
/docs/content/tutorial.fsx:
--------------------------------------------------------------------------------
1 | (*** hide ***)
2 | // This block of code is omitted in the generated HTML documentation. Use
3 | // it to define helpers that you do not want to show in the documentation.
4 | #I "../../src/FSharp.Quotations.Evaluator/bin/Release/netstandard2.0/"
5 |
6 | (**
7 | F# Quotations Evaluator Tutorial
8 | ========================
9 |
10 | To reference the library:
11 |
12 | *)
13 | #r "FSharp.Quotations.Evaluator.dll"
14 | open FSharp.Quotations.Evaluator
15 | open FSharp.Quotations
16 |
17 | (**
18 | Evaluation
19 | ----------
20 |
21 | To evaluate a strongly typed quotation:
22 | *)
23 |
24 | QuotationEvaluator.Evaluate <@ 1 + 1 @> // 2
25 |
26 | (**
27 | To evaluate a weakly typed quotation, use `EvaluateUntyped`. An object is returned, which
28 | you can cast to the expected type when it is known.
29 | *)
30 |
31 | let evalTuple n =
32 | let v = Expr.NewTuple (List.replicate n (Expr.Value n)) // codegen (fun x -> (x,x))
33 | v.EvaluateUntyped()
34 |
35 | evalTuple 4 // obj = (4,4,4,4)
36 | evalTuple 5 // obj = (5,5,5,5,5)
37 |
38 |
39 | (**
40 | Compilation
41 | -----------
42 |
43 | All evaluation is currently done via compilation. In the future some evalaution may be done via interpretation.
44 | To force compilation, use "Compile".
45 |
46 | *)
47 |
48 | let addPlusOne = QuotationEvaluator.Evaluate <@ fun x y -> x + y + 1 @>
49 |
50 | let nine = addPlusOne 3 5 // 9
51 |
52 | (**
53 | Extension methods
54 | -----------------
55 |
56 | Extension methods are available for compilation and evaluation:
57 |
58 | *)
59 |
60 | let onePlusOneExpression = <@ 1 + 1 @> // 2
61 |
62 | onePlusOneExpression.Evaluate()
63 |
64 | (**
65 | On-the-fly code generation
66 | --------------------------
67 |
68 | You can generate lambdas and compile them dynamically:
69 | *)
70 |
71 |
72 | let tupler =
73 | let v = Var("x",typeofPM> Install-Package FSharp.Quotations.Evaluator18 |