Skip to content

Commit 5e385f6

Browse files
Bump version to 2.0.0-alpha-016
1 parent c144658 commit 5e385f6

File tree

10 files changed

+720
-31
lines changed

10 files changed

+720
-31
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"type": "coreclr",
1010
"request": "launch",
1111
"preLaunchTask": "build",
12-
"program": "${workspaceRoot}/src/dotnet/Fable.Compiler/bin/Debug/netcoreapp2.0/Fable.Compiler.dll",
12+
"program": "${workspaceRoot}/src/dotnet/Fable.Compiler/bin/Debug/netcoreapp2.0/dotnet-fable.dll",
1313
"args": ["yarn-splitter", "--fable-core", "../../../build/fable-core"],
1414
"cwd": "${workspaceRoot}/src/tools/",
1515
"stopAtEntry": true,

src/dotnet/Fable.Compiler/CLI/CLI.Util.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace Fable.CLI
22

33
module Literals =
44

5-
let [<Literal>] VERSION = "2.0.0-alpha-015"
5+
let [<Literal>] VERSION = "2.0.0-alpha-016"
66
let [<Literal>] DEFAULT_PORT = 61225
77
let [<Literal>] FORCE = "force:"
88

src/dotnet/Fable.Compiler/Fable.Compiler.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<Description>Fable: F# to JS Compiler</Description>
55
<Version>2.0.0</Version>
6-
<PackageVersion>2.0.0-alpha-015</PackageVersion>
6+
<PackageVersion>2.0.0-alpha-016</PackageVersion>
77
<OutputType>Exe</OutputType>
88
<PackageType>DotnetCliTool</PackageType>
99
<AssemblyName>dotnet-fable</AssemblyName>

src/dotnet/Fable.Compiler/RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### 2.0.0-alpha-015
1+
### 2.0.0-alpha-016
22

33
* Fable 2 alpha
44

src/dotnet/Fable.Compiler/Transforms/FableTransforms.fs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ open Microsoft.FSharp.Compiler.SourceCodeServices
88
let visit f e =
99
match e with
1010
| IdentExpr _ | Debugger _ -> e
11-
| Import(e1, e2, kind, t, r) -> Import(f e1, f e2, kind, t, r)
11+
| Import(e1, e2, kind, t, r) -> Import(f e1, f e2, kind, t, r)
1212
| Value kind ->
1313
match kind with
1414
| TypeInfo _ | This _ | Super _ | Null _ | UnitConstant
@@ -319,6 +319,8 @@ module private Transforms =
319319
| FunctionType(LambdaType argType, returnType)
320320
| Option(FunctionType(LambdaType argType, returnType)) ->
321321
uncurryLambdaTypeInner [argType] returnType
322+
| FunctionType(DelegateType argTypes, returnType) ->
323+
argTypes, returnType
322324
| returnType -> [], returnType
323325

324326
let replaceIdentType replacements (id: Ident) =
@@ -475,11 +477,11 @@ module private Transforms =
475477
Operation(Emit(macro, Some info), t, r)
476478
| e -> e
477479

478-
let rec uncurryApplications e =
480+
let rec uncurryApplications (com: ICompiler) e =
479481
match e with
480482
| NestedApply(applied, args, t, r) ->
481-
let applied = visitFromOutsideIn uncurryApplications applied
482-
let args = args |> List.map (visitFromOutsideIn uncurryApplications)
483+
let applied = visitFromOutsideIn (uncurryApplications com) applied
484+
let args = args |> List.map (visitFromOutsideIn (uncurryApplications com))
483485
match applied.Type with
484486
| FunctionType(DelegateType argTypes, _) ->
485487
if List.sameLength argTypes args then
@@ -519,9 +521,9 @@ let optimizations =
519521
// Then apply uncurry optimizations
520522
fun com e -> visitFromInsideOut (uncurryReceivedArgs com) e
521523
fun com e -> visitFromInsideOut (uncurryRecordFields com) e
522-
fun com e -> visitFromInsideOut (uncurrySendingArgs com) e
523524
fun com e -> visitFromInsideOut (uncurryInnerFunctions com) e
524-
fun _ e -> visitFromOutsideIn uncurryApplications e
525+
fun com e -> visitFromOutsideIn (uncurryApplications com) e
526+
fun com e -> visitFromInsideOut (uncurrySendingArgs com) e
525527
// Don't traverse the expression for the unwrap function optimization
526528
unwrapFunctions
527529
]

src/js/fable-core/Util.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -442,28 +442,39 @@ export interface ICurried {
442442
/* tslint:disable */
443443
export function uncurry(arity: number, f: Function) {
444444
/* tslint:enable */
445-
446445
// f may be a function option with None value
447-
if (f == null) {
448-
return null;
446+
if (f == null) { return null; }
447+
448+
// return (...args) => {
449+
// // In some cases there may be more arguments applied than necessary
450+
// // (e.g. index when mapping an array), discard them
451+
// args = args.slice(0, arity);
452+
// let res = f;
453+
// while (args.length > 0) {
454+
// const curArgs = args.splice(0,1);
455+
// res = res.apply(null, curArgs);
456+
// }
457+
// return res;
458+
// };
459+
switch (arity) {
460+
case 2:
461+
return (a1: any, a2: any) => f(a1)(a2);
462+
case 3:
463+
return (a1: any, a2: any, a3: any) => f(a1)(a2)(a3);
464+
case 4:
465+
return (a1: any, a2: any, a3: any, a4: any) => f(a1)(a2)(a3)(a4);
466+
case 5:
467+
return (a1: any, a2: any, a3: any, a4: any, a5: any) => f(a1)(a2)(a3)(a4)(a5);
468+
case 6:
469+
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any) => f(a1)(a2)(a3)(a4)(a5)(a6);
470+
case 7:
471+
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7);
472+
case 8:
473+
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any) =>
474+
f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8);
475+
default:
476+
throw new Error("Uncurrying to more than 8-arity is not supported: " + arity);
449477
}
450-
451-
const wrap: ICurried = (...args: any[]) => {
452-
// In some cases there may be more arguments applied than necessary
453-
// (e.g. index when mapping an array), discard them
454-
let res: any = f;
455-
for (let i = 0; i < arity; i++) {
456-
const accArgs = [args[i]];
457-
const partialArity = Math.max(f.length, 1);
458-
while (accArgs.length < partialArity) {
459-
accArgs.push(args[++i]);
460-
}
461-
res = res.apply(null, accArgs);
462-
}
463-
return res;
464-
};
465-
wrap.curried = true;
466-
return wrap;
467478
}
468479

469480
/* tslint:disable */
@@ -522,7 +533,7 @@ export function partialApply(arity: number, f: ICurried, args: any[]): any {
522533
return (a1: any) => (a2: any) => (a3: any) => (a4: any) => (a5: any) => (a6: any) =>
523534
(a7: any) => (a8: any) => f.apply(null, args.concat([a1, a2, a3, a4, a5, a6, a7, a8]));
524535
default:
525-
throw new Error("Partially applying to get a function with more than 8-arity is not supported: " + arity);
536+
throw new Error("Partially applying to more than 8-arity is not supported: " + arity);
526537
}
527538
}
528539
}

src/tools/QuickTest.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<Reference Include="../../build/fable/Fable.Core.dll" />
88
</ItemGroup>
99
<ItemGroup>
10+
<Compile Include="../../tests/Main/Util/Thoth.Json.Decode.fs" />
1011
<Compile Include="QuickTest.fs" />
1112
</ItemGroup>
1213
</Project>

tests/Main/ApplicativeTests.fs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ module Results =
704704
let sum = add3 <!> Ok 1 <*> Ok 2 <*> Ok 3
705705
equal (Ok 6) sum
706706

707+
open Thoth.Json.Decode
708+
707709
let tests7 = [
708710
testCase "SRTP with ActivePattern works" <| fun () ->
709711
(lengthWrapper []) |> equal 0
@@ -810,6 +812,20 @@ let tests7 = [
810812
[1,2; 3,4; 5,6]
811813
|> List.map (sum 10)
812814
List.sum li |> equal 51
815+
816+
testCase "Composing methods returning 2-arity lambdas works" <| fun _ ->
817+
let infoHelp version =
818+
match version with
819+
| 4 -> succeed 1
820+
| 3 -> succeed 1
821+
| _ -> fail <| "Trying to decode info, but version " + (version.ToString()) + "is not supported"
822+
823+
let info : Decoder<int> =
824+
field "version" int
825+
|> andThen infoHelp
826+
827+
decodeString info """{ "version": 3, "data": 2 }"""
828+
|> equal (FSharp.Core.Ok 1)
813829
]
814830

815831
let tests =

tests/Main/Fable.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</ItemGroup>
1515
<ItemGroup>
1616
<Compile Include="Util/b.fs" />
17+
<Compile Include="Util/Thoth.Json.Decode.fs" />
1718
<Compile Include="Util/Aether.fs" />
1819
<Compile Include="Util/Util.fs" />
1920
<Compile Include="Util/Util2.fs" />

0 commit comments

Comments
 (0)