From 995c3efe4ed91955873c7abd7adae65bf82cfaba Mon Sep 17 00:00:00 2001 From: Patrick Stevens Date: Sat, 17 Jun 2023 19:41:15 +0100 Subject: [PATCH] Update Fantomas (#5) --- .config/dotnet-tools.json | 6 ++-- .editorconfig | 8 +++-- .github/workflows/dotnet-core.yaml | 2 +- FicroKanSharp.Test/Arithmetic.fs | 9 +++-- FicroKanSharp.Test/Recursive.fs | 8 ++--- FicroKanSharp.Test/TestExamples.fs | 50 +++++---------------------- FicroKanSharp.Test/TypedArithmetic.fs | 10 ++---- FicroKanSharp/Domain.fs | 8 ++--- FicroKanSharp/Goal.fs | 20 ++--------- FicroKanSharp/Typed.fs | 49 ++++++++++---------------- 10 files changed, 51 insertions(+), 119 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 50b7ad3..7bb2739 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -2,11 +2,11 @@ "version": 1, "isRoot": true, "tools": { - "fantomas-tool": { - "version": "4.6.0", + "fantomas": { + "version": "6.0.5", "commands": [ "fantomas" ] } } -} \ No newline at end of file +} diff --git a/.editorconfig b/.editorconfig index 8180abf..d349702 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,8 +7,12 @@ fsharp_space_before_colon=true fsharp_space_before_semicolon=true fsharp_multiline_block_brackets_on_same_column=true fsharp_newline_between_type_definition_and_members=true -fsharp_keep_indent_in_branch=true +fsharp_experimental_keep_indent_in_branch=true fsharp_align_function_signature_to_indentation=true fsharp_alternative_long_member_definitions=true -fsharp_disable_elmish_syntax=true +fsharp_multiline_bracket_style=aligned fsharp_multi_line_lambda_closing_newline=true +fsharp_max_value_binding_width=80 +fsharp_max_record_width=0 +max_line_length=120 +end_of_line=lf diff --git a/.github/workflows/dotnet-core.yaml b/.github/workflows/dotnet-core.yaml index 7a802d4..cda12f2 100644 --- a/.github/workflows/dotnet-core.yaml +++ b/.github/workflows/dotnet-core.yaml @@ -26,4 +26,4 @@ jobs: - name: Install Fantomas run: dotnet tool restore - name: Run Fantomas - run: dotnet tool run fantomas --check -r . + run: dotnet tool run fantomas --check . diff --git a/FicroKanSharp.Test/Arithmetic.fs b/FicroKanSharp.Test/Arithmetic.fs index 33aa972..11f0c8f 100644 --- a/FicroKanSharp.Test/Arithmetic.fs +++ b/FicroKanSharp.Test/Arithmetic.fs @@ -13,10 +13,7 @@ module Arithmetic = let succ (x : Term) : Term = Term.Symbol ("succ", [ x ]) let rec ofInt (n : int) : Term = - if n = 0 then - zero - else - succ (ofInt (n - 1)) + if n = 0 then zero else succ (ofInt (n - 1)) // "pluso x y z" is "x + y == z". let rec pluso (x : Term) (y : Term) (z : Term) : Goal = @@ -125,7 +122,9 @@ module Arithmetic = Goal.conj (Goal.equiv (TypedTerm.compile x) (TypedTerm.compile (succ n))) - (Goal.conj (Goal.equiv z (succ m |> TypedTerm.compile)) (Goal.delay (fun () -> pluso n y m))) + (Goal.conj + (Goal.equiv z (succ m |> TypedTerm.compile)) + (Goal.delay (fun () -> pluso n y m))) ) ) diff --git a/FicroKanSharp.Test/Recursive.fs b/FicroKanSharp.Test/Recursive.fs index f9ac111..7ad5697 100644 --- a/FicroKanSharp.Test/Recursive.fs +++ b/FicroKanSharp.Test/Recursive.fs @@ -101,11 +101,7 @@ module Recursive = |> shouldEqual ( Map.ofList [ - VariableCount 0, - TypedTerm.literal (Human "bridget") - |> TypedTerm.compile - VariableCount 1, - TypedTerm.literal (Human "caroline") - |> TypedTerm.compile + VariableCount 0, TypedTerm.literal (Human "bridget") |> TypedTerm.compile + VariableCount 1, TypedTerm.literal (Human "caroline") |> TypedTerm.compile ] ) diff --git a/FicroKanSharp.Test/TestExamples.fs b/FicroKanSharp.Test/TestExamples.fs index 2cbcc1a..64035ca 100644 --- a/FicroKanSharp.Test/TestExamples.fs +++ b/FicroKanSharp.Test/TestExamples.fs @@ -58,12 +58,7 @@ module TestThing = | None -> failwith "oh no" | Some (s, rest) -> - s - |> Map.toList - |> shouldEqual - [ - Variable.VariableCount 0, Term.Symbol (5, []) - ] + s |> Map.toList |> shouldEqual [ Variable.VariableCount 0, Term.Symbol (5, []) ] match Stream.peel rest with | None -> () @@ -78,18 +73,9 @@ module TestThing = |> Stream.take 3 |> shouldEqual [ - Map.ofList - [ - Variable.VariableCount 0, Term.Symbol (5, []) - ] - Map.ofList - [ - Variable.VariableCount 0, Term.Symbol (5, []) - ] - Map.ofList - [ - Variable.VariableCount 0, Term.Symbol (5, []) - ] + Map.ofList [ Variable.VariableCount 0, Term.Symbol (5, []) ] + Map.ofList [ Variable.VariableCount 0, Term.Symbol (5, []) ] + Map.ofList [ Variable.VariableCount 0, Term.Symbol (5, []) ] ] [] @@ -108,45 +94,25 @@ module TestThing = | None -> failwith "oh no" | Some (s, rest) -> - s - |> Map.toList - |> shouldEqual - [ - Variable.VariableCount 0, Term.Symbol (5, []) - ] + s |> Map.toList |> shouldEqual [ Variable.VariableCount 0, Term.Symbol (5, []) ] match Stream.peel rest with | None -> failwith "oh no" | Some (s, rest) -> - s - |> Map.toList - |> shouldEqual - [ - Variable.VariableCount 0, Term.Symbol (6, []) - ] + s |> Map.toList |> shouldEqual [ Variable.VariableCount 0, Term.Symbol (6, []) ] match Stream.peel rest with | None -> failwith "oh no" | Some (s, rest) -> - s - |> Map.toList - |> shouldEqual - [ - Variable.VariableCount 0, Term.Symbol (5, []) - ] + s |> Map.toList |> shouldEqual [ Variable.VariableCount 0, Term.Symbol (5, []) ] match Stream.peel rest with | None -> failwith "oh no" | Some (s, _rest) -> - s - |> Map.toList - |> shouldEqual - [ - Variable.VariableCount 0, Term.Symbol (6, []) - ] + s |> Map.toList |> shouldEqual [ Variable.VariableCount 0, Term.Symbol (6, []) ] /// This arose because x0 unified to x1, x1 unified to 1, but x0 didn't get reduced to 1 by `walk`. [] diff --git a/FicroKanSharp.Test/TypedArithmetic.fs b/FicroKanSharp.Test/TypedArithmetic.fs index 3b47cbe..7b8c60f 100644 --- a/FicroKanSharp.Test/TypedArithmetic.fs +++ b/FicroKanSharp.Test/TypedArithmetic.fs @@ -26,12 +26,7 @@ module TypedArithmetic = if t2 = 0 then None else - unify - (TypedTerm.compile t1) - (Pure (t2 - 1) - |> TypedTerm.literal - |> TypedTerm.compile) - state + unify (TypedTerm.compile t1) (Pure (t2 - 1) |> TypedTerm.literal |> TypedTerm.compile) state | Pure t1, Succ t2 -> if t1 = 0 then None @@ -69,7 +64,8 @@ module TypedArithmetic = TypedTerm.Goal.callFresh (fun n -> Goal.conj (TypedTerm.Goal.equiv x (succ n)) - (TypedTerm.Goal.callFresh (fun ny -> Goal.conj (Goal.delay (fun () -> timeso n y ny)) (pluso y ny z) + (TypedTerm.Goal.callFresh (fun ny -> + Goal.conj (Goal.delay (fun () -> timeso n y ny)) (pluso y ny z) )) ) diff --git a/FicroKanSharp/Domain.fs b/FicroKanSharp/Domain.fs index 9ccac5b..2e7160b 100644 --- a/FicroKanSharp/Domain.fs +++ b/FicroKanSharp/Domain.fs @@ -16,10 +16,7 @@ type Term = override this.ToString () = match this with | Symbol (name, args) -> - let s = - args - |> List.map (sprintf "%O") - |> String.concat ", " + let s = args |> List.map (sprintf "%O") |> String.concat ", " $"{name}[{s}]" | Variable (VariableCount v) -> $"x{v}" @@ -38,8 +35,7 @@ type Goal = if variableCount > 4 then "" else - $"exists x{variableCount}: ({(g (VariableCount variableCount)) - .ToString (variableCount + 1)})" + $"exists x{variableCount}: ({(g (VariableCount variableCount)).ToString (variableCount + 1)})" | Conj (g1, g2) -> sprintf "((%s) AND (%s))" (g1.ToString variableCount) (g2.ToString variableCount) | Disj (g1, g2) -> sprintf "((%s) OR (%s))" (g1.ToString variableCount) (g2.ToString variableCount) | Equiv (g1, g2) -> sprintf "(%O) == (%O)" g1 g2 diff --git a/FicroKanSharp/Goal.fs b/FicroKanSharp/Goal.fs index 8f07d9b..e3209d6 100644 --- a/FicroKanSharp/Goal.fs +++ b/FicroKanSharp/Goal.fs @@ -86,8 +86,7 @@ module Goal = None else //(unify : Term -> Term -> bool option) - if unifyMethod.ReturnParameter.ParameterType - <> typeof then + if unifyMethod.ReturnParameter.ParameterType <> typeof then failwith $"Incorrect unify return parameter should have been Option: {unifyMethod.ReturnParameter.ParameterType}" @@ -125,17 +124,7 @@ module Goal = failwith $"Wrong parameters on Unify method of type {ty.Name}: {wrongParams}" let result = - unifyMethod.Invoke ( - name1, - [| - unify - name1 - args1 - name2 - args2 - state - |] - ) + unifyMethod.Invoke (name1, [| unify ; name1 ; args1 ; name2 ; args2 ; state |]) |> unbox result @@ -155,8 +144,7 @@ module Goal = name1.GetType () |> fun ty -> if FSharpType.IsUnion ty then - if FSharpType.GetUnionCases ty - |> Array.forall (fun i -> i.GetFields().Length = 0) then + if FSharpType.GetUnionCases ty |> Array.forall (fun i -> i.GetFields().Length = 0) then // reference enum ty else @@ -178,8 +166,6 @@ module Goal = else customUnification ty name1 args1 name2 args2 s - | _, _ -> None - let rec private evaluate' (debug : bool) (goal : Goal) (state : State) : Stream = if debug then let varState = diff --git a/FicroKanSharp/Typed.fs b/FicroKanSharp/Typed.fs index b9855ba..54d96c6 100644 --- a/FicroKanSharp/Typed.fs +++ b/FicroKanSharp/Typed.fs @@ -12,8 +12,8 @@ type TypedTerm<'a> = type private TermConstructor = { - Literal : obj [] -> obj - Term : obj [] -> obj + Literal : obj[] -> obj + Term : obj[] -> obj } type private FSharpUnionCase = @@ -21,8 +21,8 @@ type private FSharpUnionCase = Name : string /// The PropertyInfo for the field, and the Literal case constructor of the TypedTerm /// if it is one - Fields : (PropertyInfo * Option) [] - Constructor : obj [] -> obj + Fields : (PropertyInfo * Option)[] + Constructor : obj[] -> obj } [] @@ -37,9 +37,7 @@ type internal TypeName<'a when 'a : equality> = override this.Equals (other : obj) : bool = match other with - | :? TypeName<'a> as other -> - this.UserType = other.UserType - && this.FieldValue = other.FieldValue + | :? TypeName<'a> as other -> this.UserType = other.UserType && this.FieldValue = other.FieldValue | _ -> false override this.GetHashCode () = hash (this.UserType, this.FieldValue) @@ -50,9 +48,7 @@ type internal TypeName<'a when 'a : equality> = | Some (cases, tagDiscriminator) -> if t1.FieldValue.GetType () = typeof then - let case = - cases - |> Array.find (fun case -> case.Name = unbox t1.FieldValue) + let case = cases |> Array.find (fun case -> case.Name = unbox t1.FieldValue) args |> List.mapi (fun i term -> @@ -65,11 +61,10 @@ type internal TypeName<'a when 'a : equality> = .GetType() .GetMethod( "Unbox", - BindingFlags.Public - ||| BindingFlags.NonPublic - ||| BindingFlags.Instance + BindingFlags.Public ||| BindingFlags.NonPublic ||| BindingFlags.Instance ) - .MakeGenericMethod typeof + .MakeGenericMethod + typeof let unboxed = mi.Invoke (name, [||]) |> unbox> @@ -110,8 +105,7 @@ type internal TypeName<'a when 'a : equality> = None else - if unifyMethod.ReturnParameter.ParameterType - <> typeof then + if unifyMethod.ReturnParameter.ParameterType <> typeof then failwith $"Incorrect unify return parameter should have been Option: {unifyMethod.ReturnParameter.ParameterType}" @@ -169,24 +163,23 @@ module TypedTerm = let literal<'a> (t : 'a) : TypedTerm<'a> = TypedTerm.Literal t let resolveGeneric (t : Type) : Type = - if t.IsGenericType then - t.GetGenericTypeDefinition () - else - t + if t.IsGenericType then t.GetGenericTypeDefinition () else t let rec private toUntypedLiteral' (ty : Type) : obj -> Term = if ty = typeof then fun t -> Term.Variable (unbox t) elif FSharpType.IsUnion ty then - let toTermList (o : obj []) : Term list = + let toTermList (o : obj[]) : Term list = o |> List.ofArray |> List.map (fun (o : obj) -> let ty = o.GetType () - if ty.BaseType.IsGenericType - && ty.BaseType.GetGenericTypeDefinition () = typedefof>.GetGenericTypeDefinition - () then + if + ty.BaseType.IsGenericType + && ty.BaseType.GetGenericTypeDefinition () = typedefof> + .GetGenericTypeDefinition () + then o |> compileUntyped ty.GenericTypeArguments.[0] else toUntypedLiteral o @@ -208,8 +201,7 @@ module TypedTerm = let ty = pi.PropertyType let isTypedTerm = - ty.IsGenericType - && ty.GetGenericTypeDefinition () = typedefof> + ty.IsGenericType && ty.GetGenericTypeDefinition () = typedefof> let constructor = if isTypedTerm then @@ -240,10 +232,7 @@ module TypedTerm = fun t -> let case = cases.[precomputed t] - let values = - case.Fields - |> Array.map (fun (pi, _) -> pi.GetValue t) - |> toTermList + let values = case.Fields |> Array.map (fun (pi, _) -> pi.GetValue t) |> toTermList Term.Symbol ( {