Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 5e0acf9

Browse files
Readme
1 parent 2fe4d51 commit 5e0acf9

File tree

1 file changed

+83
-1
lines changed

1 file changed

+83
-1
lines changed

README.md

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,87 @@ This is why I tried to transpile F# to Php the same way Fable does to Javascript
1010

1111
Peeble use Fable transforms to parse F# files and create a simpler intermediate representation. It then convert this to a Php model before serializing it to text.
1212

13-
## Build it
1413

14+
## Quick start
15+
16+
You need first to get [dotnet cli installed](https://dotnet.microsoft.com/download).
17+
18+
The install peeble as a global dotnet tool:
19+
20+
dotnet tool install --global peeble-cli --version 0.1.0-alpha
21+
22+
Once done, you can call it on a fsproj to convert it to php:
23+
24+
peeble sample.fsproj --output sample.inc.php
25+
26+
If you don't specify the output, the result is printed to the console.
27+
28+
You can install it as a local tool if you prefere:
29+
30+
dotnet new tool-manifest
31+
dotnet tool install peeble-cli --version 0.1.0-alpha
32+
33+
You can the call it as a local tool:
34+
35+
dotnet peeble sample.fsproj --output sample.inc.php
36+
37+
The result is a inc.php file containing the code converted to Php.
38+
39+
As your code will make calls to FSharp.Core functions for standard operations on lists, maps and other system types, you need to include their implementation. Add an include on [FSharp.Core.php](./tree/master/src/FSharp.Core) that will reference other necessary files.
40+
41+
## Build
42+
43+
On windows, run :
44+
45+
./build.cmd
46+
47+
On linux:
48+
49+
./build.sh
50+
51+
## Interop
52+
53+
### Records
54+
55+
Records are compiled as Php classes with public fields. It implemnents equality by value.
56+
57+
### Unions
58+
59+
Unions are compiled as a base class and derived classes for each cases, the same way F# does in .Net.
60+
61+
### Options
62+
63+
Like in Fable, Option are implemented using Php NULL.
64+
65+
### Array
66+
67+
Peeble use Php Arrays to implement F# arrays. The Array module is called FSharpArray to avoid name clash.
68+
69+
### List
70+
71+
F# Lists are implemented in FSharpList as a linked list.
72+
73+
### Map/Set
74+
75+
Peeble comes with FSharp Map and Set implemented with in depth equality.
76+
77+
### Emit
78+
79+
To call function that have no been defined in F#, create a function with the expeced signature and mark it with the emit attribute to indicate the Php code to emit at the call site:
80+
81+
type Php =
82+
[<Emit("_($0)")>]
83+
static member translate s = s
84+
85+
[<Emit("sprintf(_($0),$1...)")>]
86+
static member translatef(fmt : string, [<ParamArray>]args : obj[]) = fmt
87+
88+
Here calling `Php.translate("Hello")` will generate:
89+
90+
_("Hello");
91+
92+
## Contributing
93+
94+
There are still many functions missing in the Php implementation of FSharp.Core functions. As you discover some functions missing, feel free to submit implementation.
95+
96+
If you find expressions that cannot be transpiled by Peeble, please report them an issue, with - if possible - a minimal example for the code that cannot compile and the expected result.

0 commit comments

Comments
 (0)