├── .gitignore
├── .nuget
└── packages.config
├── .travis.yml
├── FsControl.BaseLib
├── BitConverter.cs
├── FsControl.BaseLib.csproj
└── Properties
│ └── AssemblyInfo.cs
├── FsControl.Core
├── AssemblyInfo.fs
├── Collection.fs
├── Converter.fs
├── Foldable.fs
├── FsControl.Core.fsproj
├── FsControl.Core.nuspec
├── Functor.fs
├── Indexable.fs
├── Internals.fs
├── MonadTrans.fs
├── Monoid.fs
├── Numeric.fs
├── Operators.fs
├── Samples
│ ├── Collections.fsx
│ ├── Converter.fsx
│ ├── Functions.fsx
│ ├── Haskell.fsx
│ └── Numerics.fsx
├── Traversable.fs
└── Tuple.fs
├── FsControl.Test
├── App.config
├── FsControl.Test.fsproj
├── MSTest.runsettings
├── UnitTest.fs
└── packages.config
├── FsControl.sln
├── LICENSE.md
├── README.md
├── build.fsx
└── makefile.fsx
/.gitignore:
--------------------------------------------------------------------------------
1 | *.suo
2 | *.bak
3 | *.user
4 | *.cache
5 | */bin
6 | */obj
7 | _ReSharper.*
--------------------------------------------------------------------------------
/.nuget/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: objective-c
2 |
3 | env:
4 | global:
5 | - EnableNuGetPackageRestore=true
6 | matrix:
7 | - MONO_VERSION="4.2.1"
8 |
9 | before_install:
10 | - wget "http://download.mono-project.com/archive/${MONO_VERSION}/macos-10-x86/MonoFramework-MDK-${MONO_VERSION}.macos10.xamarin.x86.pkg"
11 | - sudo installer -pkg "MonoFramework-MDK-${MONO_VERSION}.macos10.xamarin.x86.pkg" -target /
12 | - mozroots --import --sync
13 |
14 | script:
15 | - ./build.fsx
--------------------------------------------------------------------------------
/FsControl.BaseLib/BitConverter.cs:
--------------------------------------------------------------------------------
1 | // ==++==
2 | //
3 | // Copyright (c) Microsoft Corporation. All rights reserved.
4 | //
5 | // ==--==
6 | /*============================================================
7 | **
8 | ** Class: BitConverter
9 | **
10 | **
11 | ** Purpose: Allows developers to view the base data types as
12 | ** an arbitrary array of bits.
13 | **
14 | **
15 | ===========================================================*/
16 | namespace FsControl.BaseLib
17 | {
18 |
19 | using System;
20 |
21 | // The BitConverter class contains methods for
22 | // converting an array of bytes to one of the base data
23 | // types, as well as for converting a base data type to an
24 | // array of bytes.
25 | //
26 | // Only statics, does not need to be marked with the serializable attribute
27 | public static class BitConverter
28 | {
29 |
30 | // This field indicates the "endianess" of the architecture.
31 | // The value is set to true if the architecture is
32 | // little endian; false if it is big endian.
33 | //#if BIGENDIAN
34 | // public static readonly bool IsLittleEndian /* = false */;
35 | //#else
36 | // public static readonly bool IsLittleEndian = true;
37 | //#endif
38 |
39 | // Converts a byte into an array of bytes with length one.
40 | public static byte[] GetBytes(bool value)
41 | {
42 | byte[] r = new byte[1];
43 | r[0] = (value ? (byte) 1 : (byte) 0);
44 | return r;
45 | }
46 |
47 | // Converts a char into an array of bytes with length two.
48 | public static byte[] GetBytes(char value, bool isLittleEndian)
49 | {
50 | return GetBytes((short)value, isLittleEndian);
51 | }
52 |
53 | // Converts a short into an array of bytes with length
54 | // two.
55 | public unsafe static byte[] GetBytes(short value, bool isLittleEndian)
56 | {
57 | if (!isLittleEndian) return new [] {(byte)(value >> 8), (byte)value};
58 | byte[] bytes = new byte[2];
59 | fixed (byte* b = bytes)
60 | *((short*)b) = value;
61 | return bytes;
62 | }
63 |
64 | // Converts an int into an array of bytes with length
65 | // four.
66 | public unsafe static byte[] GetBytes(int value, bool isLittleEndian)
67 | {
68 | if (!isLittleEndian) return new [] {(byte)(value >> 24), (byte)(value >> 16), (byte)(value >> 8), (byte)value};
69 | byte[] bytes = new byte[4];
70 | fixed (byte* b = bytes)
71 | *((int*)b) = value;
72 | return bytes;
73 | }
74 |
75 | // Converts a long into an array of bytes with length
76 | // eight.
77 | public unsafe static byte[] GetBytes(long value, bool isLittleEndian)
78 | {
79 | if (!isLittleEndian) return new [] {(byte)(value >> 56), (byte)(value >> 48), (byte)(value >> 40), (byte)(value >> 32), (byte)(value >> 24), (byte)(value >> 16), (byte)(value >> 8), (byte)value};
80 | byte[] bytes = new byte[8];
81 | fixed (byte* b = bytes)
82 | *((long*)b) = value;
83 | return bytes;
84 | }
85 |
86 | // Converts an ushort into an array of bytes with
87 | // length two.
88 | public static byte[] GetBytes(ushort value, bool isLittleEndian)
89 | {
90 | return GetBytes((short)value, isLittleEndian);
91 | }
92 |
93 | // Converts an uint into an array of bytes with
94 | // length four.
95 | public static byte[] GetBytes(uint value, bool isLittleEndian)
96 | {
97 | return GetBytes((int)value, isLittleEndian);
98 | }
99 |
100 | // Converts an unsigned long into an array of bytes with
101 | // length eight.
102 | public static byte[] GetBytes(ulong value, bool isLittleEndian)
103 | {
104 | return GetBytes((long)value, isLittleEndian);
105 | }
106 |
107 | // Converts a float into an array of bytes with length
108 | // four.
109 | public unsafe static byte[] GetBytes(float value, bool isLittleEndian)
110 | {
111 | return GetBytes(*(int*)&value, isLittleEndian);
112 | }
113 |
114 | // Converts a double into an array of bytes with length
115 | // eight.
116 | public unsafe static byte[] GetBytes(double value, bool isLittleEndian)
117 | {
118 | return GetBytes(*(long*)&value, isLittleEndian);
119 | }
120 |
121 | // Converts an array of bytes into a char.
122 | public static char ToChar(byte[] value, int startIndex, bool isLittleEndian)
123 | {
124 | return (char)ToInt16(value, startIndex, isLittleEndian);
125 | }
126 |
127 | // Converts an array of bytes into a short.
128 | public static unsafe short ToInt16(byte[] value, int startIndex, bool isLittleEndian)
129 | {
130 | if (value == null)
131 | throw new ArgumentNullException(nameof(value));
132 |
133 | if ((uint)startIndex >= value.Length)
134 | throw new ArgumentOutOfRangeException(nameof(startIndex), "ArgumentOutOfRange_Index");
135 |
136 | if (startIndex > value.Length - 2)
137 | throw new ArgumentException("Arg_ArrayPlusOffTooSmall");
138 |
139 | fixed (byte* pbyte = &value[startIndex])
140 | {
141 | if (isLittleEndian)
142 | {
143 | if (startIndex % 2 == 0) // data is aligned
144 | return *((short*)pbyte);
145 |
146 | return (short)((*pbyte) | (*(pbyte + 1) << 8));
147 | }
148 | return (short)((*pbyte << 8) | (*(pbyte + 1)));
149 | }
150 | }
151 |
152 | // Converts an array of bytes into an int.
153 | public static unsafe int ToInt32(byte[] value, int startIndex, bool isLittleEndian)
154 | {
155 | if (value == null)
156 | throw new ArgumentNullException(nameof(value));
157 |
158 | if ((uint)startIndex >= value.Length)
159 | throw new ArgumentOutOfRangeException(nameof(startIndex), "ArgumentOutOfRange_Index");
160 |
161 | if (startIndex > value.Length - 4)
162 | throw new ArgumentException("Arg_ArrayPlusOffTooSmall");
163 |
164 | fixed (byte* pbyte = &value[startIndex])
165 | {
166 | if (isLittleEndian)
167 | {
168 | if (startIndex % 4 == 0) // data is aligned
169 | return *((int*)pbyte);
170 |
171 | return (*pbyte) | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24);
172 | }
173 | return (*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | (*(pbyte + 3));
174 | }
175 | }
176 |
177 | // Converts an array of bytes into a long.
178 | public static unsafe long ToInt64(byte[] value, int startIndex, bool isLittleEndian)
179 | {
180 | if (value == null)
181 | throw new ArgumentNullException(nameof(value));
182 |
183 | if ((uint)startIndex >= value.Length)
184 | throw new ArgumentOutOfRangeException(nameof(startIndex), "ArgumentOutOfRange_Index");
185 |
186 | if (startIndex > value.Length - 8)
187 | throw new ArgumentException("Arg_ArrayPlusOffTooSmall");
188 |
189 | fixed (byte* pbyte = &value[startIndex])
190 | {
191 | if (isLittleEndian)
192 | {
193 | if (startIndex % 8 == 0) // data is aligned
194 | return *((long*)pbyte);
195 |
196 | int i1 = (*pbyte) | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24);
197 | int i2 = (*(pbyte + 4)) | (*(pbyte + 5) << 8) | (*(pbyte + 6) << 16) | (*(pbyte + 7) << 24);
198 | return (uint)i1 | ((long)i2 << 32);
199 | }
200 | else
201 | {
202 | int i1 = (*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | (*(pbyte + 3));
203 | int i2 = (*(pbyte + 4) << 24) | (*(pbyte + 5) << 16) | (*(pbyte + 6) << 8) | (*(pbyte + 7));
204 | return (uint)i2 | ((long)i1 << 32);
205 | }
206 | }
207 | }
208 |
209 |
210 | // Converts an array of bytes into an ushort.
211 | //
212 | public static ushort ToUInt16(byte[] value, int startIndex, bool isLittleEndian)
213 | {
214 | return (ushort)ToInt16(value, startIndex, isLittleEndian);
215 | }
216 |
217 | // Converts an array of bytes into an uint.
218 | //
219 | public static uint ToUInt32(byte[] value, int startIndex, bool isLittleEndian)
220 | {
221 | return (uint)ToInt32(value, startIndex, isLittleEndian);
222 | }
223 |
224 | // Converts an array of bytes into an unsigned long.
225 | //
226 | public static ulong ToUInt64(byte[] value, int startIndex, bool isLittleEndian)
227 | {
228 | return (ulong)ToInt64(value, startIndex, isLittleEndian);
229 | }
230 |
231 | // Converts an array of bytes into a float.
232 | unsafe public static float ToSingle(byte[] value, int startIndex, bool isLittleEndian)
233 | {
234 | int val = ToInt32(value, startIndex, isLittleEndian);
235 | return *(float*)&val;
236 | }
237 |
238 | // Converts an array of bytes into a double.
239 | unsafe public static double ToDouble(byte[] value, int startIndex, bool isLittleEndian)
240 | {
241 | long val = ToInt64(value, startIndex, isLittleEndian);
242 | return *(double*)&val;
243 | }
244 |
245 | private static char GetHexValue(int i)
246 | {
247 | System.Diagnostics.Debug.Assert(i >= 0 && i < 16, "i is out of range.");
248 | if (i < 10)
249 | {
250 | return (char)(i + '0');
251 | }
252 |
253 | return (char)(i - 10 + 'A');
254 | }
255 |
256 | // Converts an array of bytes into a String.
257 | public static String ToString(byte[] value, int startIndex, int length)
258 | {
259 |
260 | if (value == null)
261 | {
262 | throw new ArgumentNullException(nameof(value));
263 | }
264 |
265 | int arrayLen = value.Length;
266 | if (startIndex < 0 || (startIndex >= arrayLen && startIndex > 0))
267 | {
268 | throw new ArgumentOutOfRangeException(nameof(startIndex), "ArgumentOutOfRange_StartIndex");
269 | }
270 |
271 | int realLength = length;
272 | if (realLength < 0)
273 | {
274 | throw new ArgumentOutOfRangeException(nameof(length), "ArgumentOutOfRange_GenericPositive");
275 | }
276 |
277 | if (startIndex > arrayLen - realLength)
278 | {
279 | throw new ArgumentException("Arg_ArrayPlusOffTooSmall");
280 | }
281 |
282 | if (realLength == 0)
283 | {
284 | return string.Empty;
285 | }
286 |
287 | char[] chArray = new char[realLength * 3];
288 | int i = 0;
289 | int index = startIndex;
290 | for (i = 0; i < realLength * 3; i += 3)
291 | {
292 | byte b = value[index++];
293 | chArray[i] = GetHexValue(b / 16);
294 | chArray[i + 1] = GetHexValue(b % 16);
295 | chArray[i + 2] = '-';
296 | }
297 |
298 | // We don't need the last '-' character
299 | return new String(chArray, 0, chArray.Length - 1);
300 | }
301 |
302 | // Converts an array of bytes into a String.
303 | public static String ToString(byte[] value)
304 | {
305 | if (value == null)
306 | throw new ArgumentNullException(nameof(value));
307 | return ToString(value, 0, value.Length);
308 | }
309 |
310 | // Converts an array of bytes into a String.
311 | public static String ToString(byte[] value, int startIndex)
312 | {
313 | if (value == null)
314 | throw new ArgumentNullException(nameof(value));
315 | return ToString(value, startIndex, value.Length - startIndex);
316 | }
317 |
318 | /*==================================ToBoolean===================================
319 | **Action: Convert an array of bytes to a boolean value. We treat this array
320 | ** as if the first 4 bytes were an Int4 an operate on this value.
321 | **Returns: True if the Int4 value of the first 4 bytes is non-zero.
322 | **Arguments: value -- The byte array
323 | ** startIndex -- The position within the array.
324 | **Exceptions: See ToInt4.
325 | ==============================================================================*/
326 | // Converts an array of bytes into a boolean.
327 | public static bool ToBoolean(byte[] value, int startIndex)
328 | {
329 | if (value == null)
330 | throw new ArgumentNullException(nameof(value));
331 | if (startIndex < 0)
332 | throw new ArgumentOutOfRangeException(nameof(startIndex), "ArgumentOutOfRange_NeedNonNegNum");
333 | if (startIndex > value.Length - 1)
334 | throw new ArgumentOutOfRangeException(nameof(startIndex), "ArgumentOutOfRange_Index");
335 |
336 | return value[startIndex] != 0;
337 | }
338 |
339 | public static unsafe long DoubleToInt64Bits(double value)
340 | {
341 | return *((long*)&value);
342 | }
343 |
344 | public static unsafe double Int64BitsToDouble(long value)
345 | {
346 | return *((double*)&value);
347 | }
348 | }
349 |
350 |
351 | }
--------------------------------------------------------------------------------
/FsControl.BaseLib/FsControl.BaseLib.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {1B99DF98-65AC-4038-8BE5-E72B0882F420}
8 | Library
9 | Properties
10 | FsControl.BaseLib
11 | FsControl.BaseLib
12 | v4.0
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 | true
25 |
26 |
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 | true
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
56 |
57 |
--------------------------------------------------------------------------------
/FsControl.BaseLib/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("FsControl.BaseLib")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("FsControl.BaseLib")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("b1e53245-cee2-49e1-afda-50975cc29c69")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/FsControl.Core/AssemblyInfo.fs:
--------------------------------------------------------------------------------
1 | module FsControl.AssemblyInfo
2 |
3 | open System.Reflection
4 |
5 | []
6 | []
7 |
8 | []
9 | []
10 | []
11 | []
12 | []
13 | []
14 |
15 | []
16 | []
17 | []
18 | do()
--------------------------------------------------------------------------------
/FsControl.Core/Collection.fs:
--------------------------------------------------------------------------------
1 | #nowarn "77"
2 | // Warn FS0077 -> Member constraints with the name 'get_Item' are given special status by the F# compiler as certain .NET types are implicitly augmented with this member. This may result in runtime failures if you attempt to invoke the member constraint from your own code.
3 | // Those .NET types are string and array but they are explicitely handled here.
4 |
5 | namespace FsControl
6 |
7 | open System
8 | open System.Text
9 | open System.Runtime.CompilerServices
10 | open System.Runtime.InteropServices
11 | open FsControl.Internals
12 |
13 |
14 | []
15 | type Nth =
16 | inherit Default1
17 | []static member inline Nth (x:'Foldable'T , n, []impl:Default1) = x |> ToSeq.Invoke |> Seq.skip n |> Seq.head :'T
18 | []static member Nth (x:string , n, []impl:Nth ) = x.[n]
19 | []static member Nth (x:StringBuilder , n, []impl:Nth ) = x.ToString().[n]
20 | []static member Nth (x:'a [] , n, []impl:Nth ) = x.[n] : 'a
21 | []static member Nth (x:'a ResizeArray, n, []impl:Nth ) = x.[n]
22 | []static member Nth (x:list<'a> , n, []impl:Nth ) = x.[n]
23 | []static member Nth (x:'a Id , n, []impl:Nth ) = x.getValue
24 |
25 | static member inline Invoke (n:int) (source:'Collection'T) :'T =
26 | let inline call_2 (a:^a, b:^b, n) = ((^a or ^b) : (static member Nth: _*_*_ -> _) b, n, a)
27 | let inline call (a:'a, b:'b, n) = call_2 (a, b, n)
28 | call (Unchecked.defaultof, source, n)
29 |
30 | []
31 | type Skip =
32 | inherit Default1
33 | []static member inline Skip (x:'Foldable'T , n, []impl:Default1) = x |> ToSeq.Invoke |> Seq.skip n |> OfSeq.Invoke :'Foldable'T
34 | []static member Skip (x:string , n, []impl:Skip ) = x.[n..]
35 | []static member Skip (x:StringBuilder , n, []impl:Skip ) = new StringBuilder(x.ToString().[n..])
36 | []static member Skip (x:'a [] , n, []impl:Skip ) = x.[n..] : 'a []
37 | []static member Skip (x:'a ResizeArray, n, []impl:Skip ) = ResizeArray<'a> (Seq.skip n x)
38 | []static member Skip (x:list<'a> , n, []impl:Skip ) = n |> let rec listSkip lst = function 0 -> lst | n -> listSkip (List.tail lst) (n-1) in listSkip x
39 | []static member Skip (x:'a Id , n, []impl:Skip ) = x
40 |
41 | static member inline Invoke (n:int) (source:'Collection'T) :'Collection'T =
42 | let inline call_2 (a:^a, b:^b, n) = ((^a or ^b) : (static member Skip: _*_*_ -> _) b, n, a)
43 | let inline call (a:'a, b:'b, n) = call_2 (a, b, n)
44 | call (Unchecked.defaultof, source, n)
45 |
46 |
47 | []
48 | type Take =
49 | inherit Default1
50 | []static member inline Take (x:'Foldable'T , n, []impl:Default1) = x |> ToSeq.Invoke |> Seq.take n |> OfSeq.Invoke :'Foldable'T
51 | []static member Take (x:string , n, []impl:Take ) = x.[..n-1]
52 | []static member Take (x:StringBuilder , n, []impl:Take ) = new StringBuilder(x.ToString().[..n-1])
53 | []static member Take (x:'a [] , n, []impl:Take ) = x.[..n-1] : 'a []
54 | []static member Take (x:'a ResizeArray, n, []impl:Take ) = ResizeArray<'a> (Seq.take n x)
55 | []static member Take (x:list<'a> , n, []impl:Take ) = Seq.take n x |> Seq.toList
56 | []static member Take (x:'a Id , n, []impl:Take ) = x
57 |
58 | static member inline Invoke (n:int) (source:'Collection'T) :'Collection'T =
59 | let inline call_2 (a:^a, b:^b, n) = ((^a or ^b) : (static member Take: _*_*_ -> _) b, n, a)
60 | let inline call (a:'a, b:'b, n) = call_2 (a, b, n)
61 | call (Unchecked.defaultof, source, n)
62 |
63 |
64 | []
65 | type Drop =
66 | inherit Default1
67 | []static member inline Drop (x:'Foldable'T , n, []impl:Default1) = x |> ToSeq.Invoke |> Seq.drop n |> OfSeq.Invoke :'Foldable'T
68 | []static member Drop (x:string , n, []impl:Drop) = if n > 0 then (if x.Length > n then x.[n..] else "") else x
69 | []static member Drop (x:StringBuilder , n, []impl:Drop) = if n > 0 then (if x.Length > n then new StringBuilder(x.ToString().[n..]) else new StringBuilder()) else new StringBuilder(x.ToString())
70 | []static member Drop (x:'a [] , n, []impl:Drop) = if n > 0 then (if x.Length > n then x.[n..] else [||]) else x : 'a []
71 | []static member Drop (x:'a ResizeArray, n, []impl:Drop) = ResizeArray<'a> (Seq.drop n x)
72 | []static member Drop (x:list<'a> , n, []impl:Drop) = List.drop n x
73 | []static member Drop (x:'a Id , n, []impl:Drop) = x
74 |
75 | static member inline Invoke (n:int) (source:'Collection'T) :'Collection'T =
76 | let inline call_2 (a:^a, b:^b, n) = ((^a or ^b) : (static member Drop: _*_*_ -> _) b, n, a)
77 | let inline call (a:'a, b:'b, n) = call_2 (a, b, n)
78 | call (Unchecked.defaultof, source, n)
79 |
80 |
81 |
82 | []
83 | type Limit =
84 | inherit Default1
85 | []static member inline Limit (x:'Foldable'T , n, []impl:Default1) = x |> ToSeq.Invoke |> Seq.truncate n |> OfSeq.Invoke :'Foldable'T
86 | []static member Limit (x:string , n, []impl:Limit) = if n < 1 then "" elif n < x.Length then x.[..n-1] else x
87 | []static member Limit (x:StringBuilder , n, []impl:Limit) = new StringBuilder(x.ToString().[..n-1])
88 | []static member Limit (x:'a [] , n, []impl:Limit) = if n < 1 then [||] elif n < x.Length then x.[..n-1] else x : 'a []
89 | []static member Limit (x:'a ResizeArray, n, []impl:Limit) = ResizeArray<'a> (Seq.truncate n x)
90 | []static member Limit (x:list<'a> , n, []impl:Limit) = Seq.truncate n x |> Seq.toList
91 | []static member Limit (x:'a Id , n, []impl:Limit) = x
92 |
93 | static member inline Invoke (n:int) (source:'Collection'T) :'Collection'T =
94 | let inline call_2 (a:^a, b:^b, n) = ((^a or ^b) : (static member Limit: _*_*_ -> _) b, n, a)
95 | let inline call (a:'a, b:'b, n) = call_2 (a, b, n)
96 | call (Unchecked.defaultof, source, n)
97 |
98 |
99 |
100 | type Choose =
101 | static member Choose (x:Id<'T> , f:_->'U option, []impl:Choose) = invalidOp "Choose on ID" :Id<'U>
102 | static member Choose (x:seq<'T> , f:_->'U option, []impl:Choose) = Seq.choose f x
103 | static member Choose (x:list<'T>, f:_->'U option, []impl:Choose) = List.choose f x
104 | static member Choose (x:'T [] , f:_->'U option, []impl:Choose) = Array.choose f x
105 |
106 | static member inline Invoke (chooser:'T->'U option) (source:'Collection'T) =
107 | let inline call_3 (a:^a, b:^b, c:^c, f) = ((^a or ^b or ^c) : (static member Choose: _*_*_ -> _) b, f, a)
108 | let inline call (a:'a, b:'b, c) = call_3 (a, b, Unchecked.defaultof<'r>, c) :'r
109 | call (Unchecked.defaultof, source, chooser) :'Collection'U
110 |
111 |
112 | []
113 | type Distinct =
114 | inherit Default1
115 | []static member inline Distinct (x:'Foldable'T, []impl:Default1) = x |> ToSeq.Invoke |> Seq.distinct |> OfSeq.Invoke :'Foldable'T
116 | []static member Distinct (x:list<'T> , []impl:Distinct) = Seq.distinct x |> Seq.toList
117 | []static member Distinct (x:'T [] , []impl:Distinct) = Seq.distinct x |> Seq.toArray
118 |
119 | static member inline Invoke (source:'Collection'T) =
120 | let inline call_2 (a:^a, b:^b) = ((^a or ^b) : (static member Distinct: _*_ -> _) b, a)
121 | let inline call (a:'a, b:'b) = call_2 (a, b)
122 | call (Unchecked.defaultof, source) :'Collection'T
123 |
124 |
125 | type DistinctBy =
126 | inherit Default1
127 | static member inline DistinctBy (x:'Foldable'T, f, []impl:Default1 ) = x |> ToSeq.Invoke |> Seq.distinctBy f |> OfSeq.Invoke :'Foldable'T
128 | static member DistinctBy (x:list<'T> , f, []impl:DistinctBy) = Seq.distinctBy f x |> Seq.toList
129 | static member DistinctBy (x:'T [] , f, []impl:DistinctBy) = Seq.distinctBy f x |> Seq.toArray
130 |
131 | static member inline Invoke (projection:'T->'Key) (source:'Collection'T) =
132 | let inline call_2 (a:^a, b:^b, p) = ((^a or ^b) : (static member DistinctBy: _*_*_ -> _) b, p, a)
133 | let inline call (a:'a, b:'b, p) = call_2 (a, b, p)
134 | call (Unchecked.defaultof, source, projection) :'Collection'T
135 |
136 |
137 | type GroupBy =
138 | static member GroupBy (x:Id<'T> , f:'T->'Key, _:Id<'Key*Id<'T>> , []impl:GroupBy) = let a = Id.run x in Id.create (f a, x)
139 | static member GroupBy (x:seq<'T> , f:'T->'Key, _:seq<'Key*seq<'T>> , []impl:GroupBy) = Seq.groupBy f x
140 | static member GroupBy (x:list<'T>, f:'T->'Key, _:list<'Key*list<'T>>, []impl:GroupBy) = Seq.groupBy f x |> Seq.map (fun (x,y) -> x, Seq.toList y) |> Seq.toList
141 | static member GroupBy (x:'T [] , f:'T->'Key, _:('Key*('T [])) [] , []impl:GroupBy) = Seq.groupBy f x |> Seq.map (fun (x,y) -> x, Seq.toArray y) |> Seq.toArray
142 |
143 | static member inline Invoke (projection:'T->'Key) (source:'Collection'T) : 'Collection'KeyX'Collection'T =
144 | let inline call_3 (a:^a, b:^b, c:^c, p) = ((^a or ^b or ^c) : (static member GroupBy: _*_*_*_ -> _) b, p, c, a)
145 | let inline call (a:'a, b:'b, p) = call_3 (a, b, Unchecked.defaultof<'r>, p) :'r
146 | call (Unchecked.defaultof, source, projection)
147 |
148 |
149 | type ChunkBy =
150 | static member ChunkBy (x:Id<'T> , f:'T->'Key, _:Id<'Key*Id<'T>> , []impl:ChunkBy) = let a = Id.run x in Id.create (f a, x)
151 | static member ChunkBy (x:seq<'T> , f:'T->'Key, _:seq<'Key*seq<'T>> , []impl:ChunkBy) = Seq.chunkBy f x |> Seq.map (fun (x,y) -> x, y :> _ seq)
152 | static member ChunkBy (x:list<'T>, f:'T->'Key, _:list<'Key*list<'T>>, []impl:ChunkBy) = Seq.chunkBy f x |> Seq.map (fun (x,y) -> x, Seq.toList y) |> Seq.toList
153 | static member ChunkBy (x:'T [] , f:'T->'Key, _:('Key*('T [])) [] , []impl:ChunkBy) = Seq.chunkBy f x |> Seq.map (fun (x,y) -> x, Seq.toArray y) |> Seq.toArray
154 |
155 | static member inline Invoke (projection:'T->'Key) (source:'Collection'T) : 'Collection'KeyX'Collection'T =
156 | let inline call_3 (a:^a, b:^b, c:^c, p) = ((^a or ^b or ^c) : (static member ChunkBy: _*_*_*_ -> _) b, p, c, a)
157 | let inline call (a:'a, b:'b, p) = call_3 (a, b, Unchecked.defaultof<'r>, p) :'r
158 | call (Unchecked.defaultof, source, projection)
159 |
160 |
161 | []
162 | type Length =
163 | inherit Default1
164 | []static member inline Length (x:'Foldable'T, []impl:Default1) = x |> ToSeq.Invoke |> Seq.length
165 | []static member Length (x:Id<'T> , []impl:Length) = 1
166 | []static member Length (x:seq<'T> , []impl:Length) = Seq.length x
167 | []static member Length (x:list<'T>, []impl:Length) = List.length x
168 | []static member Length (x:'T [] , []impl:Length) = Array.length x
169 |
170 | static member inline Invoke (source:'Collection'T) =
171 | let inline call_2 (a:^a, b:^b) = ((^a or ^b) : (static member Length: _*_ -> _) b, a)
172 | let inline call (a:'a, b:'b) = call_2 (a, b)
173 | call (Unchecked.defaultof, source) :int
174 |
175 |
176 |
177 | []
178 | type Max =
179 | inherit Default1
180 | []static member inline Max (x:'Foldable'T, []impl:Default1) = x |> ToSeq.Invoke |> Seq.max :'T
181 | []static member Max (x:Id<'T> , []impl:Max) = x.getValue
182 | []static member Max (x:seq<'T> , []impl:Max) = Seq.max x
183 | []static member Max (x:list<'T>, []impl:Max) = List.max x
184 | []static member Max (x:'T [] , []impl:Max) = Array.max x
185 |
186 | static member inline Invoke (source:'Collection'T) =
187 | let inline call_2 (a:^a, b:^b) = ((^a or ^b) : (static member Max: _*_ -> _) b, a)
188 | let inline call (a:'a, b:'b) = call_2 (a, b)
189 | call (Unchecked.defaultof, source) :'T
190 |
191 |
192 | type MaxBy =
193 | inherit Default1
194 | static member inline MaxBy (x:'Foldable'T, f, []impl:Default1) = x |> ToSeq.Invoke |> Seq.maxBy f :'T
195 | static member MaxBy (x:Id<'T> , f:'T->'U, []impl:MaxBy) = x.getValue
196 | static member MaxBy (x:seq<'T> , f , []impl:MaxBy) = Seq.maxBy f x
197 | static member MaxBy (x:list<'T>, f , []impl:MaxBy) = List.maxBy f x
198 | static member MaxBy (x:'T [] , f , []impl:MaxBy) = Array.maxBy f x
199 |
200 | static member inline Invoke (projection:'T->'U) (source:'Collection'T) =
201 | let inline call_2 (a:^a, b:^b, f) = ((^a or ^b) : (static member MaxBy: _*_*_ -> _) b, f, a)
202 | let inline call (a:'a, b:'b, f) = call_2 (a, b, f)
203 | call (Unchecked.defaultof, source, projection) :'T
204 |
205 |
206 | []
207 | type Min =
208 | inherit Default1
209 | []static member inline Min (x:'Foldable'T, []impl:Default1) = x |> ToSeq.Invoke |> Seq.min :'T
210 | []static member Min (x:Id<'T> , []impl:Min) = x.getValue
211 | []static member Min (x:seq<'T> , []impl:Min) = Seq.min x
212 | []static member Min (x:list<'T>, []impl:Min) = List.min x
213 | []static member Min (x:'T [] , []impl:Min) = Array.min x
214 |
215 | static member inline Invoke (source:'Collection'T) =
216 | let inline call_2 (a:^a, b:^b) = ((^a or ^b) : (static member Min: _*_ -> _) b, a)
217 | let inline call (a:'a, b:'b) = call_2 (a, b)
218 | call (Unchecked.defaultof, source) :'T
219 |
220 |
221 | type MinBy =
222 | inherit Default1
223 | static member inline MinBy (x:'Foldable'T, f, []impl:Default1) = x |> ToSeq.Invoke |> Seq.minBy f :'T
224 | static member MinBy (x:Id<'T> , f:'T->'U, []impl:MinBy) = x.getValue
225 | static member MinBy (x:seq<'T> , f , []impl:MinBy) = Seq.minBy f x
226 | static member MinBy (x:list<'T>, f , []impl:MinBy) = List.minBy f x
227 | static member MinBy (x:'T [] , f , []impl:MinBy) = Array.minBy f x
228 |
229 | static member inline Invoke (projection:'T->'U) (source:'Collection'T) =
230 | let inline call_2 (a:^a, b:^b, f) = ((^a or ^b) : (static member MinBy: _*_*_ -> _) b, f, a)
231 | let inline call (a:'a, b:'b, f) = call_2 (a, b, f)
232 | call (Unchecked.defaultof, source, projection) :'T
233 |
234 |
235 | []
236 | type Replace =
237 | inherit Default1
238 | static member inline Replace (x:'Collection , o:'Collection , n:'Collection , []impl:Default1) = x |> ToSeq.Invoke |> Seq.replace (ToSeq.Invoke o) (ToSeq.Invoke n) |> OfSeq.Invoke : 'Collection
239 | static member Replace (x:Id<'T> , o:Id<'T> , n:Id<'T> , []impl:Default1) = if x = o then n else x
240 | []static member Replace (x:list<'T> , o:list<'T> , n:list<'T> , []impl:Replace ) = x |> List.toSeq |> Seq.replace o n |> Seq.toList
241 | []static member Replace (x:'T [] , o:'T [] , n:'T [] , []impl:Replace ) = x |> Array.toSeq |> Seq.replace o n |> Seq.toArray
242 | []static member Replace (x:string , o:string , n:string , []impl:Replace ) = if o.Length = 0 then x else x.Replace(o, n)
243 | []static member Replace (x:StringBuilder, o:StringBuilder, n:StringBuilder, []impl:Replace ) = if o.Length = 0 then x else StringBuilder(x.ToString().Replace(o.ToString(), n.ToString()))
244 |
245 | static member inline Invoke (o:'Collection) (n:'Collection) (source:'Collection) =
246 | let inline call_2 (a:^a, b:^b) = ((^a or ^b) : (static member Replace: _*_*_*_ -> _) b, o, n, a)
247 | let inline call (a:'a, b:'b) = call_2 (a, b)
248 | call (Unchecked.defaultof, source) :'Collection
249 |
250 |
251 | []
252 | type Rev =
253 | inherit Default1
254 | []static member inline Rev (x:'Foldable'T, []impl:Default1) = x |> ToSeq.Invoke |> Seq.toArray |> Array.rev |> Array.toSeq |> OfSeq.Invoke :'Foldable'T
255 | []static member Rev (x:list<'a> , []impl:Rev ) = List.rev x
256 | []static member Rev (x:'a [] , []impl:Rev ) = Array.rev x
257 |
258 | static member inline Invoke (source:'Collection'T) =
259 | let inline call_2 (a:^a, b:^b) = ((^a or ^b) : (static member Rev: _*_ -> _) b, a)
260 | let inline call (a:'a, b:'b) = call_2 (a, b)
261 | call (Unchecked.defaultof, source) :'Collection'T
262 |
263 |
264 | type Scan =
265 | static member Scan (x:Id<'T> , f ,z:'S, []output:Id<'S> , []impl:Scan) = Id.create (f z x.getValue)
266 | static member Scan (x:seq<'T> , f ,z:'S, []output:seq<'S> , []impl:Scan) = Seq.scan f z x
267 | static member Scan (x:list<'T>, f ,z:'S, []output:list<'S>, []impl:Scan) = List.scan f z x
268 | static member Scan (x:'T [] , f ,z:'S, []output:'S [] , []impl:Scan) = Array.scan f z x
269 |
270 | static member inline Invoke (folder:'State'->'T->'State) (state:'State) (source:'Collection'T) =
271 | let inline call_3 (a:^a, b:^b, c:^c, f, z) = ((^a or ^b or ^c) : (static member Scan: _*_*_*_*_ -> _) b, f, z, c, a)
272 | let inline call (a:'a, b:'b, f, z) = call_3 (a, b, Unchecked.defaultof<'r>, f, z) :'r
273 | call (Unchecked.defaultof, source, folder, state) :'Collection'State
274 |
275 |
276 | []
277 | type Sort =
278 | inherit Default1
279 | []static member inline Sort (x:'Foldable'T, []impl:Default2) = x |> ToSeq.Invoke |> Seq.sort |> OfSeq.Invoke :'Foldable'T
280 | []static member inline Sort (x:^Foldable'T, []impl:Default1) = ((^Foldable'T) : (static member Sort: _->_) x) : ^Foldable'T
281 | []static member Sort (x:list<'a> , []impl:Sort ) = List.sort x
282 | []static member Sort (x:'a [] , []impl:Sort ) = Array.sort x
283 |
284 | static member inline Invoke (source:'Collection'T) =
285 | let inline call_2 (a:^a, b:^b) = ((^a or ^b) : (static member Sort: _*_ -> _) b, a)
286 | let inline call (a:'a, b:'b) = call_2 (a, b)
287 | call (Unchecked.defaultof, source) :'Collection'T
288 |
289 |
290 | type SortBy =
291 | inherit Default1
292 |
293 | static member SortBy (x:list<'a> , f , []impl:SortBy ) = List.sortBy f x
294 | static member SortBy (x:'a [] , f , []impl:SortBy ) = Array.sortBy f x
295 |
296 | static member inline Invoke (projection:'T->'Key) (source:'Collection'T) : 'Collection'T =
297 | let inline call_2 (a:^a, b:^b, f) = ((^a or ^b) : (static member SortBy: _*_*_ -> _) b, f, a)
298 | let inline call (a:'a, b:'b, f) = call_2 (a, b, f)
299 | call (Unchecked.defaultof, source, projection)
300 | static member inline InvokeOnInstance (projection:'T->'Key) (source:'Collection'T) : 'Collection'T = (^Collection'T : (static member SortBy: _*_->_) projection, source) : ^Collection'T
301 |
302 | static member inline SortBy (x:'Foldable'T, f , []impl:Default2) = x |> ToSeq.Invoke |> Seq.sortBy f |> OfSeq.Invoke :'Foldable'T
303 | static member inline SortBy (x:^Foldable'T, f , []impl:Default1) = ((^Foldable'T) : (static member SortBy: _*_->_) f, x) : ^Foldable'T
304 | static member inline SortBy (_ : ^t when ^t : null and ^t : struct, f : 'T -> 'U, mthd : Default1) = id
305 |
306 |
307 | []
308 | type Split =
309 | inherit Default1
310 | []static member Split (x:seq<'T> , e:seq> , []impl:Split) = x |> Seq.split StringSplitOptions.None e
311 | []static member Split (x:list<'T> , e:seq> , []impl:Split) = x |> List.toSeq |> Seq.split StringSplitOptions.None e |> Seq.map Seq.toList
312 | []static member Split (x:'T [] , e:seq<'T []> , []impl:Split) = x |> Array.toSeq |> Seq.split StringSplitOptions.None e |> Seq.map Seq.toArray
313 | []static member Split (x:string , e:seq , []impl:Split) = x.Split(Seq.toArray e, StringSplitOptions.None) :> seq<_>
314 | []static member Split (x:StringBuilder, e:seq, []impl:Split) = x.ToString().Split(e |> Seq.map (fun x -> x.ToString()) |> Seq.toArray, StringSplitOptions.None) |> Array.map StringBuilder :> seq<_>
315 |
316 | static member inline Invoke (sep:seq<'Collection>) (source:'Collection) =
317 | let inline call_2 (a:^a, b:^b, s) = ((^a or ^b) : (static member Split: _*_*_ -> _) b, s, a)
318 | let inline call (a:'a, b:'b, s) = call_2 (a, b, s)
319 | call (Unchecked.defaultof, source,sep) :seq<'Collection>
320 |
321 |
322 | []
323 | type Unzip =
324 | []static member Unzip (source:seq<'T * 'U> , []output:seq<'T> * seq<'U> , []impl:Unzip) = Seq.map fst source, Seq.map snd source
325 | []static member Unzip (source:list<'T * 'U>, []output:list<'T> * list<'U>, []impl:Unzip) = List.unzip source
326 | []static member Unzip (source:('T * 'U) [] , []output:'T [] * 'U [] , []impl:Unzip) = Array.unzip source
327 |
328 | static member inline Invoke (source:'``Collection<'T1 * 'T2>``) =
329 | let inline call_3 (a:^a, b:^b, d:^d) = ((^a or ^b or ^d) : (static member Unzip: _*_*_ -> _) b, d, a)
330 | let inline call (a:'a, b:'b) = call_3 (a, b, Unchecked.defaultof<'r>) :'r
331 | call (Unchecked.defaultof, source) :'``Collection<'T1>`` * '``Collection<'T2>``
332 |
333 |
334 | []
335 | type Zip =
336 | []static member Zip (x:Id<'T> , y:Id<'U> , []output:Id<'T*'U> , []impl:Zip) = Id.create(x.getValue,y.getValue)
337 | []static member Zip (x:seq<'T> , y:seq<'U> , []output:seq<'T*'U> , []impl:Zip) = Seq.zip x y
338 | []static member Zip (x:list<'T>, y:list<'U>, []output:list<'T*'U>, []impl:Zip) = List.zip x y
339 | []static member Zip (x:'T [] , y:'U [] , []output:('T*'U) [] , []impl:Zip) = Array.zip x y
340 |
341 | static member inline Invoke (source1:'Collection'T1) (source2:'Collection'T2) =
342 | let inline call_4 (a:^a, b:^b, c:^c, d:^d) = ((^a or ^b or ^c or ^d) : (static member Zip: _*_*_*_ -> _) b, c, d, a)
343 | let inline call (a:'a, b:'b, c:'c) = call_4 (a, b, c, Unchecked.defaultof<'r>) :'r
344 | call (Unchecked.defaultof, source1, source2) :'Collection'T1'T2
--------------------------------------------------------------------------------
/FsControl.Core/Converter.fs:
--------------------------------------------------------------------------------
1 | #nowarn "77"
2 | // Warn FS0077 -> Member constraints with the name 'op_Explicit' are given special status by the F# compiler as certain .NET types are implicitly augmented with this member. This may result in runtime failures if you attempt to invoke the member constraint from your own code.
3 | // But all simulated types are being handled so here Explicit is SAFE from runtime errors.
4 |
5 | namespace FsControl
6 |
7 | open System
8 | open System.Runtime.CompilerServices
9 | open System.Runtime.InteropServices
10 | open System.Collections.Generic
11 | open System.Text
12 | open Microsoft.FSharp.Quotations
13 | open Microsoft.FSharp.Core.Printf
14 | open FsControl.BaseLib
15 | open FsControl.Internals
16 | open FsControl.Internals.Prelude
17 | open System.Numerics
18 |
19 |
20 | type Explicit =
21 | inherit Default1
22 | static member inline Explicit (_:'R , _:Default1) = fun (x : ^t) -> ((^R or ^t) : (static member op_Explicit : ^t -> ^R) x)
23 | static member inline Explicit (_:^t when ^t: null and ^t: struct, _:Default1) = ()
24 | static member inline Explicit (_:byte , _:Explicit) = fun x -> byte x
25 | static member inline Explicit (_:sbyte , _:Explicit) = fun x -> sbyte x
26 | static member inline Explicit (_:int16 , _:Explicit) = fun x -> int16 x
27 | static member inline Explicit (_:uint16 , _:Explicit) = fun x -> uint16 x
28 | static member inline Explicit (_:int32 , _:Explicit) = fun x -> int x
29 | static member inline Explicit (_:uint32 , _:Explicit) = fun x -> uint32 x
30 | static member inline Explicit (_:int64 , _:Explicit) = fun x -> int64 x
31 | static member inline Explicit (_:uint64 , _:Explicit) = fun x -> uint64 x
32 | static member inline Explicit (_:nativeint , _:Explicit) = fun x -> nativeint (int x)
33 | static member inline Explicit (_:unativeint, _:Explicit) = fun x -> unativeint (int x)
34 | static member inline Explicit (_:float , _:Explicit) = fun x -> float x
35 | static member inline Explicit (_:float32 , _:Explicit) = fun x -> float32 x
36 | static member inline Explicit (_:decimal , _:Explicit) = fun x -> decimal x
37 | static member inline Explicit (_:char , _:Explicit) = fun x -> char x
38 |
39 | static member inline Invoke value:'T =
40 | let inline call_2 (a:^a, b:^b) = ((^a or ^b) : (static member Explicit: _*_ -> _) b, a)
41 | let inline call (a:'a) = fun (x:'x) -> call_2 (a, Unchecked.defaultof<'r>) x :'r
42 | call Unchecked.defaultof value
43 |
44 | type OfBytes =
45 | static member OfBytes (_:bool , _:OfBytes) = fun (x, i, _) -> BitConverter.ToBoolean(x, i)
46 | static member OfBytes (_:char , _:OfBytes) = fun (x, i, e) -> BitConverter.ToChar (x, i, e)
47 | static member OfBytes (_:float , _:OfBytes) = fun (x, i, e) -> BitConverter.ToDouble (x, i, e)
48 | static member OfBytes (_: int16 , _:OfBytes) = fun (x, i, e) -> BitConverter.ToInt16 (x, i, e)
49 | static member OfBytes (_: int , _:OfBytes) = fun (x, i, e) -> BitConverter.ToInt32 (x, i, e)
50 | static member OfBytes (_:int64 , _:OfBytes) = fun (x, i, e) -> BitConverter.ToInt64 (x, i, e)
51 | static member OfBytes (_:float32, _:OfBytes) = fun (x, i, e) -> BitConverter.ToSingle (x, i, e)
52 | static member OfBytes (_:string , _:OfBytes) = fun (x, i, _) -> BitConverter.ToString (x, i)
53 | static member OfBytes (_:uint16 , _:OfBytes) = fun (x, i, e) -> BitConverter.ToUInt16 (x, i, e)
54 | static member OfBytes (_:uint32 , _:OfBytes) = fun (x, i, e) -> BitConverter.ToUInt32 (x, i, e)
55 | static member OfBytes (_:uint64 , _:OfBytes) = fun (x, i, e) -> BitConverter.ToUInt64 (x, i, e)
56 |
57 | static member inline Invoke (isLtEndian:bool) (startIndex:int) (value:byte[]) =
58 | let inline call_2 (a:^a, b:^b) = ((^a or ^b) : (static member OfBytes: _*_ -> _) b, a)
59 | let inline call (a:'a) = fun (x:'x) -> call_2 (a, Unchecked.defaultof<'r>) x :'r
60 | call Unchecked.defaultof (value, startIndex, isLtEndian)
61 |
62 |
63 | []
64 | type ToBytes =
65 | [