Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1326 commits
Select commit Hold shift + click to select a range
805ff2b
Rename lookupE to lookupOperation.
robrix Apr 14, 2022
612a701
Rename lookupD to lookupDef.
robrix Apr 14, 2022
1390eff
Define a foldMapOfC combinator.
robrix Apr 14, 2022
b318139
Compose optics.
robrix Apr 14, 2022
5b1083a
Simplify lookupOperation.
robrix Apr 14, 2022
ce91172
Compose.
robrix Apr 14, 2022
286f44a
Avoid choice.
robrix Apr 14, 2022
e90dfb1
:fire: preview.
robrix Apr 14, 2022
84cfce0
:fire: some redundant constraints.
robrix Apr 14, 2022
0b8cda3
Remove the alternatives from ambiguous name errors for now.
robrix Apr 14, 2022
80a657f
Generalize resolveWith.
robrix Apr 14, 2022
c6844fd
resolveD doesn't return the name.
robrix Apr 14, 2022
c6ad1de
Rename resolveD to resolveDef.
robrix Apr 15, 2022
8f53491
FIXME.
robrix Apr 15, 2022
1d79a03
Define a module for pattern matrix columns.
robrix Apr 15, 2022
9515658
Define columns.
robrix Apr 15, 2022
c292f07
Define an iso for columns' contents.
robrix Apr 15, 2022
e53d9b4
Define a Semigroup instance for Column.
robrix Apr 15, 2022
570fcd6
Derive a Monoid instance for Column.
robrix Apr 15, 2022
4945a6d
Define a type synonym for row indices.
robrix Apr 15, 2022
dbac1eb
Define an Ixed instance for Column.
robrix Apr 15, 2022
f313cdd
Define an At instance for Column.
robrix Apr 15, 2022
243f16f
Define a singleton constructor for Column.
robrix Apr 15, 2022
aa2d3d7
Define a dense constructor for Column.
robrix Apr 15, 2022
355e6b2
Use the new Column definition in pattern elaboration.
robrix Apr 15, 2022
a887467
Multiple patterns.
robrix Apr 16, 2022
06c984d
Load some more files.
robrix Apr 16, 2022
215ecd4
Define a module for scopes.
robrix Apr 17, 2022
13191ba
Move Scope into its own module.
robrix Apr 17, 2022
f96987b
Lookup constructor indices by name.
robrix Apr 17, 2022
967e184
Define a Show instance for Column.
robrix Apr 17, 2022
3989108
Derive a Show instance for Clause.
robrix Apr 18, 2022
80a36b6
Export Clause.
robrix Apr 18, 2022
e9717b7
Define partitioning by constructors.
robrix Apr 18, 2022
67da56d
:fire: comp elaboration.
robrix Apr 18, 2022
130e7e5
Extract value patterns into a new type.
robrix Apr 19, 2022
7b79a65
:fire: Comp.
robrix Apr 19, 2022
f2cb5e3
:fire: Dict.
robrix Apr 19, 2022
078ec98
Define effect patterns.
robrix Apr 19, 2022
cf66e50
Derive.
robrix Apr 19, 2022
ab78f4c
Add effect patterns back in.
robrix Apr 20, 2022
54429f9
Add fields for Clause.
robrix Apr 20, 2022
be9a177
Lenses.
robrix Apr 20, 2022
733cd33
Pass clauses to checkLamS.
robrix Apr 20, 2022
f876154
Define an assertion for matching types.
robrix Apr 22, 2022
7a3d76f
Use assertTypesMatch.
robrix Apr 22, 2022
704a210
Rename Opaque to String.
robrix Apr 22, 2022
5a947fc
Rename :-> to Arrow and add fields.
robrix Apr 22, 2022
2a0bc24
:fire: some instances.
robrix Apr 22, 2022
914c044
Add quantifiers.
robrix Apr 22, 2022
6fe7641
:fire: unit types & patterns.
robrix Apr 22, 2022
edb8edb
Derive a Foldable instance for ..
robrix Apr 24, 2022
21301ad
Derive a Traversable instance for ..
robrix Apr 24, 2022
7e81d40
Split Sequent into separate classes.
robrix Apr 24, 2022
9a0d869
:fire: weakening in Context.
robrix Apr 24, 2022
cacd03c
:fire: Quantity from Context.
robrix Apr 24, 2022
612949b
:fire: quantities from lookups.
robrix Apr 24, 2022
7847fb2
:fire: usage from unification.
robrix Apr 24, 2022
6298085
:fire: a bunch of usages.
robrix Apr 24, 2022
70cff13
:fire: quantities on bound variables.
robrix Apr 24, 2022
3c7f5a7
:fire: quantities on bind.
robrix Apr 24, 2022
6568f7a
:fire: usages.
robrix Apr 24, 2022
aff9757
:fire: use.
robrix Apr 24, 2022
85f5f48
:fire: usage carriers.
robrix Apr 24, 2022
6523242
:fire: quantities.
robrix Apr 24, 2022
d35c27c
:fire: resource mismatch errors.
robrix Apr 24, 2022
0f80e7a
:fire: quantities from sequent types.
robrix Apr 24, 2022
3b76f70
:fire: the re-export of Quantity.
robrix Apr 24, 2022
6e8777b
:fire: Facet.Usage.
robrix Apr 24, 2022
bca0c67
:fire: the LeftModule instance for Snoc.
robrix Apr 24, 2022
5e038a8
:fire: Facet.Semiring.
robrix Apr 24, 2022
ba7f343
Define type contexts.
robrix Apr 24, 2022
934d8e9
Define a module for TypeContext.
robrix Apr 24, 2022
b7c39cc
Move TypeContext into its own module.
robrix Apr 24, 2022
a5fafd9
Define the empty type context.
robrix Apr 24, 2022
6570a4e
ElabContext carries a type context.
robrix Apr 24, 2022
2e9bff6
Separate type and term contexts.
robrix Apr 24, 2022
465575d
Fix an error for non-qualified names.
robrix Apr 24, 2022
9c2f0b9
Build first-order sequent terms.
robrix Apr 24, 2022
316fde8
:fire: the pattern elaboration contexts.
robrix Apr 24, 2022
bcac6c7
:fire: polarized syntax.
robrix Apr 24, 2022
cc08fad
Add the type context to errors.
robrix Apr 24, 2022
6748bc1
Print type contexts.
robrix Apr 24, 2022
339b121
:fire: the HOAS sequent stuff.
robrix Apr 24, 2022
a198ff0
Represent Context with Env.
robrix Apr 25, 2022
d4cbcf4
Spacing.
robrix Apr 25, 2022
0e67cfd
:memo: fill.
robrix Apr 25, 2022
ebe396f
Define a function to map & accumulate by iterating levels.
robrix Apr 25, 2022
18a41a1
Map accum from levels.
robrix Apr 25, 2022
d50d662
Map accum from levels.
robrix Apr 25, 2022
4654462
Define scopes for commands.
robrix Apr 25, 2022
ccb6609
Rename Scope to ScopeLR.
robrix Apr 25, 2022
c034e7f
Define an eliminator for ScopeLR.
robrix Apr 25, 2022
c66755c
Only export ScopeLR-the-type.
robrix Apr 25, 2022
f10a38c
Define a class for binding in the left context.
robrix Apr 25, 2022
2784f8a
Define a class for binding in the right context.
robrix Apr 25, 2022
86631c6
Avoid using LNames in types.
robrix Apr 25, 2022
798df81
Lift Printable to 2-functors.
robrix Apr 26, 2022
5666060
Define a Printable2 instance for pairs.
robrix Apr 26, 2022
1108fbd
Define a Printable2 instance for Either.
robrix Apr 26, 2022
7d182f3
Lift print through Printable2.
robrix Apr 26, 2022
13dbf1a
Define a Printable2 instance for :=:.
robrix Apr 26, 2022
a7f3e4d
Define a Printable instance for :=:.
robrix Apr 26, 2022
b8f2d60
Define a Printable instance for Name.
robrix Apr 26, 2022
828e92f
Don't use patterns in contexts.
robrix Apr 26, 2022
f2c82f5
Correct the instantiation types.
robrix Apr 26, 2022
9047b5d
Define left and right scopes parameterized by the command.
robrix Apr 26, 2022
3a4798e
Abstract over two variables at once.
robrix Apr 26, 2022
a781170
Specialize ScopeL/R to Command.
robrix Apr 26, 2022
2fbdb28
Define abstraction and instantiation over both sides of sequents.
robrix Apr 26, 2022
423b2c8
replace takes pairs of higher-order functions.
robrix Apr 26, 2022
f568fe9
Take the left index with the left functions.
robrix Apr 26, 2022
63cdf47
Replacement takes triples.
robrix Apr 26, 2022
ba3ed9a
Flip replacement.
robrix Apr 26, 2022
9c25a50
:fire: replace.
robrix Apr 26, 2022
b727ac5
Define a type of replacements.
robrix Apr 26, 2022
93a09b3
Define a lens for a replacer's index.
robrix Apr 26, 2022
4272cd7
Define a helper for free constructions.
robrix Apr 26, 2022
83b61f4
Define a helper for bound constructions.
robrix Apr 26, 2022
7612051
Replace using Replacers.
robrix Apr 26, 2022
ded46db
Replacers are optional.
robrix Apr 26, 2022
1e1e18c
Top-level abstraction & instantiation are optional.
robrix Apr 26, 2022
d8de534
Simplify the null/null cases.
robrix Apr 26, 2022
459bfe6
Flip abstractLR.
robrix Apr 26, 2022
c3867be
Flip instantiateLR.
robrix Apr 26, 2022
fdf9e71
Define one-sided abstract/instantiate.
robrix Apr 26, 2022
cf295b1
Define a smart constructor for MuR.
robrix Apr 26, 2022
8c9ba72
Define a smart constructor for LamR.
robrix Apr 26, 2022
dfd3490
:fire: LName.
robrix Apr 26, 2022
7dbfbca
Define gensym'd names.
robrix Apr 26, 2022
f7c8f48
Construct fresh names.
robrix Apr 26, 2022
f8f8c83
Fix a dodgy import, apparently.
robrix Apr 26, 2022
1be0fb9
Define a constructor for QName.
robrix Apr 26, 2022
1828155
Use the q constructor.
robrix Apr 26, 2022
216a952
:fire: an unused effect.
robrix Apr 26, 2022
f1850b9
Guard commands behind scopes.
robrix Apr 26, 2022
c95f09e
Wrap Let bodies up in Scopes.
robrix Apr 27, 2022
734a3e7
Define a smart constructor for Let.
robrix Apr 27, 2022
8634b17
abstractL/R always take values.
robrix Apr 27, 2022
74c863a
instantiateL/R always take values.
robrix Apr 27, 2022
e869286
Disallow pointless cases.
robrix Apr 27, 2022
a40b494
Define a lamR variant taking a term.
robrix Apr 27, 2022
a266d66
Generalize partitionBy.
robrix Apr 27, 2022
60b40b9
Idiomatic (:=:) -> (,) conversion.
robrix Apr 28, 2022
00acd1d
Fix a missing import.
robrix Apr 28, 2022
9784127
SumL maps constructor names to coterms.
robrix Apr 28, 2022
c1ff4f1
SumR maps a constructor name to a term.
robrix Apr 28, 2022
7cfbf21
:fire: BottomR.
robrix Apr 28, 2022
8fed5c2
Products are introduced n-arily.
robrix Apr 28, 2022
09e2ccf
:fire: UnitL/R.
robrix Apr 28, 2022
0dc37ec
Products are strict.
robrix Apr 28, 2022
fe7eedf
Record how many fields are in scope.
robrix Apr 28, 2022
bf7e231
Increment by the number of bound variables.
robrix Apr 28, 2022
1236a9d
Define a smart constructor for MuL.
robrix Apr 29, 2022
2ffdb0c
lamR' uses a single name.
robrix Apr 29, 2022
8ea371d
Give fixity for :|:.
robrix May 1, 2022
d6c6f25
Define a smart constructor for local variables.
robrix May 1, 2022
c99ce2b
Define a smart constructor for global variables.
robrix May 1, 2022
d5228ac
Define a smart constructor for local covariables.
robrix May 1, 2022
31b7699
lamS passes term & coterm along.
robrix May 2, 2022
5d361b8
Define a simple ND-style lambda constructor.
robrix May 2, 2022
a796528
Tacit.
robrix May 2, 2022
8aaf27e
:fire: parens.
robrix May 2, 2022
5dd1bea
Use the smart constructor.
robrix May 2, 2022
3b5ba4a
Right-associate binding.
robrix May 3, 2022
9738727
Define pattern compilation.
robrix May 7, 2022
f338a99
Scrutinees are names, not terms.
robrix May 7, 2022
979dd05
Clause is a Functor.
robrix May 7, 2022
f1a2ba0
Build lambdas.
robrix May 7, 2022
33d492f
Simplify lifting clause bodies into lambda bodies.
robrix May 7, 2022
e32819a
Simplify lamS.
robrix May 7, 2022
a7c3b35
FIXME.
robrix May 7, 2022
741a1fa
Assume.
robrix May 7, 2022
2b3dac1
Abbreviate elabWith.
robrix May 7, 2022
acbd1c0
Generalize case'.
robrix May 7, 2022
c4eeac0
:fire: an obsolete FIXME.
robrix May 7, 2022
ff45da2
Mismatches can be strings on both sides.
robrix May 8, 2022
8cb5dad
Throw a proper error when a neutral type doesn't reference a datatype.
robrix May 8, 2022
3284bd2
Define a debugging runner for sequents.
robrix May 8, 2022
97f5227
Products are eliminated by a coterm.
robrix May 8, 2022
62100e0
Define a bound variable constructor.
robrix May 8, 2022
61b261f
Define a bound covariable constructor.
robrix May 8, 2022
22ab8fa
Define Print instances for sequents.
robrix May 8, 2022
a55a169
Rename the free (co)variable smart constructors.
robrix May 8, 2022
b31fd61
Rename the free (co)variable elaborators.
robrix May 8, 2022
35f8f3b
Swap the variable names to indicate ordering.
robrix May 8, 2022
f6dcd35
Define an IsString instance for Term.
robrix May 8, 2022
99b96c2
Define an IsString instance for Coterm.
robrix May 8, 2022
cb67f23
Replace the optics on These.
robrix May 8, 2022
49db7ad
Run a Throw handler.
robrix May 8, 2022
9942795
Derive Show instances for Exp & Act.
robrix May 8, 2022
cf078ec
Derive Show instances for error reasons.
robrix May 8, 2022
d1d241c
Derive a Show instance for Synth.
robrix May 8, 2022
8489ff1
Derive Show instances for sequents.
robrix May 8, 2022
1f0d90b
Export switch.
robrix May 8, 2022
2903c3d
Define a smart constructor for kind arrows.
robrix May 9, 2022
409ecfe
Define a smart constructor for type arrows.
robrix May 9, 2022
4ca6626
Define a smart constructor for QName.
robrix May 9, 2022
eaabea0
Simplify unit construction.
robrix May 9, 2022
27df986
Simplify unit module references.
robrix May 9, 2022
5bca444
Use the QName smart constructor.
robrix May 9, 2022
73f8861
Construct QNames from Names using q.
robrix May 9, 2022
ccc33ff
Define an eliminator for QNames.
robrix May 9, 2022
5b15eda
Construct QNames using //.
robrix May 9, 2022
2766920
Avoid referencing NonEmpty snocs for QName.
robrix May 9, 2022
fd2e491
Redefine QName as a newtype.
robrix May 9, 2022
a83975f
Define a Pretty instance for QName.
robrix May 9, 2022
051922a
Define a Show instance for Op.
robrix May 9, 2022
a5c978b
Define a generalized version of subscript.
robrix May 9, 2022
2a62352
Define subscript in terms of subscriptWith.
robrix May 9, 2022
aed78a2
Define a Show instance for Name.
robrix May 9, 2022
a4b1292
Define a Show instance for QName.
robrix May 9, 2022
49f2410
Define an IsList instance for Scope.
robrix May 9, 2022
0d59645
Define a helper for running actions with These in scope.
robrix May 9, 2022
a12fe8b
Export checkLamS.
robrix May 9, 2022
975f0aa
Check recursively.
robrix May 9, 2022
e3e688d
Correct lamS' variable occurrences.
robrix May 9, 2022
1c0a3e7
Correct the ordering of the final lambda's params.
robrix May 9, 2022
48f95c2
Allow resolveWith to produce multiple names.
robrix May 9, 2022
69ef8e3
Add the alternatives back to ambiguous name errors.
robrix May 9, 2022
0b1f78e
Derive a Functor instance for Notice.
robrix May 9, 2022
6544a4a
Print error reasons in Print.
robrix May 9, 2022
15f96e2
Solve spurious ambiguity.
robrix May 9, 2022
281bc13
Customize the Show instance for Type to show its own constructors pro…
robrix May 9, 2022
d5b3dc9
Qualify sum names.
robrix May 10, 2022
dab93a0
Specialize the error case a bit.
robrix May 10, 2022
60c7d3a
Spacing.
robrix May 10, 2022
494a034
Avoid trailing commas.
robrix May 10, 2022
d8a953c
Show variables nicely.
robrix May 10, 2022
5740fe2
Show foldables the same way.
robrix May 10, 2022
a839856
Apply precedence correctly.
robrix May 10, 2022
518b02d
Show tacit arrows nicely.
robrix May 10, 2022
f18cb05
Use uppercase variables.
robrix May 10, 2022
51fbc0a
Show spines as applications.
robrix May 10, 2022
2f54c66
Don't parenthesize atoms.
robrix May 10, 2022
d7e5aa3
Decompose foralls.
robrix May 10, 2022
2bd99cb
Don't make recursive calls without clauses.
robrix May 10, 2022
1941110
Build a µ abstraction for the last leg.
robrix May 10, 2022
eb4657a
Correct the printing of applications.
robrix May 10, 2022
3f653f0
Increment both counters.
robrix May 10, 2022
71dd32d
Bind the final continuation in the context.
robrix May 10, 2022
1a76121
Share a single counter.
robrix May 10, 2022
1c41496
Distinguish local QNames.
robrix May 10, 2022
f4a00eb
Discard pointless µ̃-abstractions.
robrix May 10, 2022
bc9acde
Use the right-abstraction.
robrix May 10, 2022
27bf2c8
µ-left abstractions provide synths.
robrix May 10, 2022
2be7fef
Define a combinator for µ-right abstractions.
robrix May 10, 2022
0e69ba4
:fire: some foldls.
robrix Feb 16, 2025
df96da0
Merge branch 'main' into condictuationary-passing-style
robrix Feb 16, 2025
9d38ee7
Typo.
robrix Feb 17, 2025
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
4 changes: 3 additions & 1 deletion .ghci.repl
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
-- 8.10+
:seti -Wno-missing-safe-haskell-mode
:seti -Wno-prepositive-qualified-module
-- 9.2+
:seti -Wno-missing-kind-signatures

-- We have this one on in the project but not in the REPL to reduce noise
:seti -Wno-type-defaults
:set -Wno-unused-packages

:load Facet.CLI test/Test.hs
:load Facet.CLI Facet.Elab.Sequent test/Test.hs

import Facet.Parser
import Facet.Print
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ghc: ["8.10.4"]
cabal: ["3.2.0.0"]
ghc: ["8.10", "9.2"]

steps:
- uses: actions/checkout@v2
if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/main'

- uses: actions/setup-haskell@v1.1.4
- uses: haskell/actions/setup@v1
name: Setup Haskell
with:
ghc-version: ${{ matrix.ghc }}
Expand Down
1 change: 1 addition & 0 deletions .hlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- ignore: {name: Use camelCase}
12 changes: 10 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ _Caveat lector: there are no guarantees of correctness or completeness on the co

- Ideally, emit DWARF data.

- Type patterns, for use with type lambdas & probably quantifiers.

- Dictionary patterns, to bind the operations of an effect interface in the scope of a handler.


### Surface

Expand Down Expand Up @@ -144,11 +148,15 @@ _Caveat lector: there are no guarantees of correctness or completeness on the co

### Elaborator

- Emit warnings.
- Emit warnings.

- Continue after errors on a declaration-by-declaration basis.

- Add entire composite patterns to contexts. One entry for the whole pattern at type A, with sub-entries for each sub-pattern at decomposed types.
- ✅ Add entire composite patterns to contexts. One entry for the whole pattern at type A, with sub-entries for each sub-pattern at decomposed types.

- `Level`/`Level` pairs could be represented as `Ratio`s.

- Distinguish between the `Level` a variable was bound and the `Level` of the place it’s being inserted at the type level using `newtype`s.


### Pretty-printer
Expand Down
441 changes: 441 additions & 0 deletions docs/elaboration.md

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions docs/handlers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Handlers

Handlers have the general form:

handle : C̅ -> [E̅] A -> B

Typically, `A` will be parametric, and `B` can be viewed as a function of `A` and the context type(s) `C̅`. We will call `A` the incremental return type—that is, the return type of the action—and `B` the eventual return type—the return type of the handler itself.


Handlers are defined by providing a list of clauses for the constructors in `E̅` and a list of clauses for non-effect values at type `A`. The former define a dictionary for `E̅`, and the latter define a continuation with which to run the body. Ignoring for the moment any context arguments of type `C̅`, that gives us:

{ [o̅ x̅ ; k̅] -> b̅
, a̅ -> b̅ }

where

o̅ : X̅ -> X′
x̅ : X̅
k̅ : X′ -> [E̅] A
a̅ : A
b̅ : B

Note that since `k̅` returns in `[E̅] A`, clauses which use the continuation must call the handler recursively on the result. The sole exception is that if `B` is `[E̅] A`, they can technically call the continuation without calling the handler recursively. Note however that this would be _extremely_ strange as it would amount to handling only the first operation within an effect and allowing the remainder to be handled by the calling context.

For example, we have the following types for the operations of `State S`, `Reader R`, and `Empty`:

```facet
# State S
get : [State S] S
put : S -> [State S] Unit

# Reader R
ask : [Reader R] R
local : {X : Type} -> (R -> R) -> [Reader R] X -> [Reader R] X

# Empty
empty : {X : Type} -> [Empty] X
```

Note that all of these return computation types.

Translating them into CPS yields:

```facet
# State S
get : (S -> [State S] A) -> B
put : S -> (Unit -> [State S] A) -> B

# Reader R
ask : (R -> [Reader R] A) -> B
local : {X : Type} -> (R -> R) -> [Reader R] X -> (X -> [Reader R] A) -> B

# Empty
empty : {X : Type} -> [Empty] X
```


Scoped operations like `local` and `catch` themselves contain `E̅`-actions.


Handlers must be able to:

1. return a value of type `B` directly, without calling the continuation `k`. This implies that the type of handlers must not be universally quantified with respect to its eventual return type.

2. return a value of type `X′` by calling the continuation `k`, thus producing a result of type `A` with effects in `E̅`, which it must therefore handle by calling itself recursively.
52 changes: 37 additions & 15 deletions facet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -70,88 +70,109 @@ common common
library
import: common
exposed-modules:
Facet.Carrier.Error.Lens
Facet.Carrier.CallStack.Stack
Facet.Carrier.Error.Optic
Facet.Carrier.Output.IO
Facet.Carrier.Parser.Church
Facet.Carrier.Profile.Flat
Facet.Carrier.Profile.Identity
Facet.Carrier.Profile.Tree
Facet.Carrier.Readline.Haskeline
Facet.Carrier.State.Lens
Facet.Carrier.State.Optic
Facet.Carrier.Throw.Inject
Facet.Carrier.Time.System
Facet.Carrier.Write.General
Facet.Carrier.Write.Inject
Facet.CLI
Facet.Context
Facet.Core.Module
Facet.Core.Pattern
Facet.Core.Term
Facet.Core.Type
Facet.Diff
Facet.Driver
Facet.Effect.CallStack
Facet.Effect.Parser
Facet.Effect.Profile
Facet.Effect.Readline
Facet.Effect.Time
Facet.Effect.Time.System
Facet.Effect.Write
Facet.Elab
Facet.Elab.Sequent
Facet.Elab.Term
Facet.Elab.Type
Facet.Env
Facet.Eval
Facet.Flag
Facet.Format
Facet.Functor.Check
Facet.Functor.Compose
Facet.Functor.Synth
Facet.Graph
Facet.Interface
Facet.Kind
Facet.Lens
Facet.Lexer
Facet.Module
Facet.Name
Facet.Norm
Facet.Notice
Facet.Notice.Elab
Facet.Notice.Parser
Facet.Parser
Facet.Parser.Table
Facet.Pattern
Facet.Pattern.Column
Facet.Pretty
Facet.Print
Facet.Print.Options
Facet.Quote
Facet.REPL
Facet.REPL.Parser
Facet.Run
Facet.Scope
Facet.Semialign
Facet.Semiring
Facet.Sequent.Expr
Facet.Sequent.Pattern
Facet.Sequent.Type
Facet.Snoc
Facet.Snoc.NonEmpty
Facet.Source
Facet.Source.Reference
Facet.Span
Facet.Style
Facet.Subst
Facet.Surface
Facet.Surface.Module
Facet.Surface.Term.Expr
Facet.Surface.Type.Class
Facet.Surface.Type.Expr
Facet.Syntax
Facet.Term.Class
Facet.Term.Expr
Facet.Term.Norm
Facet.Timing
Facet.Type.Class
Facet.Type.Expr
Facet.Type.Norm
Facet.TypeContext
Facet.Unify
Facet.Usage
Facet.Vars
other-modules:
Paths_facet
autogen-modules:
Paths_facet
build-depends:
, ansi-terminal
, base >= 4.14 && < 4.21
, base >= 4.14 && < 5
, charset
, colour
, containers
, directory
, exceptions ^>= 0.10
, filepath
, fresnel
, fused-effects
, fused-effects-lens
, haskeline ^>= 0.8.1
, lens
, optparse-applicative
, parsers
, prettyprinter
, profunctors
, semialign
, silkscreen
, terminal-size
Expand All @@ -178,8 +199,9 @@ test-suite test
, facet
, hedgehog ^>= 1.5
, parsers
ghc-options:
-Wno-missing-signatures
if (impl(ghc >= 9.2))
ghc-options:
-Wno-missing-signatures


executable facetc
Expand Down
6 changes: 6 additions & 0 deletions lib/Effect/Empty.facet
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ module Effect.Empty : Module

import Data.Bool
import Data.Function
import Data.Option
import Data.Unit

interface Empty : Interface
{ empty : { A : Type } -> A }

guard : (c : Bool) -> [Empty] Unit
{ if c id { (unit) -> empty } }


toOption : {A : Type} -> [Empty] A -> Option A
{ [empty ; _] -> none
, a -> some a }
5 changes: 3 additions & 2 deletions script/ghci-flags
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ function flags {
echo "-Wno-name-shadowing"
echo "-Wno-safe"
echo "-Wno-unsafe"
[[ "$ghc_version" = 8.8.* ]] || [[ "$ghc_version" = 8.10.* ]] && echo "-Wno-missing-deriving-strategies" || true
[[ "$ghc_version" = 8.10.* ]] && echo "-Wno-missing-safe-haskell-mode" && echo "-Wno-prepositive-qualified-module" && echo "-Wno-unused-packages"
[[ "$ghc_version" = 8.8.* ]] || [[ "$ghc_version" = 8.10.* ]] || [[ "$ghc_version" = 9.2.* ]] && echo "-Wno-missing-deriving-strategies" || true
[[ "$ghc_version" = 8.10.* ]] || [[ "$ghc_version" = 9.2.* ]] && echo "-Wno-missing-safe-haskell-mode" && echo "-Wno-prepositive-qualified-module" && echo "-Wno-unused-packages"
[[ "$ghc_version" = 9.2.* ]] && echo "-Wno-missing-kind-signatures"

echo "-XDeriveTraversable"
echo "-XDerivingStrategies"
Expand Down
10 changes: 0 additions & 10 deletions script/ghci-flags-dependencies

This file was deleted.

25 changes: 25 additions & 0 deletions src/Facet/Carrier/CallStack/Stack.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE UndecidableInstances #-}
module Facet.Carrier.CallStack.Stack
( -- * CallStack carrier
runCallStack
, CallStackC(..)
-- * CallStack effect
, module Facet.Effect.CallStack
) where

import Control.Algebra
import Control.Carrier.Reader
import Facet.Effect.CallStack

runCallStack :: CallStackC m a -> m a
runCallStack = runReader [] . runCallStackC

newtype CallStackC m a = CallStackC { runCallStackC :: ReaderC Stack m a }
deriving (Applicative, Functor, Monad)

instance Algebra sig m => Algebra (CallStack :+: sig) (CallStackC m) where
alg hdl sig ctx = CallStackC $ case sig of
L (Push l s m) -> local ((l, s):) (runCallStackC (hdl (m <$ ctx)))
L CallStack -> asks (<$ ctx)
R other -> alg (runCallStackC . hdl) (R other) ctx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE UndecidableInstances #-}
module Facet.Carrier.Error.Lens
module Facet.Carrier.Error.Optic
( -- * Error carrier
runError
, ErrorC(..)
Expand All @@ -11,17 +11,21 @@ module Facet.Carrier.Error.Lens
import Control.Algebra
import Control.Carrier.Reader
import Control.Effect.Error
import Control.Lens (APrism', withPrism)
import Control.Monad.IO.Class
import Fresnel.Prism (Prism', matching)
import Fresnel.Review (review)

runError :: APrism' e f -> ErrorC e f m a -> m a
runError prism (ErrorC m) = runReader prism m
runError :: Prism' e f -> ErrorC e f m a -> m a
runError prism (ErrorC m) = runReader (APrism' prism) m

newtype ErrorC e f m a = ErrorC (ReaderC (APrism' e f) m a)
deriving (Applicative, Functor, Monad, MonadFail, MonadIO)

instance Has (Error e) sig m => Algebra (Error f :+: sig) (ErrorC e f m) where
alg hdl sig ctx = ErrorC $ ReaderC $ \ prism -> case sig of
L (L (Throw e)) -> throwError (withPrism prism (\ review _ -> review e))
L (R (Catch m h)) -> runError prism (hdl (m <$ ctx)) `catchError` \ e -> withPrism prism (\ _ preview -> either throwError (runError prism . hdl . (<$ ctx) . h) (preview e))
alg hdl sig ctx = ErrorC $ ReaderC $ \ (APrism' prism) -> case sig of
L (L (Throw e)) -> throwError (review prism e)
L (R (Catch m h)) -> runError prism (hdl (m <$ ctx)) `catchError` \ e -> either throwError (runError prism . hdl . (<$ ctx) . h) (matching prism e)
R other -> alg (runError prism . hdl) other ctx


newtype APrism' s a = APrism' (Prism' s a)
6 changes: 4 additions & 2 deletions src/Facet/Carrier/Parser/Church.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,22 @@ import Control.Algebra
import Control.Effect.Cut
import Control.Effect.NonDet
import Control.Effect.Throw
import Control.Lens (Lens', lens, (%~), (&), (.~))
import Control.Monad (ap)
import Control.Monad.Fail as Fail
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Data.Coerce (coerce)
import Data.Function ((&))
import Data.Functor.Compose
import Data.Functor.Identity
import Data.List.NonEmpty (NonEmpty(..))
import Data.Set (Set, singleton)
import Facet.Effect.Parser
import Facet.Source as Source
import Facet.Span as Span
import Fresnel.Lens (Lens', lens)
import Fresnel.Setter ((%~), (.~))
import Text.Parser.Char (CharParsing(..))
import Text.Parser.Combinators
import Text.Parser.Token (TokenParsing)
Expand All @@ -55,7 +57,7 @@ runParserWithFile path p = do
{-# INLINE runParserWithFile #-}

runParserWithSource :: Has (Throw (Source, Err)) sig m => Source -> ParserC m a -> m a
runParserWithSource src@(Source _ _ _ (Line line _ _:|_)) = runParser (const pure) failure failure input
runParserWithSource src@(Source _ _ (Line line _ _:|_)) = runParser (const pure) failure failure input
where
input = Input (Pos line 0) (contents src)
failure = throwError . (,) src
Expand Down
Loading
Loading