Skip to content

Commit c469a98

Browse files
committed
Fixes for compatibility
1 parent bc551cc commit c469a98

File tree

3 files changed

+88
-62
lines changed

3 files changed

+88
-62
lines changed

docs-src/dotnet/compatibility.md

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ Fable provides support for some classes of .NET BCL (Base Class Library) and mos
66

77
The following classes are translated to JS and most of their methods (static and instance) should be available in Fable.
88

9-
.NET | JavaScript
9+
.NET | Python
1010
--------------------------------------|----------------------------
11-
Numeric Types | number
12-
Arrays | Array / Typed Arrays
11+
Numeric Types | int
12+
Arrays | array / bytearray
1313
Events | fable-core/Event
14-
System.Boolean | boolean
15-
System.Char | string
16-
System.String | string
17-
System.Guid | string
18-
System.TimeSpan | number
19-
System.DateTime | Date
20-
System.DateTimeOffset | Date
14+
System.Boolean | bool
15+
System.Char | str
16+
System.String | str
17+
System.Guid | guid
18+
System.TimeSpan | timedelta
19+
System.DateTime | datetime
20+
System.DateTimeOffset | timedelta
2121
System.Timers.Timer | fable-core/Timer
22-
System.Collections.Generic.List | Array
22+
System.Collections.Generic.List | List
2323
System.Collections.Generic.HashSet | Set
24-
System.Collections.Generic.Dictionary | Map
25-
System.Text.RegularExpressions.Regex | RegExp
24+
System.Collections.Generic.Dictionary | dict
25+
System.Text.RegularExpressions.Regex | re
2626
System.Lazy | fable-core/Lazy
2727
System.Random | {}
28-
System.Math | (native JS functions)
28+
System.Math | math
2929

3030
The following static methods are also available:
3131

@@ -35,47 +35,58 @@ The following static methods are also available:
3535
- `System.Diagnostics.Debugger.Break()`
3636
- `System.Activator.CreateInstance<'T>()`
3737

38-
There is also support to convert between numeric types and to parse strings, check [the conversion tests](https://github.com/fable-compiler/Fable/blob/master/tests/Main/ConvertTests.fs).
38+
There is also support to convert between numeric types and to parse
39+
strings, check [the conversion
40+
tests](https://github.com/fable-compiler/Fable/blob/master/tests/Main/ConvertTests.fs).
3941

4042
### Caveats
4143

42-
- All numeric types become JS `number` (64-bit floating type), except for `int64`, `uint64`, `bigint` and `decimal`. Check the [Numeric Types](numbers.md) section to learn more about the differences between .NET and JS.
43-
- Numeric arrays are compiled to [Typed Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) when possible.
44+
- All numeric types become Python `int` (64-bit floating type), except for `decimal`. Check the [Numeric
45+
Types](numbers.md) section to learn more about the differences between .NET and Python.
46+
- Numeric arrays are compiled to [array](https://docs.python.org/3/library/array.html) when possible. Numeric arrays of
47+
`uint8` are compiled to [bytearray](https://docs.python.org/3/library/array.html#bytearrays) in order to support
48+
libraries that expect e.g `bytes` as input.
4449
- No bound checks for numeric types (unless you do explicit conversions like `byte 500`) nor for array indices.
45-
- `Regex` will always behave as if passed `RegexOptions.ECMAScript` flag (e.g., no negative look-behind or named groups).
4650

4751
## FSharp.Core
4852

49-
Most of FSharp.Core operators are supported, as well as formatting with `sprintf`, `printfn` or `failwithf` (`String.Format` is also available).
50-
The following types and/or corresponding modules from FSharp.Core lib will likewise translate to JS:
53+
Most of FSharp.Core operators are supported, as well as formatting with `sprintf`, `printfn` or `failwithf`
54+
(`String.Format` is also available). The following types and/or corresponding modules from FSharp.Core lib will likewise
55+
translate to JS:
5156

52-
.NET | JavaScript
57+
.NET | Python
5358
------------------|----------------------------------------------------------
54-
Tuples | Array
59+
Tuples | tuple
5560
Option | (erased)
5661
Choice | fable-core/Choice
5762
Result | fable-core/Result
5863
String | fable-core/String (module)
59-
Seq | [Iterable](http://babeljs.io/docs/learn-es2015/#iterators-for-of)
64+
Seq | [Iterable](ttps://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)
6065
List | fable-core/List
6166
Map | fable-core/Map
6267
Set | fable-core/Set
6368
Async | fable-core/Async
69+
Task | [Awaitable](https://docs.python.org/3/library/asyncio-task.html#awaitables)
6470
Event | fable-core/Event (module)
6571
Observable | fable-core/Observable (module)
66-
Arrays | Array / Typed Arrays
72+
Arrays | array / bytearray
6773
Events | fable-core/Event
6874
MailboxProcessor | fable-core/MailboxProcessor (limited support)
6975

7076
### Caveats II
7177

72-
- Options are **erased** in Python (`Some 5` becomes just `5` in Python and `None` translates to `null`). This is needed for example, to represent Python [optional properties](https://docs.python.org/3/library/typing.html#typing.Optional). However in a few cases (like nested options) there is an actual representation of the option in the runtime.
78+
- Options are **erased** in Python (`Some 5` becomes just `5` in Python and `None` translates to `None`). This is needed
79+
for example, to represent Python [optional properties](https://docs.python.org/3/library/typing.html#typing.Optional).
80+
However in a few cases (like nested options) there is an actual representation of the option in the runtime.
7381
- `Async.RunSynchronously` is not supported.
74-
- `MailboxProcessor` is single-threaded in Python and currently only `Start`, `Receive`, `Post` and `PostAndAsyncReply` are implemented (`cancellationToken` or `timeout` optional arguments are not supported).
82+
- `MailboxProcessor` is single-threaded in Python and currently only `Start`, `Receive`, `Post` and `PostAndAsyncReply`
83+
are implemented (`cancellationToken` or `timeout` optional arguments are not supported).
7584

7685
## Object Oriented Programming
7786

78-
Most of F# OOP features are compatible with Fable: interfaces and abstract classes, structs, inheritance, overloading, etc. However, please note that due to some limitations of [ES2015 classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) the generated code uses the [prototype chain](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain) instead. Also note that instance members are not attached to the prototype, which means they won't be accessible from native JS code. The exception to this rule are the implementations of **interface and abstract members**.
87+
Most of F# OOP features are compatible with Fable: interfaces and abstract classes, structs, inheritance, overloading,
88+
etc. However, please note that instance members are not attached to the prototype, which means they won't be accessible
89+
from native JS code. The exception to this rule are the implementations of **interface and abstract members**.
7990

8091
### Caveats III
8192

@@ -85,7 +96,8 @@ Most of F# OOP features are compatible with Fable: interfaces and abstract class
8596

8697
There is some reflection support in Fable, you can check the [reflection tests](https://github.com/fable-compiler/Fable/blob/master/tests/Main/ReflectionTests.fs) to see what is currently possible.
8798

88-
Generics are erased by default in the generated Python code. However, it is still possible to access generic information (like `typeof<'T>`) at runtime by marking functions with `inline`:
99+
Generics are erased by default in the generated Python code. However, it is still possible to access generic information
100+
(like `typeof<'T>`) at runtime by marking functions with `inline`:
89101

90102
```fsharp
91103
let doesNotCompileInFable(x: 'T) =

0 commit comments

Comments
 (0)