Fsharpc cannot generate fsi files - f#

I am trying to generate the fsi file for a particular fs file.
Config.fs:
namespace Web2
open FSharp.Data
module Config =
type JsonConfig =
JsonProvider<Sample="./config.json">
let config =
JsonConfig.Load("./config.json")
Generating the signature file:
fsharpc --sig:Config.fsi Config.fs
Error:
Microsoft (R) F# Compiler version 10.2.3 for F# 4.5
Copyright (c) Microsoft Corporation. All Rights Reserved.
Config.fs(8,5): error FS0039: The type 'JsonProvider' is not defined.
Config.fs(8,5): error FS0039: The type 'JsonProvider' is not defined.
Config.fs(11,16): error FS0039: The field, constructor or member 'Load' is not defined.
Not sure what I am doing wrong.

The issue is that the code in Config.fs depends on JsonProvider which comes from the FSharp.Data.dll library - but when you invoke the compiler, you are not specifying the dependency.
You can do that by using the -r command line option:
fsharpc -r:whatever/folder/FSharp.Data.dll --sig:Config.fsi Config.fs
In general, if you are compiling a project, the references are specified in the project file and so you do not need to specify them elsewhere. But when you're invoking the compiler directly, you need to do that.

Related

"Type JsonProvider is not defined" in fsx script

In my .fsx script I have:
#r "nuget: FSharp.Data"
open FSharp.Data
type appSettings = JsonProvider<"C:\\Users\\me\\schema\\sample.json">
This generates an error of Type JsonProvider not defined both in the IDE and when I build it using dotnet fsi. How can I fix this?

How to launch FsUnit tests on Linux/Mac

I have installed FsUnit
» nuget install fsunit
Attempting to resolve dependency 'NUnit (≥ 2.6.3)'.
Installing 'NUnit 2.6.3'.
Successfully installed 'NUnit 2.6.3'.
Installing 'FsUnit 1.3.0.1'.
Successfully installed 'FsUnit 1.3.0.1'.
I have created simple unit test:
module Tests
open NUnit.Framework
open FsUnit
[<Test>]
let ``simple test`` () =
1 |> should equal 1
Here is I am launching my test:
» fsharpc -r NUnit.2.6.3/lib/nunit.framework.dll -r FsUnit.1.3.0.1/Lib/Net40/FsUnit.NUnit.dll 01_binomial_tests.fs
F# Compiler for F# 3.1 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License
/Users/demas/development/book_exericses/fsharp_deep_dive/01_binomial_tests.fs(7,1): warning FS0988: Main module of program is empty: nothing will happen when it is run
It was compiled fine but I don't know how to launch the tests without VS
Update
I have tried to use NUnit.Runners:
> nuget install NUnit.Runners
> fsharpc -r NUnit.2.6.3/lib/nunit.framework.dll -r FsUnit.1.3.0.1/Lib/Net40/FsUnit.NUnit.dll --target:library 01_binomial_tests.fs
> mono NUnit.Runners.2.6.4/tools/nunit-console.exe 01_binomial_tests.dll
NUnit-Console version 2.6.4.14350
Copyright (C) 2002-2012 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.
Runtime Environment -
OS Version: Unix 14.4.0.0
CLR Version: 2.0.50727.1433 ( Mono 3.5 ( 3.10.0 ((detached/92c4884 Thu Nov 13 23:27:38 EST 2014) ) )
ProcessModel: Default DomainUsage: Single
Execution Runtime: mono-3.5
Could not load file or assembly '01_binomial_tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
You have a couple of options:
Add dependency on NUnit.Runners NuGet package, which comes with a stand-alone runner
Use Xamarin Studio, which seems to have Unit Tests panel for running tests
Use FAKE which is a nice F# build tool that can run unit tests
I personally use FAKE because it nicely automates everything. To do that, you need to put something like this in your FAKE build.fsx script:
Target "Test" (fun _ ->
!! "/tests*.dll |> NUnit (fun p ->
{p with
DisableShadowCopy = true;
OutputFile = testDir + "TestResults.xml" })
)
You'll need dependencies on FAKE and NUnit.Runners and then FAKE should also find the runner automatically (so you do not have to set it explicitly in your build script).

compiling F# on linux with TPL

I am pretty feeling pretty stumped with this issue... i am trying to compiling an F# prog that uses the TPL. I am using an up to data verson of mono which compiles C# and TPL.
The F# project is for a uni, which need to be run on there machines, so i have limited access i.e. no sudo rights. it is also commandline driven
These are errors generated:
Microsoft (R) F# 2.0 Compiler build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
/home/msc/sg315/fs/MapSkel.fs(12,23): error FS0039: The namespace 'Tasks' is not defined
/home/msc/sg315/fs/MapSkel.fs(23,5): error FS0039: The namespace or module 'Parallel' is not defined
/home/msc/sg315/fs/MapSkel.fs(31,3): error FS0039: The namespace or module 'Parallel' is not defined
/home/msc/sg315/fs/MapSkel.fs(44,5): error FS0039: The namespace or module 'Parallel' is not defined
/home/msc/sg315/fs/MapSkel.fs(52,12): error FS0039: The namespace or module 'Parallel' is not defined
/home/msc/sg315/fs/MapSkel.fs(55,12): error FS0039: The namespace or module 'Parallel' is not defined
/home/msc/sg315/fs/MapSkel.fs(61,12): error FS0039: The namespace or module 'Parallel' is not defined
/home/msc/sg315/fs/MapSkel.fs(68,12): error FS0039: The namespace or module 'Parallel' is not defined
/home/msc/sg315/fs/MapSkel.fs(77,13): error FS0039: The namespace or module 'Parallel' is not defined
/home/msc/sg315/fs/BHList.fs(60,14): error FS0039: The field, constructor or member 'ReadLines' is not defined
-bash-4.1$
It obviously needs library references but have no idea which ones...
Thanks
As in your previous question Compiling issues with mono and multi-threaded application, the problem is that you are targeting a version of .NET which is too old.
You can download the new compiler source here http://github.com/fsharp/fsharp. Newer versions of the compiler automatically target a more moder .NET. This can be compiled and installed into a home directory (no root required).

"Required package rtl not found" when building with Hudson

I am trying to get Hudson to work with my Delphi project. I am using the following batch file to build my project (as suggested in this blog post):
call "C:\Program Files\Embarcadero\RAD Studio\8.0\bin\rsvars.bat"
msbuild /p:Win32LibraryPath="$(BDS)\lib;$(BDS)\lib\win32\release;$(BDS)\lib\win32\debug;$(BDSUSERDIR)\Imports;$(BDS)\Imports;$(BDSCOMMONDIR)\Dcp;$(BDS)\include;" /t:build /p:config=Debug /verbosity:detailed "MyProject\src\MyProject.dproj"
if errorlevel 1 exit 1
I always end up with the error
Embarcadero Delphi for Win32 compiler version 22.0
Copyright (c) 1983,2010 Embarcadero Technologies, Inc.
Fatal: E2202 Required package 'rtl' not found
I don't understand this as rtl.dcp is in "$(BDS)\lib\win32\release" which is on the library path. I am using runtime packages by the way.
Any hints what I can do to solve this?
Edit It seems that the paths do not end up in the command line, which looks something like (after removing project-specific paths):
C:\Program Files\Embarcadero\RAD Studio\8.0\bin\dcc32.exe -$O- -$W+ --inline:off -$A4 -$R+ -$Q+ --doc --no-config -B -LUrtl;vcl;ReportingR;ComponentsR -Q -AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE -DDEBUG;CONSTRAINT_CHECKING;_VER6;EUREKALOG_VER6;EurekaLog -V -VN -GD --drc -W-SYMBOL_DEPRECATED -W-SYMBOL_PLATFORM -W-UNIT_PLATFORM -W-UNIT_DEPRECATED Myproject.dpr
I found the answer in a comment to the original blog post. It turns out that in Delphi XE they changed the name of the Win32LibraryPath property to DelphiWin32LibraryPath. Changing the batch script accordingly fixes the issue.
The first path $(BDS)\Lib for XE,XE2 and XE 10.2 should be change for $(BDSLIB)\$(PLATFORM)\release

Installing luasql 2.2 with luarocks onto lua for windows install

So it turns out lua for windows install has some earlier 2.1 version of luasql on it, and I need to be able to use luasql 2.2 (particularly mysql). I've spent all day trying to install this thing with luarocks but keep hitting a wall. This is the 3rd wall I've hit but the first one that I just have no clue where to even begin.
I run: luarocks install luasql-mysql MYSQL_DIR="E:/Programs/MySQL/MySQL Server 5.5"
It goes through and outputs (removing a lot of the output where it's just repeating the same thing but different file):
Extracting luasql-2.2.0\src\jdbc
Extracting luasql-2.2.0\src\jdbc\Makefile
... (lots of these here)
Extracting luasql-2.2.0\vc6\sqlite.def
Everything is Ok
Folders: 17
Files: 84
Size: 358091
Compressed: 440320
cl /MD /O2 -c -Fosrc/luasql.obj -IF:/Code/Lua/5.1/include src/luasql.c -IE:/Prog
rams/MySQL/MySQL Server 5.5/include
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
luasql.c
cl /MD /O2 -c -Fosrc/ls_mysql.obj -IF:/Code/Lua/5.1/include src/ls_mysql.c -IE:/
Programs/MySQL/MySQL Server 5.5/include
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
ls_mysql.c
e:\programs\mysql\mysql server 5.5\include\mysql_com.h(291) : error C2061: synta
x error : identifier 'SOCKET'
e:\programs\mysql\mysql server 5.5\include\mysql_com.h(337) : error C2059: synta
x error : '}'
... (lots of these here, same errors just different lines)
E:/Programs/MySQL/MySQL Server 5.5/include\mysql.h(374) : error C2143: syntax er
ror : missing '{' before '*'
E:/Programs/MySQL/MySQL Server 5.5/include\mysql.h(374) : fatal error C1003: err
or count exceeds 100; stopping compilation
Error: Build error: Failed compiling object src/ls_mysql.obj
Any idea where to start? I've had to a) install standalone mysql (was previously using one that came with WAMP since I was already using that before), and b) install visual studio 2010 (c# and c++ versions so far), and c) use visual studio command prompt to run the luarocks stuff, if I use regular command problem it breaks way before this.
I'm hoping this is an easy issue to fix for someone familiar with compiling C which is what this seems to be doing.
Add the following to ls_mysql.c after line 17:
#include <windows.h>
So that windows.h is included after winsock.h and before mysql.h.
References:
http://forums.mysql.com/read.php?45,37472,37472
C++ Redefinition Header Files (winsock2.h)

Resources