Comments (11)
IIRC, persistent
breaks all of the Template Haskell helpers out into a separate package (persistent-template
) to avoid the additional dependency and associated initial compile time hit of the template-haskell
package.
Seems like that might be a best-of-both-worlds situation, and would be in line with fused-effects-lens
and fused-effects-exceptions
, so that people could opt-in for the added convenience.
from fused-effects.
It was pretty trivial to patch Ed Kmett's implementation to work with my effects, the diff is here if you're interested:
@@ -38,6 +34,7 @@ import Data.Char (toLower)
import Data.List ((\\), nub)
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
+import Generics.SYB
#if !(MIN_VERSION_base(4,8,0))
import Control.Applicative
@@ -191,13 +188,19 @@ extractVars (ParensT x) = extractVars x
extractVars _ = []
liftCon' :: Bool -> [TyVarBndr] -> Cxt -> Type -> Type -> [Type] -> Name -> [Type] -> Q [Dec]
-liftCon' typeSig tvbs cx f n ns cn ts = do
+liftCon' typeSig tvbs cx f n nns cn tts = do
-- prepare some names
opName <- mkName <$> mkOpName (nameBase cn)
- m <- newName "m"
+ r <- newName "r"
a <- newName "a"
- monadFree <- findTypeOrFail "MonadFree"
- liftF <- findValueOrFail "liftF"
+ semantic <- findTypeOrFail "Semantic"
+ member <- findTypeOrFail "Member"
+ liftF <- findValueOrFail "send"
+ let m = last nns
+ ns = init nns
+ replaceMType t | t == m = ConT semantic `AppT` VarT r
+ | otherwise = t
+ ts = everywhere (mkT replaceMType) tts
-- look at the constructor parameters
args <- mapM (mkArg n) ts
let ps = params args -- these are not using type parameter
@@ -205,26 +208,28 @@ liftCon' typeSig tvbs cx f n ns cn ts = do
-- based on cs we get return type and refined expressions
-- (e.g. with Nothing/Just or Left/Right tags)
(retType, es) <- unifyCaptured a cs
- -- operation type is (a1 -> a2 -> ... -> aN -> m r)
- let opType = foldr (AppT . AppT ArrowT) (AppT (VarT m) retType) ps
+ -- operation type is (a1 -> a2 -> ... -> aN -> Semantic r z)
+ let opType = foldr (AppT . AppT ArrowT) (ConT semantic `AppT` VarT r `AppT` retType) ps
-- picking names for the implementation
xs <- mapM (const $ newName "p") ps
let pat = map VarP xs -- this is LHS
exprs = zipExprs (map VarE xs) es args -- this is what ctor would be applied to
fval = foldl AppE (ConE cn) exprs -- this is RHS without liftF
ns' = nub (concatMap extractVars ns)
- q = filter nonNext tvbs ++ map PlainTV (qa ++ m : ns')
+ q = filter nonNext tvbs ++ map PlainTV (qa ++ r : ns')
qa = case retType of VarT b | a == b -> [a]; _ -> []
f' = foldl AppT f ns
return $ concat
[ if typeSig
#if MIN_VERSION_template_haskell(2,10,0)
- then [ SigD opName (ForallT q (cx ++ [ConT monadFree `AppT` f' `AppT` VarT m]) opType) ]
+ then [ SigD opName (ForallT q (cx ++ [ConT member `AppT` f' `AppT` VarT r]) opType) ]
#else
- then [ SigD opName (ForallT q (cx ++ [ClassP monadFree [f', VarT m]]) opType) ]
+ then [ SigD opName (ForallT q (cx ++ [ClassP member [f', VarT r]]) opType) ]
#endif
else []
- , [ FunD opName [ Clause pat (NormalB $ AppE (VarE liftF) fval) [] ] ] ]
+ , [ FunD opName [ Clause pat (NormalB $ AppE (VarE liftF) fval) [] ]
+ , PragmaD $ InlineP opName Inline FunLike AllPhases
+ ] ]
where
nonNext (PlainTV pn) = VarT pn /= n
nonNext (KindedTV kn _) = VarT kn /= n
from fused-effects.
I’d like to have it live in a separate package
Yeah I agree.
from fused-effects.
@evanrelf Good catch. Updating.
from fused-effects.
Is this something you guys are still interested in?
I'd like to use fused-effects
for something at work soon, and I'd value having a way to get rid of the smart constructor boilerplate.
I might play around with implementing this in my free time, once the GADT syntax is released in the next version.
from fused-effects.
Is this something you guys are still interested in?
I'd like to use
fused-effects
for something at work soon, and I'd value having a way to get rid of the smart constructor boilerplate.I might play around with implementing this in my free time, once the GADT syntax is released in the next version.
I think so, tho per @jkachmar’s comment, I’d like to have it live in a separate package, tho perhaps a separate package in this repository.
from fused-effects.
Fixed. https://hackage.haskell.org/package/fused-effects-th
from fused-effects.
@patrickt FYI, fused-effects-th
failed for me. The source repo is private, so I couldn't raise the issue I got.
from fused-effects.
@AlistairB If you can build a reproducible case & file a bug against fused-effects-th
, I’d be happy to take a look at it.
from fused-effects.
@AlistairB The repo seems to have moved from patrickt/fused-effects-th to fused-effects/fused-effects-th, but @patrickt that isn't reflected on Hackage.
from fused-effects.
Ah thanks. Created fused-effects/fused-effects-th#1
from fused-effects.
Related Issues (20)
- Unversioned documentation links all point to master HOT 3
- throwError law is undocumented
- Add Accum effect HOT 4
- Regression with Error in fused effects 1.1 HOT 7
- Carriers should preserve MonadResource HOT 3
- fused-effects 1.1 performance degradation? HOT 6
- TraceText Effect HOT 3
- MonadBaseControl for Labelled Effects HOT 1
- Add instances of MonadCatch, MonadThrow, MonadMask, where possible? HOT 6
- Indexed error handling HOT 1
- This code for solving prime numbers is about 6 times slower than primes HOT 2
- test suite build failure on Stackage Nightly (GHC 9.0.1) HOT 2
- Why are we slower than mtl? HOT 7
- Difficulty (impossibility?) to wrap `reactive-banana` as effect HOT 2
- Export effect constructors from separate modules
- GHC 9.4.1 compatibility
- Write infodump on how to define algebras
- Accum effect mixed with other effects duplicates accumulated monoidal value HOT 4
- The README makes an unclear statement about visible type applications relating to running effects HOT 1
- Update dependency bounds to support GHC 9.8 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fused-effects.