This repository was archived by the owner on Apr 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFSharp.Core.php
More file actions
120 lines (95 loc) · 2.23 KB
/
Copy pathFSharp.Core.php
File metadata and controls
120 lines (95 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
include "FSharpArray.php";
include "FSharpList.php";
include "Seq.php";
include "Set.php";
include "Map.php";
$equals = function ($x,$y) { return $x == $y; };
interface iComparable {
public function CompareTo($Other);
}
class Util {
static function equals($x,$y) {
if ( $x instanceof iComparable)
return $x->CompareTo($y) == 0;
return $x == $y; }
static function max($comparer, $x, $y) {
return $comparer($x,$y) >= 0 ? $x : $y;
}
static function min($comparer, $x, $y) {
return $comparer($x,$y) <= 0 ? $x : $y;
}
static function randomNext($min,$max)
{
return bga_rand ($min , $max );
}
static function comparePrimitives($x,$y)
{ return $x == $y ? 0 : ($x > $y ? 1 : -1); }
static function compareArrays ($x,$y) {
$i = 0;
$xl = count($x);
$yl = count($y);
while(true)
{
if ($i == $xl && $i == $yl)
return 0;
if ($i == $xl)
return -1;
if ($i == $yl)
return 1;
$c = Util::compare($x[$i],$y[$i]);
if ($c !== 0)
return $c;
$i++;
}
}
static function compare($x,$y)
{
if (is_array($x))
{
if (is_array($y))
return Util::compareArrays($x,$y);
else
return 1;
}
elseif ($x instanceof iComparable )
{
return $x->CompareTo($y);
}
{
if (is_array($y))
return -1;
else
return Util::comparePrimitives($x,$y);
}
}
}
interface Union {
public function get_Case();
}
interface FSharpUnion {
public function get_FSharpCase();
}
function void($x) {}
class Result {
}
class Ok extends Result {
public $ResultValue;
function __construct($value)
{
$this->ResultValue = $value;
}
}
class ResultError extends Result {
public $ErrorValue;
function __construct($value)
{
$this->ErrorValue = $value;
}
}
class Option {
static function defaultArg($opt, $val)
{
return is_null($opt) ? $val : $opt;
}
}