Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add effectful-th package #56

Closed
wants to merge 11 commits into from
Closed

Conversation

mmhat
Copy link
Contributor

@mmhat mmhat commented Feb 3, 2022

This PR adds a new package effectful-th including a TH function makeSendFunctions that generates functions for the effect operations of dynamic effects (See the OP of #20).

The test suite included just checks if the generated functions for the dynamic effects defined in effectful-core compile.

@mmhat
Copy link
Contributor Author

mmhat commented Feb 4, 2022

@arybczak I think this one can be reviewed and merged. 🙂

@mmhat mmhat changed the title Added effectful-th package Add effectful-th package Feb 4, 2022
Copy link
Member

@arybczak arybczak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Do other packages have more tests for a bit more "weird" effect data types that can be added?

For example, I wonder if this works: polysemy-research/polysemy#339

@@ -0,0 +1,238 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you replace this with TemplateHaskellQuotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately that is not possible. Changing that to TemplateHaskellQuotes results in:

src/Effectful/TH.hs:156:40: error:
    Operator applied to too few arguments: :>
    |
156 |       effectConstraint = [t| $(effect) :> $(varT es) |]
    |

Copy link
Member

@arybczak arybczak Feb 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires getting rid of splices, but it should be possible as you can construct the AST manually. FWIW optics-th uses TemplateHaskellQuotes only. This matters for cross-compilation.

effectful-th/src/Effectful/TH.hs Outdated Show resolved Hide resolved
, setMakeFunctionFor
, setToFunctionName

-- * Re-exports
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the re-exports?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I included them for slightly better ergonomics: This way one can just import Effectful.TH and is not confronted with a bunch of "... not in scope" error messages immediately.

effectful-th/src/Effectful/TH.hs Show resolved Hide resolved
effectful-th/effectful-th.cabal Outdated Show resolved Hide resolved
effectful-th/effectful-th.cabal Outdated Show resolved Hide resolved
@mmhat
Copy link
Contributor Author

mmhat commented Feb 9, 2022

Unfortunately the current implementation does not work well with "weird" effects.
This module is build around th-abstraction - which is just too much abstraction to support these types.
In particular, both

data T1 a where
  C1 :: forall a b. T1 a

data T2 a where
  C2 :: forall b a. T2 a

are reified to something like:

DatatypeInfo { ..., datatypeVars = [KindedTV a () StarT], ..., datatypeCons = [ConstructorInfo {..., constructorVars = [KindedTV b () StarT], ...}]}

Note the order of the type variables of the explicit forall is completely lost and we cannot figure out how to construct the type applications at the call site.

I will think about a more elaborate solution using template-haskell directly.

@arybczak
Copy link
Member

I wouldn't worry about that, it's better to use th-abstraction as that eases maintenance burden, direct template-haskell breaks too often.

@mmhat
Copy link
Contributor Author

mmhat commented Feb 10, 2022

I wouldn't worry about that, it's better to use th-abstraction as that eases maintenance burden, direct template-haskell breaks too often.

That's why I chose it in the first place 🙂
However, the example given in polysemy-research/polysemy#339 will not work since it requires an extra type application of the ty variable and I don't know (yet) how to get this right.

I propose the following: Unless I find a clear path forward throughout the next days will push some more documentation regarding known limitations and we can merge this (I will of course address the remaining issues first). If we figure out a way to improve the module in this regard it can happen on a separate PR.

@arybczak arybczak mentioned this pull request Feb 19, 2022
@arybczak
Copy link
Member

I think I'll go with #60. The code is trivially ported from cleff.

@arybczak
Copy link
Member

Superseded by #60, thanks for the work though!

@arybczak arybczak closed this Feb 22, 2022
@mmhat mmhat deleted the effectful-th branch February 23, 2022 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants