You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs-src/introduction/py-users-read-this.md
+13-10Lines changed: 13 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,21 +4,24 @@
4
4
5
5
Hi!
6
6
7
-
We're happy you decided to try Fable. Since F# is a language originally created for the .NET environment, Fable uses some tools that come from there.
7
+
We're happy you decided to try Fable. Since F# is a language originally created for the .NET environment, Fable uses
8
+
some tools that come from there.
8
9
9
-
Don't panic! There is enough documentation to explain how the .NET tools integrate in your environment. And there are basically only two things you need to know:
10
+
Don't panic! There is enough documentation to explain how the .NET tools integrate in your environment. And there are
11
+
basically only two things you need to know:
10
12
11
13
1. Fable uses F# project files (`.fsproj`) to list your F# code files and libraries.
12
-
2. Fable uses NuGet to load F# libraries, which is the equivalent of NPM for the .NET environment
14
+
2. Fable uses NuGet to load F# libraries, which is the equivalent of PyPI for the .NET environment
13
15
14
-
Voilà. Nothing else. We'll come to explanations later in the docs. But we promise, there's nothing you won't understand right away. Apart from these facts, it's all JavaScript!
16
+
Voilà. Nothing else. We'll come to explanations later in the docs. But we promise, there's nothing you won't understand
17
+
right away. Apart from these facts, it's all JavaScript!
15
18
16
19
**Welcome home!**
17
20
18
-
- Fable transpiles F# to ES2015 JavaScript, Fable uses the great [Babel](https://babeljs.io/) tool for that.
19
-
- Fable integrates with the popular [Webpack](https://webpack.js.org/). And it's not hard to use another bundler.
20
-
-JS Dependencies are listed in your common `package.json` file.
21
-
- Unit testing is available through [Fable.Mocha](https://github.com/Zaid-Ajaj/Fable.Mocha) (but you can use another test runner if you wish).
22
-
- In most cases, building and running a Fable project only requires to call `npm install` and `npm start`.
21
+
- Fable transpiles F# to Python 3.9.
22
+
% - Fable integrates with the popular [Webpack](https://webpack.js.org/). And it's not hard to use another bundler.
23
+
-Python Dependencies are listed in your common `pyproject.toml` file.
24
+
- Unit testing is available through [pytest](https://docs.pytest.org) (but you can use another test runner if you wish).
25
+
- In most cases, building and running a Fable project only requires to call `dotnet fable --lang py` and `poetry run python`.
23
26
24
-
So since we're mainly using JavaScript tools, you won't be lost with Fable!
27
+
So since we're using many of the well known Python tools, you won't be lost with Fable!
Copy file name to clipboardExpand all lines: docs-src/new-to-fsharp/learning-the-language.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,10 @@
1
1
# Learning the language
2
2
3
-
There are many resources available to learn F#. This section is only intended as a general guide targeted to JS developers, but is mainly contribution-driven and is still a work in progress. If you already know the basics of the language you can skip to [the next section](../2-steps/setup.html) or you can also check other sites and books about F# like:
3
+
There are many resources available to learn F#. This section is only intended as a
4
+
general guide targeted to Python developers, but is mainly contribution-driven and is still
5
+
a work in progress. If you already know the basics of the language you can skip to [the
6
+
next section](../2-steps/setup.html) or you can also check other sites and books about
7
+
F# like:
4
8
5
9
-[Tour of F#](https://docs.microsoft.com/en-us/dotnet/fsharp/tour)
6
10
-[F# for Fun and Profit](https://fsharpforfunandprofit.com/)
Copy file name to clipboardExpand all lines: docs-src/new-to-fsharp/let-keyword.md
+22-9Lines changed: 22 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,19 @@
1
1
# The let keyword
2
2
3
-
`let` is the F# keyword used to bind any value to a name, it's used to bind the so called primitive types such as a `string` or an `integer`, to bind to a function or more complex structures such as arrays or records.
3
+
`let` is the F# keyword used to bind any value to a name, it's used to bind the so called primitive types such as a
4
+
`string` or an `integer`, to bind to a function or more complex structures such as arrays or records.
4
5
5
6
Here's how you can bind a string to an identifier named `x`:
6
7
7
8
```fsharp
8
9
let x = "some text"
9
10
```
10
11
11
-
The above snippet would be considered a constant in some other languages such as JavaScript. In F# there's no `var` or `const` there's only `let` and since in F# every value is immutable by default, that snippet is the equivalent of a constant.
12
+
The above snippet would be considered a variable in some other languages such as Python. In F# there's no `var` or
13
+
`const` there's only `let` and since in F# every value is immutable by default, that snippet is the equivalent of a
14
+
constant.
12
15
13
-
Note that `let` in F# is different than `let` in JavaScript and this will be mentioned later on this page.
16
+
Note that `let` in F# is different than assignment in Python and this will be mentioned later on this page.
14
17
15
18
We're going to see more on functions later but here's how you can bind a function to an identifier named `add`:
16
19
@@ -19,11 +22,13 @@ let add x y =
19
22
x + y
20
23
```
21
24
22
-
In the above snippet a function that adds two integers is being bound to an identifier named `add` and then two values are being bound to the identifiers `x` and `y`.
25
+
In the above snippet a function that adds two integers is being bound to an identifier named `add` and then two values
26
+
are being bound to the identifiers `x` and `y`.
23
27
24
28
## Shadowing
25
29
26
-
In F#, bindings are immutable by default which means that normally one _can't_ reassign a value to a named binding, rather, if you try to do so using `let` what will happen is that you'll shadow an existing binding.
30
+
In F#, bindings are immutable by default which means that normally one _can't_ reassign a value to a named binding,
31
+
rather, if you try to do so using `let` what will happen is that you'll shadow an existing binding.
27
32
28
33
For instance, in the following example:
29
34
@@ -32,7 +37,9 @@ let x = "the answer"
32
37
let x = 42
33
38
```
34
39
35
-
In this case `x` is not being redefined nor its type is being changed from a `string` to an `int`, instead there are two different bindings with the same name `x` to different values. Of course, this example is not very useful because one binding is happening right after the other, but consider the following:
40
+
In this case `x` is not being redefined nor its type is being changed from a `string` to an `int`, instead there are two
41
+
different bindings with the same name `x` to different values. Of course, this example is not very useful because one
42
+
binding is happening right after the other, but consider the following:
36
43
37
44
```fsharp
38
45
let printName name =
@@ -47,14 +54,20 @@ let printName name =
47
54
printName "John Doe"
48
55
```
49
56
50
-
Don't worry too much if you don't fully grasp the above code, the main goal of that snippet is to demonstrate that the function `printName` expects an argument named `name` and in its body it defines another function `stripLastName` that also expects an argument `name`. Inside the scope of `stripLastName` the `name` argument is creating a new binding and thus shadowing the `name` argument received on the `printName` function. And that can be asserted by the two prints at the end of the `printName` function.
57
+
Don't worry too much if you don't fully grasp the above code, the main goal of that snippet is to demonstrate that the
58
+
function `printName` expects an argument named `name` and in its body it defines another function `stripLastName` that
59
+
also expects an argument `name`. Inside the scope of `stripLastName` the `name` argument is creating a new binding and
60
+
thus shadowing the `name` argument received on the `printName` function. And that can be asserted by the two prints at
61
+
the end of the `printName` function.
51
62
52
63
## Comparing with Python
53
64
54
65
The main differences that the `let` keyword in F# has from assignments in Python are:
55
66
56
-
- In Python one would use an assignment to define a named variable, and its value can be reassigned which is not the case in F#.
57
-
- In Python assignments are scope bound, so one can declare a new variable with an already used name as long as it is in a different scope, in F# that can be done within the same scope.
67
+
- In Python one would use an assignment to define a named variable, and its value can be reassigned which is not the
68
+
case in F#.
69
+
- In Python assignments are scope bound, so one can declare a new variable with an already used name as long as it is in
70
+
a different scope, in F# that can be done within the same scope.
Copy file name to clipboardExpand all lines: docs-src/your-fable-project/author-a-fable-library.md
+7-2Lines changed: 7 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,8 +18,13 @@ The last point may sound complicated but it's only a matter of adding a couple o
18
18
</ItemGroup>
19
19
```
20
20
21
-
That's all it takes to make your library compatible with Fable! In order to publish the package to Nuget check [the Microsoft documentation](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-the-dotnet-cli) or alternatively you can also [use Fake](https://fake.build/dotnet-nuget.html#Creating-NuGet-packages).
21
+
That's all it takes to make your library compatible with Fable! In order to publish the package to Nuget check [the
22
+
Microsoft
23
+
documentation](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-the-dotnet-cli) or
24
+
alternatively you can also [use Fake](https://fake.build/dotnet-nuget.html#Creating-NuGet-packages).
22
25
23
26
## Testing
24
27
25
-
It's a good idea to write unit tests for your library to make sure everything works as expected before publishing. The simplest way for that is to use a JS test runner like [Mocha](https://mochajs.org/), as in [this sample](https://github.com/fable-compiler/fable2-samples/tree/master/mocha). Or you can also use a library like [Fable.Mocha](https://github.com/Zaid-Ajaj/Fable.Mocha) containing more tools for Fable projects.
28
+
It's a good idea to write unit tests for your library to make sure everything works as expected before publishing. The
29
+
simplest way for that is to use a Python test runner like [pytest](https://pytest.org/), as in [this
0 commit comments