I have a F# FAKE build file that I want to call with a parameter conf that can have two values, cs and sk. My batch file looks like this
#echo off
cls
"tools\nuget\nuget.exe" "install" "FAKE" "-OutputDirectory" "tools" "-ExcludeVersion"
"tools\FAKE\tools\Fake.exe" build.fsx conf=sk
pause
In the F# file, I get the parameter using environVar "conf" and this works ok.
Now I want to create a helper methof in the F# file that matches the conf parameters and returns a string (build configuration value in my case), so I have
let getConfiguration conf =
if (conf=="cs") then "Release"
else "Release(SK)"
I get a strange message
build.fsx(29,71): error FS0001: The type 'string' does not support the operator '=='
This is how I use the method
Target "Build" (fun _ ->
!! #"**/*.csproj"
|> MSBuild buildDir "Build" ["Configuration",(getConfiguration (environVar "conf"))]
|> Log "AppBuild-Output: "
)
The F# equality operator is =.
I don't know FAKE or whether your approach will work, but the reason for the compiler error is that, as the error message states, there is no == operator. Valid version:
if conf = "cs" then "Release" else "Release(SK)"
See e.g. the symbol and operator reference in the MSDN.
Related
I want to list every function of a SML library. Is there something like an help command?
For example:
Is there a way to see this list in the PolyML terminal?
I need to view it on the terminal without using google. I can't use internet during the exam and I can't bring notes.
You can type open TextIO; in the REPL. This will import the content of the module into your current scope, but in the REPL it will also have the side-effect of printing what it imported. You may not be interested in the scope being updated like that, so it may be wise to restart the REPL afterwards if you intend to use it again.
$ poly
Poly/ML 5.7.1 Release
> open TextIO;
structure StreamIO: TEXT_STREAM_IO
val canInput = fn: instream * int -> int option
val closeIn = fn: instream -> unit
val closeOut = fn: outstream -> unit
...
How to get rid of this annoying error? I do not understand what it want me to do.
This happens when I am trying to run a test
Clicking on "Run" follows up with the following
Screen
Clicking on "Continue Anyway" runs the tests normally.
So what should I do in order to stop this window from popping up every time I ran the tests?
Updated:
Here is what I've found myself meanwhile:
From here
if (targetType == PyRunTargetVariant.PYTHON && !isWellFormed()) {
throw RuntimeConfigurationError("Provide a qualified name of function, class or a module")
}
And a function isWellFormed() declaration from here
/**
* Sanity check for "target" value. Does not resolve target, only check its syntax
* CUSTOM type is not checked.
*/
fun TargetWithVariant.isWellFormed() = when (targetVariant) {
PyRunTargetVariant.PYTHON -> Regex("^[a-zA-Z0-9._]+[a-zA-Z0-9_]$").matches(target ?: "")
PyRunTargetVariant.PATH -> !VfsUtil.isBadName(target)
else -> true
}
Everything looks good with a regex of my test class and method names.
Ok, this is really weird.
I took a good look at a regex and found that it doesn't want any '-' in the target path. So renaming a filename from ads_wrapper-tests.py to ads_wrapper_tests.py solves the problem and the window is not popping up any more.
With this issue Error: Provide a qualified name of a function, class or module just got fixed, soon Pycharm would allow using all valid identifier names in target name.
tl;dr I'm trying to make a source transformation binary using AST_mapper and ppx_driver. I can't figure out how to get the example in the AST_mapper docs to be used by ppx_driver. Are there any good examples of how to use Ppx_driver.register_transformation_using_ocaml_current_ast?
I'm trying to port the example AST_mapper in the docs to be compatible with ppx_driver. Specifically, I'm looking to create a binary that takes source as input, transforms the source using this test mapper, and then outputs the transformed source. Unfortunately, the default main provided by Ast_mapper only accepts Ocaml AST as input (and presumably produces it as output). This is undesirable, because I don't want to have to run this through ocamlc with -dsource to get my output.
Here's my best stab at porting this:
test_mapper.ml
open Asttypes
open Parsetree
open Ast_mapper
let test_mapper argv =
{ default_mapper with
expr = fun mapper expr ->
Pprintast.expression Format.std_formatter expr;
match expr with
| { pexp_desc = Pexp_extension ({ txt = "test" }, PStr [])} ->
Ast_helper.Exp.constant (Ast_helper.Const.int 42)
| other -> default_mapper.expr mapper other; }
let test_transformation ast =
let mapper = (test_mapper ast) in
mapper.structure mapper ast
let () =
Ppx_driver.register_transformation_using_ocaml_current_ast
~impl:test_transformation
"test_transformation"
A few things to note:
The example from the docs didn't work out of the box (before introducing ppx_driver): Const_int 42 had to be replaced with Ast_helper.Const.int 42
For some reason test_mapper is Parsetree.structure -> mapper. (It is unclear to me why a recursive transformation needs the structure to create the mapper, but no matter.) But, this type isn't what Ppx_driver.register_transformation_using_ocaml_current_ast expects. So I wrote a sloppy wrapper test_transformation to make the typechecker happy (that is loosely based off how Ast_mapper.apply_lazy appears to apply a mapper to an AST so in theory it should work)
Unfortunately, after compiling this into a binary:
ocamlfind ocamlc -predicates ppx_driver -o test_mapper test_mapper.ml -linkpkg -package ppx_driver.runner
And running it on a sample file:
sample.ml
let x _ = [%test]
with the following:
./test_mapper sample.ml
I don't see any transformation occur (the sample file is regurgitated verbatim). What's more, the logging Pprintast.expression that I left in the code doesn't print anything, which suggests to me that my mapper never visits anything.
All of the examples I've been able to find in the wild are open sourced by Jane Street (who wrote ppx_*) and seem to either not register their transformation (perhaps there's some magic detection going on that's going over my head) or if they do they use Ppx_driver.register_transformation ~rules which uses Ppx_core.ContextFree (which doesn't seem to be complete and won't work for my real use case--but for the purposes of this question, I'm trying to keep things generally applicable).
Are there any good examples of how to do this properly? Why doesn't ppx_driver use my transformation?
If you want to make a standalone rewriter with a single module, you need to add
let () = Ppx_driver.standalone ()
to run the rewriter and links with ppx_driver and not ppx_driver.runner: ppx_driver.runner runs the driver as soon as it is loaded, therefore before your transformation is registered. Note also that you should at least specify a specific Ast version and uses Ppx_driver.register_transformation rather than Ppx_driver.register_transformation_using_current_ocaml_ast otherwise there is little point in using ppx_driver rather than doing the parsing by hand with compiler-libs and the Pparse module.
I have implemented a pretty-printer for a module. Currently I start up utop, load the dependencies then do #install_printer pp_custom;; where pp_custom is the pretty-printer.
I would like to automate this so that I can have it in a way that is similar to the lacaml library where the pretty-printer for the matrix is "installed" by default.
How would I go about to doing that?
In short, you need to run #install_printer directive whenever you load your library in the top. I'm using the following code to evaluate code in the toplevel:
open Core_kernel.Std
open Or_error
let eval_exn str =
let lexbuf = Lexing.from_string str in
let phrase = !Toploop.parse_toplevel_phrase lexbuf in
Toploop.execute_phrase false Format.err_formatter phrase
let eval str = try_with (fun () -> eval_exn str)
It depends on Core_kernel, but you can get rid of this easily, by just using eval_exn instead of eval (the last one wraps a possible exception into the Or_error monad). Once you've got the eval function, it can be used to load your printers:
let () = eval (sprintf "#install_printer %s;;" printer)
where printer is the name of the pretty printing function (usually qualified with a module name). Usually, one put such code into the separate library, named library.top, where library is the name of your library.
For further automation, you can require all types, that you want to be auto-printable in toplevel, to register itself in a central registry, and then call all registered printers, instead of enumerating them by hand. To see all this working at once, you can take a look at the BAP library. It has a sublibrary called bap.top that automatically installs all printers. Each type that is desired to be printable implements Printable signature, using Printable.Make functor, that not only derives many printing functions from the basic definition, but also registers the generated pretty-printers in Core_kernel's Pretty_printer registry (you can use your own registry, this is just a set of strings, nothing more). When bap.top library is loaded into the toplevel (using require or load directive), it enumerates all registered printers and install them.
There are subprojects and allprojects properties, but how can I just literally list the known subset of projects? I try the following approach:
[project(':child1'), project(':child2')] {
...
}
which is inspired by the output of println allprojects:
[project ':stripper', project ':webui', project ':wikidigest']
but it doesn't work. Log output:
* What went wrong:
A problem occurred evaluating root project 'projects'.
> No signature of method: java.util.ArrayList.call() is applicable for argument types: (build_1ngb77rivv12hrhe33snq4jat0$_run_closure4) values: [build_1ngb77rivv12hrhe33snq4jat0$_run_closure4#38a3f968]
Possible solutions: tail(), wait(), last(), any(), max(), wait(long)
The solution was to wrap list by call to configure():
configure([project(':child1'), project(':child2')]) {
...
}