I am trying to create a F# Library to use with Windows Store apps. I need access to the Windows namespace (especially Windows.Storage). What type of project should I choose for the library?
When I select F# Portable Library, there is no way to add reference to Windows.Storage, neither when I create a project of type F# Library. I am looking for something like Class Library (Windows Store Apps)
I've found Windows.Storage in here: C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral\Windows.winmd. This means that F# cannot directly reference it.
I suggest that you model your back-end around it (you do have to combine C# with your F# code, because F# doesn't work on its own with Windows 8).
Related
Since Visual Studio 2013 Update 2, it is possible to create Portable Class Libraries (PCLs) that can reference Windows Runtime types (which was not possible before) as long as they only target Windows 8.1 and Windows Phone 8.1 and no other targets.
I tried this in C# by adding a C# Class Library (Portable for Universal Apps) and it works, which means that you can consume and produce Windows Runtime types as if the project was a Windows App or Windows Runtime Component.
Since F# also supports PCLs and Windows 8.1 and Windows Phone 8.1 are supported targets, I would like to achieve the same with F# PCLs (if possible). While Visual Studio 2013 Update 4 does not offer creating F# PCLs that only target Windows 8.1 and Windows Phone 8.1, it is possible to modify the .fsproj file of an F# PCL to match the .csproj file of a C# PCL with those targets that was created with Visual Studio. This requires changing the XML elements to the following:
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile32</TargetFrameworkProfile>
and adding the following to an <ItemGroup>
<TargetPlatform Include="WindowsPhoneApp, Version=8.1" />
<TargetPlatform Include="Windows, Version=8.1" />
After these changes, I was able to consume and produce Windows Runtime types in the F# PCL as in the C# PCL (without complaints from Visual Studio in the F# PCL or C# (Universal) Windows App), but when I actually run the (Universal) Windows App I get the following exception when a function that uses Windows Runtime types is called in the F# PCL from the C# (Universal) Windows App:
An exception of type 'System.IO.FileNotFoundException' occurred in
[application name].exe but was not handled in user code
Additional information: Could not load file or assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null' or one
of its dependencies. The system cannot find the file specified.
When I check the references in the Solution Explorer of Visual Studio, the C# PCL shows a reference named Windows, which is missing from the F# PCL. The Reference Properties of that reference look like this:
I tried adding this reference manually to the .fsproj file of the F# PCL by adding
<Reference Include="C:\Program Files (x86)\Microsoft SDKs\Portable\v12.0\110C4FEFF2BA61C0746933A9ED6E248D\Windows.winmd" />
to an <ItemGroup>. After this, the reference does show up in the F# PCL in the Solution Explorer with the following Reference Properties:
but does not fix the problem. That is, I still get the same exception as before.
I also tried copying and pasting the Windows reference via the context menu of the Solution Explorer of Visual Studio, but it complains with an error message.
Do you know how to properly add the Windows reference to a F# PCL? This would be really awesome, because that would make it possible to write (Universal) Windows Apps almost entirely in F#! If you know for a fact that this is not possible, then could you please explain what is preventing this from being possible?
EDIT: improved formatting of exception message
You're making a portable class library. F# does not support windows store apps, so the only way you can use F# in such a situation is to call it from C#. If you manage to succeed, you'll be the first of anyone.
I need to do a http get in RAD Studio XE5 C++. The tutorials on the RAD Studio site discuss a RESTCLient that is not included with the version I have. I found the Casablanca project, which is specifically for Visual Studio, and I made a small program in VS that does the simple http get and handles response in the way I need.
What do I need to do to successfully use Casablanca from within RAD Studio?
There are the steps I have taken so far.
Compiled Casablanca in Visual Studio 2013
Copied the .lib and .dll over to a folder in the RAD Studio project
added that folder to the link path in the RAD Studio project
added the .lib to the project
added dll imports to classes that should be in the .lib to the .cpp I want to use the function in.
class __declspec(dllimport) http_client;
class __declspec(dllimport) filestream;
class __declspec(dllimport) producerconsumerstream;
class __declspec(dllimport) rawptrstream;
There was a OMF error, and I used a tool that came with RAD Studio to convert the .lib, that got past the error.
I don't know how to declare the dll prototype's of the functions, because the returns types are from a namespace in the library itself so they aren't recognized. http_client is an unrecognized structure.
I tried this as well without the class keyword.
DLLs that export classes are not portable across compilers. So you will not be able to use a Visual Studio compiled DLL in C++Builder if it exports classes. Either flatten the DLL interface to export plain C-style functions instead (and then use C++Builder's command-line IMPLIB tool to create an import .lib file for the DLL, do not use the .lib file created by Visual Studio), or else find another solution.
For instance, C++Builder (and Delphi) ships with Indy 10, which has a TIdHTTP component. You can use its TIdHTTP::Get() method to perform an HTTP GET request. But if you need to actually use REST, you might be better off simply upgrading your XE5 to a version that has TRESTClient available (BTW, Embarcadero's REST classes use Indy internally).
F#/ Visual studio pros, please help!
How to import libraries? Please just give me an example. How about java.io?
For Java I have tried to install thisbut didn't work.
It looks like you're trying to use the Stanford NLP libraries, these are available on NuGet and can be installed by right clicking on the project and selecting manage nuget packages. From there it's possible to add the references to the project. The .nuspec files which you've referenced in your project are for packaging up the libraries. So in your case, the nuspec filenames will be the thing that you search for in Nuget.
The Nuget website offers a guide for how to install packages here
.NET (which F# uses) and the JVM (which Java) uses are both managed code environments with many of the same capabilities.
But that are mutually incompatible.
While 3rd party tools might be able to bridge that gap (for at least simpler cases) there will be far more work to do that just referencing a .jar in Visual Studio.
Almost certainly better to use an equivalent .NET package (for IO look at the System.IO namespace (the necessary .NET assemblies should already be referenced).
In the Build 2011 keynote and demos, they were always talking about C++, C#, Visual Basic and JavaScript. Can't I build Metro style Apps with F#? Or is it safe to say that if it works with C#, then it works with F# as well?
Or is it eligible to say if it works with C# then it works with F# as well?
Yes, that's how it is supposed to work. In addition to javascript and C/C++, any CLS compliant language that runs on top of the CLR will have access to the WinRT API.
Unfortunately in the VS 2011 Express edition you don't get tooling support but I guess this will be added progressively or to other editions:
Don talks about this a little around 7:40 into his talk.
http://channel9.msdn.com/Events/BUILD/BUILD2011/SAC-904T
I had the same question and created a blog post: Create a Metro App in F# (NOT)
There are a few issues:
You cannot reference ordinary .NET dll’s (even in C#). They have to
be have recompiled with a “reference” to the WinRT. Because of this
you cannot reference the F# dll. I think this will be solved when F#
3.0 get released (source: Understanding F# slide from Don Syme at
build).
The ability from F# to create Metro apps. This has to be
built by the F# team. This is an open question. This is the all-F#
approach (In WPF it is today possible but not recommended).
Tool support for creation Metro front-end projects. This will be not the case for the
F# 3.0 release. (source: Understanding F# slide from Don Syme at
build).
Using Visual Studio 11 Developer Preview (Full, not Express), I was able to reference and run F# code from a C# Metro style application with the following caveats:
You will get a build warning saying that the project can't be referenced, even though Visual Studio will still allow you to add it.
You must remove all references to all DLL's in the F# project, including FSharp.Core.
By following these steps it is possible to run F# code from a C# Metro style application, but it is nearly impossible to write any useful code in F# without references to the core language libraries. Let's hope they update the libraries to be WinRT compatible soon.
The question has been answered here:
Windows 8 and F#
Although you cannot create and design Metro apps directly in F#, you can still create so called Portable library in F# with all Models and ViewModels and use it in another Metro projects. It's not ideal, but it works.
I ported my stock chart library for .NET3.5-4.0 to Portable library,it works quite well on Metro with C# Metro application and some my Metro UI bridge.
I'm convinced that I can use F# to make Metro application in many parts.
Some popular languages like Python and Ruby have native, JVM and .Net CLR implementations. C# is implemented with free Mono project. Aren't there any attempts of implementing F#?
As others pointed out, the standard F# implementation from Microsoft is just a .NET (CLI) application that runs on multiple implementations of CLI (namely .NET and Mono). F# also produces .NET (CLI) applications as libraries that also work on both .NET and Mono. However, that is still the same CLI implementation of F# (just running on different implementation of CLI)
To answer your question -
As far as I know, there is no other attempt to implement F# compiler for other platforms/runtimes.
F# shares a common background with OCaml, so the easiest way to get another implementation of F# would be to take OCaml and add F#-specific features (and remove OCaml-specific features).
You can use only shared sub-language and cross-compile using both F# and OCaml.
Also, there are some plans to release F# as open source, so it may be possible that (in the future), someone will port F# to other platforms such as JVM using the source (when released).
F# interactive, fsi.exe, already runs on Mono, as do compiled F# programs.
There is a compiler for targeting a subset of F# to FPGAs, which I guess is a non-.NET implementation
http://www.avalda.com/
Link
Mono is an implementation of .net which happens to include a c# compiler (as well as a vb compiler). It is not primarily a c# implementation.