Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
f607aa5
Implement first part of Normalform instance generator #150
Aug 26, 2020
b7350aa
Generate full Normalform instances #150
Aug 26, 2020
c998122
Always export Identity #150
Aug 26, 2020
95d7a97
Clean up code a little #150
Aug 26, 2020
329f491
Merge with branch issue-148#150
Aug 26, 2020
65d4222
Format code #150
Aug 26, 2020
01fec1a
Merge main into issue-150 #150
Aug 26, 2020
7672eee
Refactor code #150
Aug 27, 2020
5410691
Refactor code and expand type synonyms #150
Aug 27, 2020
29300fc
Generalize instance generation #150
Aug 27, 2020
99d8309
Use fresh variables for unification and adjust local environments #150
Aug 30, 2020
32a911f
Add helper functions to FreeC.IR.Syntax.Type #150
Aug 30, 2020
8dafd90
Add smart constructor for qualified Coq names to Coq.Syntax #150
Aug 30, 2020
41a3e66
Add some constants to Coq.Base #150
Aug 30, 2020
c9fce32
Use helper function from IR.Syntax.Type in CompletePatternPass #150
Aug 30, 2020
35051fa
Refactor code a little #150
Aug 30, 2020
32198d6
Refactor code some more #150
Aug 30, 2020
039b07d
Remove redundant brackets #150
Aug 30, 2020
dfc24ef
Add examples to test generated normalforms in Coq #175
MarvinLira Aug 30, 2020
26f73c3
Run floskell #175
MarvinLira Aug 30, 2020
2b1aa90
Add documentation and refactor code #150
Sep 10, 2020
1853b9d
Merge branch 'main' of https://github.com/FreeProving/free-compiler i…
Sep 10, 2020
65e8311
Merge partially with issue-183 #150
Sep 10, 2020
044e1ad
Merge fully with issue-183 #150
Sep 10, 2020
2a7edd5
Refactor code and remove Shape and Pos arguments from local functions…
Sep 10, 2020
216d8cd
Refactor code, add documentation and fix a bug #150
Sep 10, 2020
5efac3a
Merge branch 'issue-150' of https://github.com/FreeProving/free-compi…
Sep 10, 2020
274127c
Use Map for type map #150
Sep 10, 2020
bccdf4c
Fix refactoring-induced bug #150
Sep 10, 2020
8bc591d
Merge branch 'issue-176' of https://github.com/FreeProving/free-compi…
Sep 11, 2020
7946d48
Merge branch 'issue-176' of https://github.com/FreeProving/free-compi…
Sep 11, 2020
6d0da01
Use Coq.Base functions added to the main branch #150
Sep 14, 2020
3f55afd
Merge branch 'main' of https://github.com/FreeProving/free-compiler i…
Sep 14, 2020
d56b21d
Make helper functions local #150
Sep 14, 2020
8b02b89
Expand documentation #150
Sep 14, 2020
cc75a40
Add Coq comment above class instances #150
Sep 14, 2020
d48a234
Add constant for underscore variable #150
Sep 14, 2020
7a2d4a5
Format code with Floskell #150
Sep 14, 2020
e8201b6
Format Coq.Base #150
Sep 14, 2020
e457b6e
Merge main into issue-150 #150
Sep 14, 2020
bc134ba
Adjust tests #150
Sep 15, 2020
a5ed9cb
Merge main into issue-150 #150
Sep 15, 2020
02a3b00
Format code with Floskell #150
Sep 15, 2020
deb41b3
Generate ShareableArgs instances #150 #151
Sep 15, 2020
7cf7f1b
Adjust tests #150 #151
Sep 15, 2020
f07e6d3
Apply HLint hint #150 #151
Sep 15, 2020
df40a5f
Add tests for generated ShareableArgs instances #150 #151
Sep 15, 2020
c0f3304
Rename Normalform and NormalformProofs #150 #151
Sep 15, 2020
627002b
Format code with Floskell #150 #151
Sep 15, 2020
72f1150
Fix indentation of Haddock comment #150 #151
Sep 15, 2020
8f7080f
Format code with Floskell #150 #151
Sep 15, 2020
bb296e3
Add a few more example type to test generated instances #150 #151
Sep 15, 2020
4f59925
Add periods to comments #150 #151
MajaRet Sep 16, 2020
a983129
Apply suggestions #150
Sep 20, 2020
030a255
Fix HLint and Haddock errors #150
Sep 20, 2020
9103c13
Move instance and induction scheme generation into separate modules #150
Sep 20, 2020
c068f50
Format code #150
Sep 20, 2020
8b73979
Test unformatted as-pattern #150
Sep 20, 2020
2aba14b
Try workaround without as-pattern #150
Sep 20, 2020
b3f257a
Rename source span variables #150
Sep 20, 2020
4a25f3b
Also rename occurrences of the source span variables #150
Sep 20, 2020
b4f9edb
Change Floskell configuration so as-patterns are not split #150
Sep 20, 2020
733079b
Capitalize words in header comments #150
Sep 20, 2020
1a21bd1
Merge branch 'main' of https://github.com/FreeProving/free-compiler i…
Sep 20, 2020
91328df
Format TypeDecl tests #150
Sep 20, 2020
b85dca3
Add prefixes for normalized and shared variables to Fresh #150
Sep 25, 2020
a6c5ea0
Use new data type for stripped type #150
Sep 25, 2020
341a401
Remove Ord instance from SrcSpan and Type #150
Sep 25, 2020
c8137c8
Incorporate changes from issue-202 pertaining to Normalform generatio…
Sep 28, 2020
29d2a94
Adjust TypeDeclTests #150
Sep 28, 2020
5fd71b0
Merge main into branch #150
Sep 28, 2020
90de42e
Remove second type variable from Handlers #150
Sep 28, 2020
1304908
Use generateBind #150
Sep 28, 2020
c619199
Remove redundant brackets and fix var names in tests #150
Sep 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base/coq/Free.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
From Base Require Export Free.Class.
From Base Require Export Free.ForFree.
From Base Require Export Free.Induction.
From Base Require Export Free.Instance.Identity.
From Base Require Export Free.Malias.
From Base Require Export Free.Monad.
From Base Require Export Free.Tactic.ProveInd.
Expand Down
25 changes: 15 additions & 10 deletions base/coq/Free/Class/Normalform.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,37 @@

From Base Require Import Free.Monad.

From Base Require Import Free.Instance.Identity.

Class Normalform (Shape : Type) (Pos : Shape -> Type)
(A B : Type) :=
(A : Type) :=
{
(** The normalized return type. *)
nType : Type;
(** The function is split into two parts due to termination check errors
for recursive data types. *)
nf' : A -> Free Shape Pos B
nf' : A -> Free Shape Pos nType
}.

Definition nf {Shape : Type} {Pos : Shape -> Type} {A B : Type}
`{Normalform Shape Pos A B} (n : Free Shape Pos A)
: Free Shape Pos B
(* Normalizes a Free value. *)
Definition nf {Shape : Type} {Pos : Shape -> Type} {A : Type}
`{Normalform Shape Pos A} (n : Free Shape Pos A)
: Free Shape Pos nType
:= n >>= nf'.

Lemma nfImpure {Shape : Type} {Pos : Shape -> Type} {A B : Type}
`{Normalform Shape Pos A B}
Lemma nfImpure {Shape : Type} {Pos : Shape -> Type} {A : Type}
`{Normalform Shape Pos A}
: forall s (pf : _ -> Free Shape Pos A),
nf (impure s pf) = impure s (fun p => nf (pf p)).
Proof. trivial. Qed.

Lemma nfPure {Shape : Type} {Pos : Shape -> Type} {A B : Type}
`{Normalform Shape Pos A B} : forall (x : A),
Lemma nfPure {Shape : Type} {Pos : Shape -> Type} {A : Type}
`{Normalform Shape Pos A} : forall (x : A),
nf (pure x) = nf' x.
Proof. trivial. Qed.

(* Normalform instance for functions.
Effects inside of functions are not pulled to the root. *)
Instance NormalformFunc (Shape : Type) (Pos : Shape -> Type) (A B : Type)
: Normalform Shape Pos (A -> B) (A -> B) :=
: Normalform Shape Pos (A -> B) :=
{ nf' := pure }.
132 changes: 66 additions & 66 deletions base/coq/Free/Handlers.v
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Require Import Coq.Lists.List.
Section NoEffect.

(* Identity handler *)
Definition handleNoEffect {A B : Type}
`{Normalform _ _ A B}
(p : Free Identity.Shape Identity.Pos A) : B
Definition handleNoEffect {A : Type}
`{Normalform _ _ A}
(p : Free Identity.Shape Identity.Pos A)
:= run (nf p).

End NoEffect.
Expand All @@ -32,50 +32,50 @@ Section OneEffect.
Definition SMId := Comb.Shape Maybe.Shape Identity.Shape.
Definition PMId := Comb.Pos Maybe.Pos Identity.Pos.

Definition handleMaybe {A B : Type}
`{Normalform SMId PMId A B}
Definition handleMaybe {A : Type}
`{Normalform SMId PMId A}
(p : Free SMId PMId A)
: option B := run (runMaybe (nf p)).
: option nType := run (runMaybe (nf p)).

(* Error :+: Identity handler *)

Definition SErrId := Comb.Shape (Error.Shape string) Identity.Shape.
Definition PErrId := Comb.Pos (@Error.Pos string) Identity.Pos.

Definition handleError {A B : Type}
`{Normalform SErrId PErrId A B}
(p : Free SErrId PErrId A) : (B + string)
Definition handleError {A : Type}
`{Normalform SErrId PErrId A}
(p : Free SErrId PErrId A) : (nType + string)
:= run (runError (nf p)).


(* ND :+: Identity handler *)
Definition SNDId := Comb.Shape ND.Shape Identity.Shape.
Definition PNDId := Comb.Pos ND.Pos Identity.Pos.

Definition handleND {A B : Type}
`{Normalform SNDId PNDId A B}
(p : Free SNDId PNDId A) : list B
Definition handleND {A : Type}
`{Normalform SNDId PNDId A}
(p : Free SNDId PNDId A) : list nType
:= collectVals (run (runChoice (nf p))).

(* Trace :+: Identity handler *)

Definition STrcId := Comb.Shape Trace.Shape Identity.Shape.
Definition PTrcId := Comb.Pos Trace.Pos Identity.Pos.

Definition handleTrace {A B : Type}
`{Normalform STrcId PTrcId A B}
Definition handleTrace {A : Type}
`{Normalform STrcId PTrcId A}
(p : Free STrcId PTrcId A)
: (B * list string) :=
: (nType * list string) :=
collectMessages (run (runTracing (nf p))).

(* Share :+: Identity handler *)

Definition SShrId := Comb.Shape Share.Shape Identity.Shape.
Definition PShrId := Comb.Pos Share.Pos Identity.Pos.

Definition handleShare {A B : Type}
`{Normalform SShrId PShrId A B}
(p : Free SShrId PShrId A) : B :=
Definition handleShare {A : Type}
`{Normalform SShrId PShrId A}
(p : Free SShrId PShrId A) : nType :=
run (runEmptySharing (0,0) (nf p)).

End OneEffect.
Expand All @@ -92,9 +92,9 @@ Section TwoEffects.
Definition PShrND := Comb.Pos Share.Pos (Comb.Pos ND.Pos Identity.Pos).


Definition handleShareND {A B : Type}
`{Normalform SShrND PShrND A B}
(p : Free SShrND PShrND A) : (list B)
Definition handleShareND {A : Type}
`{Normalform SShrND PShrND A}
(p : Free SShrND PShrND A) : (list nType)
:= collectVals (run (runChoice (runNDSharing (0,0) (nf p)))).

(* Share :+: Trace :+: Identity handler *)
Expand All @@ -103,31 +103,31 @@ Section TwoEffects.
Definition PShrTrc := Comb.Pos Share.Pos (Comb.Pos Trace.Pos Identity.Pos).


Definition handleShareTrace {A B : Type}
`{Normalform SShrTrc PShrTrc A B}
Definition handleShareTrace {A : Type}
`{Normalform SShrTrc PShrTrc A}
(p : Free SShrTrc PShrTrc A)
: (B * list string) :=
: (nType * list string) :=
collectMessages (run (runTracing (runTraceSharing (0,0) (nf p)))).

(* Share :+: Maybe :+: Identity handler *)

Definition SShrMaybe := Comb.Shape Share.Shape (Comb.Shape Maybe.Shape Identity.Shape).
Definition PShrMaybe := Comb.Pos Share.Pos (Comb.Pos Maybe.Pos Identity.Pos).

Definition handleShareMaybe {A B : Type}
`{Normalform SShrMaybe PShrMaybe A B}
(p : Free SShrMaybe PShrMaybe A) : option B :=
Definition handleShareMaybe {A : Type}
`{Normalform SShrMaybe PShrMaybe A}
(p : Free SShrMaybe PShrMaybe A) : option nType :=
run (runMaybe (runEmptySharing (0,0) (nf p))).

(* ND :+: Maybe :+: Identity handler *)

Definition SNDMaybe := Comb.Shape ND.Shape (Comb.Shape Maybe.Shape Identity.Shape).
Definition PNDMaybe := Comb.Pos ND.Pos (Comb.Pos Maybe.Pos Identity.Pos).

Definition handleNDMaybe {A B : Type}
`{Normalform SNDMaybe PNDMaybe A B}
Definition handleNDMaybe {A : Type}
`{Normalform SNDMaybe PNDMaybe A}
(p : Free SNDMaybe PNDMaybe A)
: option (list B) := match run (runMaybe (runChoice (nf p))) with
: option (list nType) := match run (runMaybe (runChoice (nf p))) with
| None => None
| Some t => Some (collectVals t)
end.
Expand All @@ -137,20 +137,20 @@ Section TwoEffects.
Definition SMaybeTrc := Comb.Shape Maybe.Shape (Comb.Shape Trace.Shape Identity.Shape).
Definition PMaybeTrc := Comb.Pos Maybe.Pos (Comb.Pos Trace.Pos Identity.Pos).

Definition handleMaybeTrace {A B : Type}
`{Normalform SMaybeTrc PMaybeTrc A B}
Definition handleMaybeTrace {A : Type}
`{Normalform SMaybeTrc PMaybeTrc A}
(p : Free SMaybeTrc PMaybeTrc A)
: option B * list string :=
: option nType * list string :=
collectMessages (run (runTracing (runMaybe (nf p)))).

(* Share :+: Error :+: Identity handler *)

Definition SShrErr := Comb.Shape Share.Shape (Comb.Shape (Error.Shape string) Identity.Shape).
Definition PShrErr := Comb.Pos Share.Pos (Comb.Pos (@Error.Pos string) Identity.Pos).

Definition handleShareError {A B : Type}
`{Normalform SShrErr PShrErr A B}
(p : Free SShrErr PShrErr A) : (B + string)
Definition handleShareError {A : Type}
`{Normalform SShrErr PShrErr A}
(p : Free SShrErr PShrErr A) : (nType + string)
:= run (runError (runEmptySharing (0,0) (nf p))).


Expand All @@ -159,9 +159,9 @@ Section TwoEffects.
Definition SNDErr := Comb.Shape ND.Shape (Comb.Shape (Error.Shape string) Identity.Shape).
Definition PNDErr := Comb.Pos ND.Pos (Comb.Pos (@Error.Pos string) Identity.Pos).

Definition handleNDError {A B : Type}
`{Normalform SNDErr PNDErr A B}
(p : Free SNDErr PNDErr A) : list B + string
Definition handleNDError {A : Type}
`{Normalform SNDErr PNDErr A}
(p : Free SNDErr PNDErr A) : list nType + string
:= match run (runError (runChoice (nf p))) with
| inl t => inl (collectVals t)
| inr e => inr e
Expand All @@ -175,23 +175,23 @@ Section TwoEffects.
Definition SErrorTrc := Comb.Shape (Error.Shape string) (Comb.Shape Trace.Shape Identity.Shape).
Definition PErrorTrc := Comb.Pos (@Error.Pos string) (Comb.Pos Trace.Pos Identity.Pos).

Definition handleErrorTrc {A B : Type}
`{Normalform SErrorTrc PErrorTrc A B}
Definition handleErrorTrc {A : Type}
`{Normalform SErrorTrc PErrorTrc A}
(p : Free SErrorTrc PErrorTrc A)
: (B + string) * list string
: (nType + string) * list string
:= collectMessages (run (runTracing (runError (nf p)))).

(* Trace :+: ND :+: Identity handler *)

Definition STrcND := Comb.Shape Trace.Shape (Comb.Shape ND.Shape Identity.Shape).
Definition PTrcND := Comb.Pos Trace.Pos (Comb.Pos ND.Pos Identity.Pos).

Definition handleTraceND {A B : Type}
`{Normalform STrcND PTrcND A B}
Definition handleTraceND {A : Type}
`{Normalform STrcND PTrcND A}
(p : Free STrcND PTrcND A)
: list (B * list string) :=
map (@collectMessages B)
(@collectVals (B * list (option Sharing.ID * string))
: list (nType * list string) :=
map (@collectMessages nType)
(@collectVals (nType * list (option Sharing.ID * string))
(run (runChoice (runTracing (nf p))))).

End TwoEffects.
Expand All @@ -214,13 +214,13 @@ Section ThreeEffects.
(Comb.Pos ND.Pos
(Comb.Pos Maybe.Pos Identity.Pos)).

Definition handleShareNDMaybe {A B : Type}
`{Normalform SShrNDMaybe PShrNDMaybe A B}
Definition handleShareNDMaybe {A : Type}
`{Normalform SShrNDMaybe PShrNDMaybe A}
(p : Free SShrNDMaybe PShrNDMaybe A)
: option (list B) :=
: option (list nType) :=
match (run (runMaybe (runChoice (runNDSharing (0,0) (nf p))))) with
| None => None
| Some t => Some (@collectVals B t)
| Some t => Some (@collectVals nType t)
end.

(* Maybe :+: Share :+: Trace :+: Identity handler *)
Expand All @@ -235,10 +235,10 @@ Section ThreeEffects.
(Comb.Pos Share.Pos
(Comb.Pos Trace.Pos Identity.Pos)).

Definition handleMaybeShareTrace {A B : Type}
`{Normalform SMaybeShrTrc PMaybeShrTrc A B}
Definition handleMaybeShareTrace {A : Type}
`{Normalform SMaybeShrTrc PMaybeShrTrc A}
(p : Free SMaybeShrTrc PMaybeShrTrc A)
: option B * list string :=
: option nType * list string :=
collectMessages (run (runTracing (runTraceSharing (0,0) (runMaybe (nf p))))).


Expand All @@ -254,10 +254,10 @@ Section ThreeEffects.
(Comb.Pos Maybe.Pos
(Comb.Pos Trace.Pos Identity.Pos)).

Definition handleNDMaybeTrc {A B : Type}
`{Normalform SNDMaybeTrc PNDMaybeTrc A B}
Definition handleNDMaybeTrc {A : Type}
`{Normalform SNDMaybeTrc PNDMaybeTrc A}
(p : Free SNDMaybeTrc PNDMaybeTrc A)
: (option (list B) * list string) :=
: (option (list nType) * list string) :=
let (val,log) := (collectMessages (run (runTracing (runMaybe (runChoice (nf p))))))
in match val with
| None => (None, log)
Expand All @@ -277,10 +277,10 @@ Section ThreeEffects.
(Comb.Pos ND.Pos
(Comb.Pos (@Error.Pos string) Identity.Pos)).

Definition handleShareNDError {A B : Type}
`{Normalform SShrNDErr PShrNDErr A B}
Definition handleShareNDError {A : Type}
`{Normalform SShrNDErr PShrNDErr A}
(p : Free SShrNDErr PShrNDErr A)
: list B + string
: list nType + string
:= match run (runError (runChoice (runNDSharing (0,0) (nf p)))) with
| inl t => inl (collectVals t)
| inr e => inr e
Expand All @@ -298,10 +298,10 @@ Section ThreeEffects.
(Comb.Pos Share.Pos
(Comb.Pos Trace.Pos Identity.Pos)).

Definition handleErrorShareTrace {A B : Type}
`{Normalform SErrShrTrc PErrShrTrc A B}
Definition handleErrorShareTrace {A : Type}
`{Normalform SErrShrTrc PErrShrTrc A}
(p : Free SErrShrTrc PErrShrTrc A)
: (B + string) * list string
: (nType + string) * list string
:= collectMessages (run (runTracing (runTraceSharing (0,0) (runError (nf p))))).

(* ND :+: Error :+: Trace :+: Identity handler *)
Expand All @@ -316,10 +316,10 @@ Section ThreeEffects.
(Comb.Pos (@Error.Pos string)
(Comb.Pos Trace.Pos Identity.Pos)).

Definition handleNDErrorTrace {A B : Type}
`{Normalform SNDErrTrc PNDErrTrc A B}
Definition handleNDErrorTrace {A : Type}
`{Normalform SNDErrTrc PNDErrTrc A}
(p : Free SNDErrTrc PNDErrTrc A)
: (list B + string) * list string
: (list nType + string) * list string
:= match collectMessages (run (runTracing (runError (runChoice (nf p))))) with
| (inl t, log) => (inl (collectVals t), log)
| (inr e, log) => (inr e, log)
Expand Down
4 changes: 2 additions & 2 deletions base/coq/Free/Instance/Identity.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(** * Definition of the identity monad in terms of the free monad. *)

From Base Require Import Free.
From Base Require Import Free.Instance.Comb.
From Base Require Import Free.Class.Injectable.
From Base Require Import Free.Monad.
From Base Require Import Free.Util.Void.

Module Identity.
Expand Down
2 changes: 1 addition & 1 deletion base/coq/Prelude/Bool.v
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ End SecBool.
(* Normalform instance for Bool *)

Instance NormalformBool (Shape : Type) (Pos : Shape -> Type)
: Normalform Shape Pos (Bool Shape Pos) (Bool Identity.Shape Identity.Pos)
: Normalform Shape Pos (Bool Shape Pos)
:= { nf' := pure }.

(* ShareableArgs instance for Bool *)
Expand Down
2 changes: 1 addition & 1 deletion base/coq/Prelude/Integer.v
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ End SecInteger.
(* Normalform instance for Integer *)

Instance NormalformInteger (Shape : Type) (Pos : Shape -> Type)
: Normalform Shape Pos (Integer Shape Pos) (Integer Identity.Shape Identity.Pos)
: Normalform Shape Pos (Integer Shape Pos)
:= { nf' := pure }.

(* ShareableArgs instance for Integer *)
Expand Down
Loading