Are there any experiences using this library together with Fable for web/app development?
Is it feasible to make it compatible and work well with Fable?
@alfonsogarciacaro may have some experience using both libraries.
As far as I know there shouldn't be any problem using this library and Fable, but Fable might be having problems translating static constrained functions, if so you will have to avoid using them, but that shouldn't be a problem, use the non generic extensions instead.
I haven't used FSharpPlus with Fable much yet. It would be interesting to try to port some of the tests. Some Fable devs use Aether which heavily uses SRTP (some have reported problems in certain cases, but nobody has been able to isolate the issue). In Fable 2 we've improved SRTP resolution so hopefully it works better, although the use of flexible types + interfaces can be problematic in some situations.
Have anyone tried FSharpPlus with Fable?
Let's start by adding the config for the nuget package then we can try it and add some tests.
Even if it doesn't work, we can isolate a subset of the library that exposes the functions Fable can understand.
The config has been added and fable is now correctly picking up the nuget.
However, fable does have trouble compiling the source. Here are the errors:
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(1030,12): (1030,24) error FABLE: Cannot resolve System.Threading.Tasks.Task.get_IsCanceled
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(1031,17): (1031,28) error FABLE: Cannot resolve System.Threading.Tasks.Task.get_IsFaulted
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(1031,42): (1031,53) error FABLE: Cannot resolve System.Threading.Tasks.Task.get_Exception
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(1032,24): (1032,32) error FABLE: Cannot resolve System.Threading.Tasks.Task`1.get_Result
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(1036,23): (1036,52) error FABLE: Cannot resolve System.Threading.Tasks.TaskCompletionSource`1..ctor
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(1037,66): (1037,88) error FABLE: Cannot resolve System.Threading.CancellationToken.get_None
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(1038,51): (1038,72) error FABLE: Cannot resolve System.Threading.Tasks.TaskCompletionSource`1.TrySetCanceled
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(1044,34): (1044,55) error FABLE: Cannot resolve System.Threading.Tasks.TaskCompletionSource`1.TrySetCanceled
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(1045,34): (1045,55) error FABLE: Cannot resolve System.Threading.Tasks.TaskCompletionSource`1.TrySetException
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(1048,24): (1048,53) error FABLE: Cannot resolve System.Threading.Interlocked.Decrement
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(1049,25): (1049,46) error FABLE: Cannot resolve System.Threading.Tasks.TaskCompletionSource`1.SetResult
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(1050,112): (1050,133) error FABLE: Cannot resolve System.Threading.Tasks.TaskScheduler.get_Default
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(1050,17): (1050,134) error FABLE: Cannot resolve System.Threading.Tasks.Task`1.ContinueWith
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(1051,13): (1051,21) error FABLE: Cannot resolve System.Threading.Tasks.TaskCompletionSource`1.get_Task
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(177,35): (177,74) error FABLE: Cannot resolve System.Linq.Enumerable.Repeat
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(181,59): (181,77) error FABLE: Cannot resolve System.Collections.ObjectModel.ReadOnlyCollection`1..ctor
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(189,46): (189,71) error FABLE: Cannot resolve System.Collections.ObjectModel.ReadOnlyCollection`1..ctor
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(282,50): (282,116) error FABLE: Cannot resolve System.String.StartsWith
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(289,90): (289,124) error FABLE: Cannot resolve System.String.Normalize
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(295,41): (295,78) error FABLE: Cannot resolve System.Globalization.CharUnicodeInfo.GetUnicodeCategory
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(384,9): (391,78) error FABLE: Cannot resolve System.Linq.Enumerable.Join
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(406,40): (406,65) error FABLE: Cannot resolve System.Collections.ObjectModel.ReadOnlyDictionary`2..ctor
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(464,9): (470,96) error FABLE: Cannot resolve System.Linq.Enumerable.Union
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(464,9): (471,62) error FABLE: Cannot resolve System.Linq.Enumerable.ToDictionary
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(475,9): (482,76) error FABLE: Cannot resolve System.Linq.Enumerable.Join
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(475,9): (483,62) error FABLE: Cannot resolve System.Linq.Enumerable.ToDictionary
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(553,9): (559,96) error FABLE: Cannot resolve System.Linq.Enumerable.Union
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(553,9): (560,62) error FABLE: Cannot resolve System.Linq.Enumerable.ToDictionary
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(564,9): (571,78) error FABLE: Cannot resolve System.Linq.Enumerable.Join
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(564,9): (572,64) error FABLE: Cannot resolve System.Linq.Enumerable.ToDictionary
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(771,27): (771,46) error FABLE: Cannot compile expression AddressSet
(Value val curr,
Application
(Value val f,[],[Call (Some Value val e,member get_Current,[type 'a],[],[])]))
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(786,25): (786,57) error FABLE: Cannot compile expression AddressSet
(Value val curr,
Call
(Some Value val f,member Invoke,
[type Microsoft.FSharp.Core.int; type 'a; type 'b],[],
[Call (None,val op_Dereference,[],[type Microsoft.FSharp.Core.int],[Value val i]);
Call (Some Value val e,member get_Current,[type 'a],[],[])]))
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(799,25): (799,66) error FABLE: Cannot compile expression AddressSet
(Value val curr,
Call
(Some Value val f,member Invoke,[type 'a; type 'b; type 'c],[],
[Call (Some Value val e1,member get_Current,[type 'a],[],[]);
Call (Some Value val e2,member get_Current,[type 'b],[],[])]))
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(814,25): (814,70) error FABLE: Cannot compile expression AddressSet
(Value val curr,
Call
(Some Value val f,member Invoke,
[type Microsoft.FSharp.Core.int; type 'a; type 'b; type 'c],[],
[Call (None,val op_Dereference,[],[type Microsoft.FSharp.Core.int],[Value val i]);
Call (Some Value val e1,member get_Current,[type 'a],[],[]);
Call (Some Value val e2,member get_Current,[type 'b],[],[])]))
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(831,25): (831,78) error FABLE: Cannot compile expression AddressSet
(Value val curr,
Call
(Some Value val f,member Invoke,[type 'a; type 'b; type 'c; type 'd],[],
[Call (Some Value val e1,member get_Current,[type 'a],[],[]);
Call (Some Value val e2,member get_Current,[type 'b],[],[]);
Call (Some Value val e3,member get_Current,[type 'c],[],[])]))
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(881,29): (881,38) error FABLE: Cannot compile expression AddressSet (Value val curr,Value val r)
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(940,38): (940,70) error FABLE: Cannot compile expression AddressSet
(Value val curr,
NewTuple
(type 'a * 'b,
[Call (Some Value val e1,member get_Current,[type 'a],[],[]);
Call (Some Value val e2,member get_Current,[type 'b],[],[])]))
ERROR in ./.fable/FSharpPlus.1.0.0/Extensions.fs
Module Error (from ./node_modules/fable-loader/index.js):
[REDACTED local path]/.fable/FSharpPlus.1.0.0/Extensions.fs(953,44): (953,88) error FABLE: Cannot compile expression AddressSet
(Value val curr,
NewTuple
(type 'a * 'b * 'c,
[Call (Some Value val e1,member get_Current,[type 'a],[],[]);
Call (Some Value val e2,member get_Current,[type 'b],[],[]);
Call (Some Value val e3,member get_Current,[type 'c],[],[])]))
Looks like it fails on the task extensions?
So there is need for #if ?
I guess that's expected, tasks stuff doesn't translate to js, so there we'll need to enclose those functions in #if s.
For sure generic functions won't compile as well, I tried the fable compiler online and it fails to resolve complex overloading, which is also expected, as the overload resolution from F# is quite, quite obscure and complex.
Hi ! Can't get it from discussion does it supposed to work in Fable ? Trying to use FSharpx.Collections.Map.updateWith and got error error FABLE: Cannot resolve FSharpx.Collections.Map.updateWith some suggestions ?
I think you are in the wrong project. This is FSharpPlus not FSharpX :)
... and yes, we added Fable support although is not fully tested, apparently there are some issues. Feedback is welcome.
Sorry for this ! Both projects in my tabs opened so mistake here. Thanks for response !
Closing this as partial Fable support was included in F# 1.1
Most generic functions in this library don't have Fable support, since complex SRTP overload resolution is not yet possible in Fable.
We can re-open this issue or a different one by the time a new F# version allows to create better support in Fable.
Nuts, I wonder if there's a way to get lenses to work in Fable, or at least something similar...
Manipulating Elmish models is a perfect use case for lenses.
I think there is a way to get lenses to work in Fable, since they use a non-complex trait call.
Prisms should also be possible but for other optics I think we'll have to wait for F#5 and a new version of Fable supporting their new features.
Can you expand a bit more on the use case?
FYI using Myriad you can generate lenses that should be compatible with Fable I believe.
Yes, but those are very basic Data.Lenses
If you go to their PR I asked them to add proper Control.Lenses but everybody (including myself) was lazy to do the step 馃憤
Anyway, one thing is generate lenses and another to consume them.
I think the question is more about consuming them.
Myriad looks interesting.
I mostly just wanted lenses for a more comfortable way to manipulate models in a Fable/Elmish app -- so lots of nested records. That's also a case where simple types suffice for implementing lenses, so I ended up making my own pretty quickly:
type Lens<'a, 'b> =
{ Get: 'a -> 'b option
Set: 'b -> 'a -> 'a }
member l.Update f a =
match l.Get a with
| Some x -> l.Set (f x) a
| None -> a
let inline compose (l1: Lens<_, _>) (l2: Lens<_, _>) =
{ Get = fun a -> Option.bind l1.Get (l2.Get a)
Set = l1.Set >> l2.Update }
let inline (>>|) l1 l2 = compose l1 l2
let inline (<<|) l1 l2 = compose l2 l1
let setl (lens:Lens<'a, 'b>) = lens.Set
let getl (lens:Lens<'a, 'b>) = lens.Get
@reinux those are Data.Lenses as well.
This library use Control.Lenses which are functions, which you can compose directly, without needing to define a new operator for that.
Anyway, you can also consume Data.Lenses using the lens function which takes the getter and the setter as parameters.
I don't remember what was the issue with Fable, I will have a look.
Looks like I'm doing some progress: https://github.com/fsprojects/FSharpPlus/pull/337
Now I remember there was an issue with the tuple accessor lens, for some reason I still don't know they compile in Fable but fails when they are being used,
But the other basic lensing stuff seems to works fine. Let's see if we can merge that PR and do a release.
That would be awesome. Thanks!
I'm having fun refactoring my code to use my homebrew lenses 馃槃
What's the status on this? I tried both installing via nuget and paket and I still get The namespace 'Lens' is not defined.. Am I doing something wrong?
I did some progress until I faced these Fable limitations and as discussed there, it won't be fixed in Fable 2, because the coming Fable version 3 would handle it properly.
The good news is that Fable 3 was released as RC yesterday, so we started already integrating it hopefully soon we'll be able to use most parts of the library in Fable.
Most helpful comment
Sorry for this ! Both projects in my tabs opened so mistake here. Thanks for response !