I'd like to follow the N+1 days of MvvmCross tutorials in F#, e.g. translating the original C# into F#.
I've been doing a lot of OCaml but .NET and Mono are generally new to me, I've tried them many times on Mac OSX
and they finally work very well under Xamarin Studio, with the great use case of cross-platform mobile development.
MvvmCross starts with a Core library as a C# PCL project, however, until 2/20/2014, there was no F# PCL.
In the current masters there is one, here's how to get it:
- select Alpha channel in Xamarin Studio and update, get Mono 3.2.7
- install F# bindings, their version will be 3.2.23
- install F# iOS add-in
Get github.com/fsharp/fsharp, do
./autogen.sh --prefix=/Library/Frameworks/Mono.framework/Versions/3.2.7
make
make install
Then get https://github.com/fsharp/fsharpbinding, install from monodevelop/ per fsharp.org/use/ios/.
Installing the package will warn about uninstalling the 3.2.23 version, and will now show 3.2.24.
The F# iOS addin will be disabled, you can reenable it.
Now we create a new solution EffinPickle
with an F# Portable Library project, EffinPickle.Core
.
The FSharp.Core
reference is red, the message under it says there's no version for .NETportable
. We simply remove it. We can add the version 4.3.1.0 from the newly installed F#; interestingly we don't need to add an FSharp.Core
at all, the template code compiles without it.
We set the portable profile 78 per various tweets. :)
If we build it right away, we get a warning:
/Library/Frameworks/Mono.framework/Versions/3.2.7/lib/mono/4.5/Microsoft.Common.targets: Warning: Unable to find framework corresponding to the target framework moniker '.NETFramework,Version=v4.5,Profile=Profile78'. Framework assembly references will be resolved from the GAC, which might not be the intended behavior. (EffinPickle)
Changing the profile doesn't seem to help.
In Xamarin Studio, we add addin repository http://mrward.github.com/monodevelop-nuget-addin-repository/4.0/main.mrep, and install NuGet addin. With it, we install package MvvmCross, MvvmCross CrossCore.
Juan Gómez created an F# translation of the MvvmCross Hello World example
http://jmgomez.me/reaching-the-nirvana-mvvmcross-xamarin.ios-fsharp.
The project looks like it was developed in Visual Studio and the ReachingNirvana.Core
library is not portable. It was not building in Xamarin Studio on Mac.
We copy the App.fs
form it, and split out the view model into the new FirstViewModel.fs
file into ViewModels
folder.
We remove the .cs
equivalents from the MvvmCross template.
Building shows the following error in FirstViewModel.fs
:
/Users/Alexy/Projects/EffinPickle/EffinPickle.Core/ViewModels/FirstViewModel.fs(6,6): Error FS1108: The type 'INotifyPropertyChanged' is required here and is unavailable. You must add a reference to assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'. (FS1108) (EffinPickle.Core)
Obviosly the C# equivalent, produced by adding the same MvvmCross NuGet packages, does not require that dependency.
What is going on?
Github issue: fsharp/fsharp#196
fsharp-opensource post: https://groups.google.com/forum/?hl=en#!topic/fsharp-opensource/EVGO7LQFIBo