Xplot and Deedle in F# - f#

I am trying to run F# to work with Deedle and google XPlot and I have the following problem: It seems that the newest version XPlot (version 1.2.2 ) needs access to the module "Deedle.FSharpFrameExtensions". However Deedle (version 1.2.4) provides Deedle.F# Frame extensions. Hence I tried to add a module with the same name :
[]
module Deedle =
open Deedle
type FSharpFrameExtensions = F# Frame extensions
But it does not seem to work. Does anyone know a Workaround ?

Did you use the FSLab package from nuget? That is about all you need/want in a package, and as such the versioning all over is (should be?) ok.
Check out http://fslab.org/ and especially http://fslab.org/download/ for different download/usage options.

Related

How do I access FSharp.Data.JsonExtensions?

Sorry if this question is a bit unclear. It was the best I could do in my state of confusion about packages in F# 4.0.
The book Expert F# 4.0 by Don Syme, Adam Granicz, and Antonio Cisternino contains code that processes JSON data. The code starts with
open FSharp.Data
open FSharp.Data.JsonExtensions
I have FSharp.Data installed in Visual Studio. Still, the word "JsonExtensions" gets red squiggles under it and the rest of the code does not compile.
Going to Add References in the Solution Explorer I did not find a package FSharp.Data.JsonExtensions. I also looked under NuGet and found no package FSharp.Data.JsonExtensions. There is documentation for JsonExtensions
which suggests it is a module. However, using the dot in Visual Studio it does not appear under FSharp.Data. (There is only one entry: Unit Systems)
How can I make the code in this module available so I can run the code in the book?
This happens because actually you don't have FSharp.Data installed (So Foggy is right above). There is an FSharp.Data namespace but you need to nuget the package to be able to use it. So go to Tools | Nuget Package Manager | Manage Nuget Packages for Solution and download the latest and greatest FSharp.Data. This will automatically add it to your references file in VS:
See:
Now you can use it:
If you are using it from an .fsx script make sure to reference it with #r
#r #"..\packages\FSharp.Data.2.3.2\lib\net40\FSharp.Data.dll"
In that case you can just right-click on the References (after nugetting) and VS will generate you the path:
If you don't see Send to F# Interactive I strongly suggest you install the Visual F# Power Tools.
You can explore other ways of accessing/serializing JSON files: there is the JSON type provider, Newtonsoft JSON, FSharplu, Chiron, and FSPickler.

How do I compile F# code with ML compatibility?

The following F# fragment seems to be valid only if compiled in ML compatibility mode (run it here):
let i = (1 lxor 5)
However I can't compile it in a trivial project in Visual Studio 2012 or using fsc.exe from the command line. I get the error:
error FS0039: The value or constructor 'lxor' is not defined
Reading the F# spec it says
Although F# reserves several OCaml keywords for future use, the /mlcompatibility option enables the use of these keywords as identifiers.
It then lists lxor as one such operator. So I tried the command line fsc.exe Program.fs --mlcompatibility (version 11.0.60610.1), but it stil get the same error.
The documentation for fsc.exe seems to indicate that the mlcompatbility option only ignores warnings. I didn't see any other relevant options in fsc's documentation or project options in VS to enable compatibility.
All of the other SO questions about F#/ML compatibility seem to be related to which language constructs can be used, but all I'm looking for is how to actually compile in compatibility mode. Do I have to open a specific namespace, reference another assembly, or do something else?
Update
I have also tried using the open source compiler fsharpc (F# 3.0) on Mono on Ubuntu 13.04. The result is the same as fsc.
The --mlcompatibility option only turns off warnings, so this looks like a regression. YOu can verify this by searching the source for all references to mlcompatibility here https://github.com/fsharp/fsharp/search?q=mlCompatibility&type=Code.
When calling fsc (fsharpc on non-Windows systems), the compiler options go before the source filenames. So the correct way to call it would be something like:
fsc -o:MyProgram.exe --mlcompatibility Program.fs
When compiling with Visual Studio, you can go into the project's properties and add --mlcompatibility to the Other flags box:

CSV Type provider

I am trying to find a easy example or introduction to a CSV Type provider. So I followed this link to help me get started. Now I have a Visual Studio 2012 students edition and while documentation says that F# 3.0 has the CSV type provider I am not able to find it. So I am trying to use a type provider for a local CSV File. What I see is that the CSV TypeProvider mentioned does not exist at all. Since the given examples don't really compile I looked around and used something like this to load the oData services :
#r "FSharp.Data.TypeProviders"
///loading a stackoverflow odata type provider
type stackOverflow = Microsoft.FSharp.Data.TypeProviders.ODataService<"http://data.stackexchange.com/stackoverflow/atom">
So this is a bit different from what is mentioned in the example page above. I am not able to see the csv type provider. I use the Visual Studio IDE to list the type providers and csv is not listed. I tried updating the packages using nuget and this still persists. Can anyone point the right documentation on how to work with a csv type provider and also the right updated links where a simple example could be found?
FSharp.Data isn't a built-in library, so you either need to use nuget or manually download the package. See here for more information on where to get it (and how to use it).
If you manually download the project you can put it wherever you want and then simply use a file path to reference it with #r. For a path relative to your project, use the __SOURCE_DIRECTORY__ symbol, otherwise you can simply use the absolute file path of the .dll.
After referencing the dll, you still need to open the namespace, so you need to have open FSharp.Data after you reference the dll.
Alright so this is what I did. I used Nuget to manage references and I installed the FSharp.Data and FSharp.Data.TypeProviders and like #mydogisbox mentioned I then use the open FSharp.Data to load the csv files i.e.
open FSharp.Data.Csv
While this works if I use Nuget, it doesn't work otherwise. So have to figure out how to do that. For now this should suffice I guess.

How to i solve the MissingMethodException when using FSharp.Data.Json.JsonValue.Parse

Trying to parse a simple json string with the FSharp.Data.Json library and am faced with the following error. I am using F# 2.0 interactive. Any thoughts on how to go about solving the error
JsonValue.Parse(#"{""id"": ""117sds""}");;
System.MissingMethodException: Method not found: '!!0 Microsoft.FSharp.Collections.SeqModule.ExactlyOne(System.Collections.Generic.IEnumerable1<!!0>)'.
at FSharp.Data.Json.JsonParser..ctor(String jsonText, FSharpOption1 culture)
at FSharp.Data.Json.JsonValue.Parse(String text, FSharpOption`1 culture) in C:\Tomas\Projects\FSharp.Data\src\Library\Json.fs:line 215
at .$FSI_0063.main#()
As Jack pointed out, the F# Data library really only works with F# 3.0. If you can update the F# version, it will work and you'll get other benefits (like type providers).
If you cannot upgrade then you can probably just copy the file with JSON parser and runtime to your project and change a few things to support F# 2.0 (the licence allows that). The file you need is Json.fs.
I don't think we'd want to support 2.0 version (so far), but if the fix is easy, submit a pull request with the change and we can merge that to make this easier for others.
Seq.exactlyOne is a method which is only available in F# 3.0. Unfortunately, there's not going to be an easy way to use the FSharp.Data library from within F# 2.0.
As of version 1.1.6, the runtime components (Json parser, Csv parser and Http utilities) no longer use any method not present in FSharp.Core 4.0.0.0 (the F# 2.0 version), so you'll be able to use FSharp.Data with F# 2.0 if you don't use the type providers

A NaturalSpec method with ' in name not found on Mono

I've managed to compile NaturalSpec on mono and am trying an F# library project in MonoDevelop using it. The README test fails:
module ListSpec
open NaturalSpec
[<Scenario>]
let When_removing_an_3_from_a_small_list_it_should_not_contain_3() =
Given [1;2;3;4;5]
|> When removing 3
|> It shouldn't contain 3
|> Verify
-- with the error that NaturalSpec.Syntax.shouldn't method is not found. Replacing that by a should test rectifies that. Is there a problem for mono to use a method with an apostrophe in it? Compilation works fine, so that method is seen, but cannot be found at runtime?
I ended up recompiling NaturalSpec with F# 3.0 and .NET framework 4.5 from Mono 3.0.0, and then doing exactly the same with my own project. Apparently, when you open NaturalSpec.fsproj, you get .NET 3.5 as a default. Also, even with Mono 3.0.0, the default F# was 2.0. I've installed F# from open source code drop separately and specified fsc and fsi from it as in F# preferences in MonoDevelop. Now I made that NaturalSpec a reference, and unit tests are showing up properly in MonoDevelop -- a great way to do TDD in Mono.

Resources