Commit Graph

311 Commits

Author SHA1 Message Date
TheMatten
4fe424cfce Merge https://github.com/isovector/polysemy 2019-07-07 17:35:50 +02:00
Sandy Maguire
faaf1e3a96
Don't use Loopbreaker until GHC 8.7+ (#164)
Turns out haddocks have been broken forever, but because of haskell/cabal#5977 we never noticed. This PR fixes CI so it breaks (see 6f915b6), and then fixes it by changing the GHC versions under which we're allowed to use loopbreaker. Fixes #160
2019-07-07 11:27:18 -04:00
Sandy Maguire
9f3a476afd
Rename Yo ==> Weaving (#162)
The name Yo is objectively terrible. I changed it, and added some documentation.
2019-07-06 09:16:07 -04:00
Sandy Maguire
f259f8ae78
Cleanup and document fundep plugin (#155)
I made the code style agree with the rest of the codebase, and I wrote down everything I know about how this works.
2019-07-05 14:14:45 -04:00
TheMatten
1786925e72 Merge https://github.com/isovector/polysemy 2019-07-05 20:05:27 +02:00
Sandy Maguire
83c1c20242 Release polysemy-plugin-0.2.2.0 2019-07-04 22:06:19 -04:00
Sandy Maguire
082ed39e85 Release polysemy-0.6.0.0 2019-07-04 22:05:51 -04:00
Silvan Mosberger
210d8d6a35 Improve runBatchOutput (#158)
This function now transforms an Output o into Output [o], which only outputs elements once the specified number of o's have been collected. The only exception is the last element which contains the rest (if any).
2019-07-04 18:27:13 -04:00
Sandy Maguire
9e586eaeab
Redefine Type.Errors directly in polysemy (#153)
Fixes #152
2019-07-04 16:09:36 -04:00
TheMatten
e3ab51b2bd Merge https://github.com/isovector/polysemy 2019-07-04 20:50:48 +02:00
Sandy Maguire
ef5ff1749a
Don't emit ambiguous effect errors for genuine type errors (#149)
This PR changes the plugin so it will notice an insoluble constraint of the form Sem r a ~ Foo, and mark that r takes part in a genuine type error. The plugin will then provide a bogus evidence term for IfStuck (IndexOf r _) _ _, which prevents the AmbiguousSend error message from firing.
2019-07-04 09:35:33 -04:00
Sandy Maguire
d9dab9fa6a
Implement runEmbedded (#148)
runEmbedded lets you interpret a `Lift m` via some `forall x. m x -> IO
x` by pretending all the other polysemy actions are in IO and using its
MonadIO instance.
2019-07-04 07:45:40 -04:00
Sandy Maguire
72e060ac79
Parenthesize r when it's a cons (#147)
When emitting messages for ambiguous sends: use `IfStuck` on `r` to
determine if we can compose it. This means `r` is in one of three
states, stuck, cons or nil. We want to wrap it in parentheses iff it's
a cons.
2019-07-04 07:45:09 -04:00
Sandy Maguire
13fc3a1649
Remove some loopbreakers that were left around (#150) 2019-07-04 07:43:14 -04:00
Sandy Maguire
482de98afe
Use type-errors for our type errors! (#144)
This PR has farmed out the type error machinery out to my new package https://github.com/isovector/type-errors. It's much nicer to work with, and a big red diff!
2019-07-03 16:05:51 -04:00
TheMatten
8bbd9dc7d6 Use new, separate loopbreaker library for inlining (#145)
* Remove explicit loopbreakers, enable plugin

* Use uploaded version of `loopbreaker`

* Fix span of macro

* Disable plugin on GHC <8.6

* Add comment about use of plugin

* Separate unrelated conditions
2019-07-01 02:13:37 -04:00
Sandy Maguire
d82d48cdf6
Improved errors (#143)
This shuffles around the error messages so they are only connected to code generated via makeSem. This means that badly-typed interpreters will no longer set off the eager error messages!
2019-06-29 23:37:56 -04:00
Georgi Lyubenov
5bc01e0af6 Add runOutputAsList and a test for it (#140)
* Add runOutputAsList and a test for it

* Also use runOutputAsList in runTraceAsList
2019-06-29 17:40:56 -04:00
Sandy Maguire
8bd297fe49 Release polysemy 0.5.1.0 2019-06-28 16:19:33 -04:00
Sandy Maguire
77fd10494a
New error combinators (#138)
Introduction of `fromEither` and `fromEitherM`
2019-06-28 16:18:00 -04:00
Sandy Maguire
162d0cdf5b World's Better Logo 2019-06-27 02:51:36 -04:00
Sandy Maguire
01df83c6b7 Merge branch 'master' of github.com:isovector/polysemy 2019-06-27 00:37:16 -04:00
Sandy Maguire
4d360445ed Release polysemy 0.5.0.1 2019-06-27 00:36:43 -04:00
Sandy Maguire
e4b711a1ed
Fix intercept not hoisting itself into embedded computations (#134)
Fixes #133
2019-06-27 00:35:52 -04:00
Sandy Maguire
d2c8131cb8 Fix plugin badge 2019-06-26 10:23:06 -04:00
Sandy Maguire
6ca5b4f428 Release polysemy-plugin-0.2.1.1 2019-06-26 10:21:15 -04:00
Sandy Maguire
008a152097 hpack or cabal (or both) is a janky POS 2019-06-26 00:43:10 -04:00
Sandy Maguire
a2e39776ce Release polysemy 0.5.0.0 2019-06-26 00:29:26 -04:00
Sandy Maguire
33a6d95dab
runResource via forklift (#130)
This PR adds `runResourceBase` (which is a crap name, but naming things is hard), which interprets `Resource` without the ugly `Sem r ~> IO` parameter. It's a nice solution to #84!
2019-06-26 00:08:55 -04:00
Sandy Maguire
8f3a4bcf19
Async effect (#129)
Here's an Async effect that does exactly what you'd expect.

Fixes #80
2019-06-26 00:01:12 -04:00
Sandy Maguire
2654d35066
Forklift interpretations (#128)
This PR provides a single function withLowerToIO, which runs a desired Sem r effect all the way down to IO, without needing to know the natural transformation beforehand. It does it by running the desired code in a new thread, and shipping all of the unhandled effects back to the main thread. The main thread turns into an event loop for the duration of the withLowerToIO block.
2019-06-25 23:46:54 -04:00
Vladimir Semyonov
585aeb1224 Better runMonadicInput type order (#122) (#131) 2019-06-25 17:42:23 -04:00
Sandy Maguire
dc1489297a Fix build badge 2019-06-24 17:05:14 -04:00
TheMatten
2aa63ecc6c
Merge upstream 2019-06-20 21:37:04 +02:00
Sandy Maguire
29216ceb69
Improve CI coverage -- now on GHC 8.4! (#39) 2019-06-19 17:25:37 -04:00
Sandy Maguire
aab9cbccff
Faster hoist, cleaned up Union (#120)
After the clean up in #118, I realized that we no longer need to define hoist in terms of weave. This should save some allocations. After that, I realized it was sort of stupid to keep all of the *Yo functions around. Literally nobody should call them, so I just inlined them into the Union versions.

Red diffs, yeah!
2019-06-18 21:48:09 -04:00
Sandy Maguire
c3d3cc24f8
Stop using stack in Travis (#121)
The travis cache appears to be broken (probably due to the nightly stack?), but it just means CI takes like half an hour now. Since I already build on stack, I'm pretty sure it's fine --- also this will give a sanity check against accidentally breaking cabal build plans.

This improves CI times from ~30 minutes down to ~2.
2019-06-18 12:36:38 -04:00
Sandy Maguire
78d0c4905a
Split out effect lib (#83)
This PR teases apart the reusable pieces of the current TH machinery. Doing so allows us to build other TH abstractions in polysemy --- such as an RPC effect.
2019-06-18 12:23:27 -04:00
Sandy Maguire
6ffb4fd282
Remove Effect class (#118)
This thing was a vestige of the bad old days when you had to write
*instances* of classes things in Polysemy. It was a terrible experience,
and so we don't do that anymore. As a result, the only two instances of
`Effect` were for `Union` and `Yo` --- so I just inlined them.
2019-06-17 15:16:28 -04:00
Sandy Maguire
b23f7d2561
Simplify the CI (#119)
This PR removes some things in the travis CI that I cargo culted and
didn't understand but am reasonably sure don't do anything except slow
down CI times.
2019-06-17 15:15:13 -04:00
Sandy Maguire
6c1a6575bb Add kind synonyms for effects and effect rows
Fixes #116
2019-06-17 12:47:58 -04:00
TheMatten
a92d7fd328
Merge upstream 2019-06-17 10:25:56 +02:00
Sandy Maguire
bba49aaeb8
Don't emit the FirstOrder error for unknown effects (#115)
This PR introduces the FCF machinery that will give us more control over writing type-level functions. It defines an IfStuck a b c tyfam that will leave b around if a is stuck, otherwise it will fcf-evaluate c. Everything is polykinded so we can stack these things together to make big logic chains to emit specific variables depending on what exactly is stuck.
2019-06-16 17:14:36 -04:00
Sandy Maguire
0a1ce2b837 Add hspec-discover to package build-tools
Fixes #111
2019-06-15 20:12:18 -04:00
Sandy Maguire
82f86add29
Custom type error testing (#113)
This PR adds doctests allowing us to write tests for the custom type errors. Having this stuff reified in the test suite means we can iterate on the implementations and give much better QA.
2019-06-15 20:04:11 -04:00
Sandy Maguire
b5d086b859 Release polysemy-plugin 0.2.1.0 2019-06-14 11:38:47 -04:00
Sandy Maguire
e90c745d7a
Allow bidirectional typechecking in the plugin (#105)
* Allow bidirectional typechecking in the plugin

The plugin used to choke on this:

```haskell
flipShouldBe 11 . sum . fst . run . runFoldMapOutput id $ do
  output [1]
  output $ replicate 2 5
```

because it would fail to unify `Output (t Int)` (the polymorphic
`Traversable` variable in `sum`) with `Output [Int]`.

In this case, there are no given constraints, so the plugin is
attempting to solve a `Member (Output (t Int)) '[Output [Int]]`. We
reuse the codepath for unifying wanted/givens, pretending like the
`Output (t Int)` is a given.[^1]

[^1]: Pretending it's a wanted breaks something else that I don't
remember right now. This code is brittle :(

So now we have a "wanted" `Output [Int]`, and a "given" `Output (t
Int)`. In general, this thing isn't OK to solve. Consider a real
example:

```haskell
foo :: Member (Output (t Int)) r => Sem r ()
foo = output [5]
```

This is a type error, because the polymorphism goes the wrong way. We
have no guarantees that `t` is supposed to be `[]`.

But in our original example, this isn't a problem, because our `t` isn't
actually in given position. It's just an artifact of reusing the code!
`mkWanted` now takes a new parameter for whether or not it's OK to allow
the givens to be polymorphic.

Such a thing necessitates a change though. We never want to unify
a polymorphic *effect* in given position. Doing so will break Haskell's
regular type inference that determines what the effect row should be,
based on the order in which the interpreters are run.
2019-06-14 11:28:14 -04:00
Sandy Maguire
18e16f68db Release polysemy-plugin 0.2.0.3 2019-06-13 15:39:57 -04:00
Sandy Maguire
fc88a961ad
Ensure wanted constraints are emitted only once. (#102)
* Ensure wanted constraints are emitted only once.

This is a fix for the "solveSimpleWanteds: too many iterations" problem
that people are running into. In these cases, the plugin is being asked
to solve the same `Member` constraint several times, and generating
a new wanted each time. In doing so, GHC thinks that work was done, so
it will ask the plugin to run again next time. This process diverges,
and produces the error.

Fixes #79
2019-06-13 14:39:49 -04:00
Sandy Maguire
416530b149
Use tySynInstDCompat for future compatibility with TH (#101)
Fixes #99
2019-06-12 11:45:26 -04:00