Giter VIP home page Giter VIP logo

Comments (11)

jkachmar avatar jkachmar commented on May 27, 2024 4

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.

isovector avatar isovector commented on May 27, 2024 1

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.

evanrelf avatar evanrelf commented on May 27, 2024 1

I’d like to have it live in a separate package

Yeah I agree.

from fused-effects.

patrickt avatar patrickt commented on May 27, 2024 1

@evanrelf Good catch. Updating.

from fused-effects.

evanrelf avatar evanrelf commented on May 27, 2024

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.

robrix avatar robrix commented on May 27, 2024

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.

patrickt avatar patrickt commented on May 27, 2024

Fixed. https://hackage.haskell.org/package/fused-effects-th

from fused-effects.

AlistairB avatar AlistairB commented on May 27, 2024

@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.

patrickt avatar patrickt commented on May 27, 2024

@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.

evanrelf avatar evanrelf commented on May 27, 2024

@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.

AlistairB avatar AlistairB commented on May 27, 2024

Ah thanks. Created fused-effects/fused-effects-th#1

from fused-effects.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.