Comments (8)
Here is the output code with the ugly extensions removed:
{-# LANGUAGE KindSignatures #-}
import Data.Acid
import Data.Acid.Advanced
import Data.Generics
import Data.Map as Map
import Data.SafeCopy
import Control.Monad.Reader
import Control.Monad.State
putValue :: Ord key => key -> val -> Update (Map key val) ()
putValue key val = modify $ Map.insert key val
lookValue :: Ord key => key -> Query (Map key val) (Maybe val)
lookValue key = ask >>= return . Map.lookup key
instance Ord k_a334 => IsAcidic Map where
acidEvents =
[UpdateEvent (\ (PutValue key val) -> putValue key val),
QueryEvent (\ (LookValue key) -> lookValue key)]
data PutValue (key :: *) (val :: *) = PutValue key val deriving (Typeable)
instance Ord key => SafeCopy PutValue where
putCopy (PutValue key val) = contain (do { safePut key; safePut val; return () })
getCopy = contain (((return PutValue) <*> safeGet) <*> safeGet)
instance Ord key => Method PutValue where
type MethodResult PutValue = ()
type MethodState PutValue = Map key val
instance Ord key => UpdateEvent PutValue
newtype LookValue (key :: *) (val :: *) = LookValue key deriving (Typeable)
instance Ord key => SafeCopy LookValue where
putCopy (LookValue arg) = contain (do { safePut arg; return () })
getCopy = contain ((return LookValue) <*> safeGet)
instance Ord key => Method LookValue where
type MethodResult LookValue = Maybe val
type MethodState LookValue = Map key val
instance Ord key => QueryEvent LookValue
from acid-state.
Here is the output of ghc-7.8, cleaned up similarly:
{-# LANGUAGE TypeFamilies, DeriveDataTypeable #-}
import Control.Applicative
import Data.Acid
import Data.Acid.Advanced
import Data.Generics
import Data.Map as Map
import Data.SafeCopy
import Control.Monad.Reader
import Control.Monad.State
putValue :: Ord key => key -> val -> Update (Map key val) ()
putValue key val = modify $ Map.insert key val
lookValue :: Ord key => key -> Query (Map key val) (Maybe val)
lookValue key = ask >>= return . Map.lookup key
instance (SafeCopy k, Typeable k, SafeCopy a, Typeable a, Ord k) => IsAcidic (Map k a) where
acidEvents = [UpdateEvent (\ (PutValue k a) -> putValue k a),
QueryEvent (\ (LookValue a) -> lookValue a)]
data PutValue key val = PutValue key val deriving (Typeable)
instance (SafeCopy key, SafeCopy val, Ord key) => SafeCopy (PutValue key val) where
putCopy (PutValue key val) = contain (do { safePut key; safePut val; return () })
getCopy = contain (((return PutValue) <*> safeGet) <*> safeGet)
instance (SafeCopy key, Typeable key, SafeCopy val, Typeable val, Ord key) => Method (PutValue key val) where
type MethodResult (PutValue key val) = ()
type MethodState (PutValue key val) = Map key val
instance (SafeCopy key, Typeable key, SafeCopy val, Typeable val, Ord key) => UpdateEvent (PutValue key val)
newtype LookValue key val = LookValue key deriving (Typeable)
instance (SafeCopy key, SafeCopy val, Ord key) => SafeCopy (LookValue key val) where
putCopy (LookValue key) = contain (do { safePut key; return () })
getCopy = contain ((return LookValue) <*> safeGet)
instance (SafeCopy key, Typeable key, SafeCopy val, Typeable val, Ord key) => Method (LookValue key val) where
type MethodResult (LookValue key val) = Maybe val
type MethodState (LookValue key val) = Map key val
instance (SafeCopy key, Typeable key, SafeCopy val, Typeable val, Ord key) => QueryEvent (LookValue key val)
from acid-state.
I don't really know if this is a template-haskell-2.10 issue or a base-4.8 issue.
from acid-state.
Ok, now I understand this problem. First, there are missing superclasses in the code above, and it now needs the TypeFamilies directive:
{-# LANGUAGE KindSignatures, TemplateHaskell, TypeFamilies #-}
import Control.Monad.Reader (ask)
import Control.Monad.State (modify)
import Data.Acid (Update, Query, makeAcidic)
import Data.Data (Data, Typeable)
import Data.Map as Map (insert, lookup, Map)
import Data.SafeCopy (SafeCopy)
putValue :: (SafeCopy key, Ord key, Typeable key, SafeCopy val, Typeable val) => key -> val -> Update (Map key val) ()
putValue key val = modify $ Map.insert key val
lookValue :: (SafeCopy key, Ord key, Typeable key, SafeCopy val, Typeable val) => key -> Query (Map key val) (Maybe val)
lookValue key = ask >>= return . Map.lookup key
$(makeAcidic ''Map ['putValue, 'lookValue])
Now we get these messages:
Bug.hs:15:3:
The RHS of an associated type declaration mentions ‘val_a2rS’
All such variables must be bound on the LHS
Bug.hs:15:3:
The RHS of an associated type declaration mentions ‘key_a2rR’, ‘val_a2rS’
All such variables must be bound on the LHS
Bug.hs:15:3:
The RHS of an associated type declaration mentions ‘key_a2Xh’, ‘val_a2Xi’
All such variables must be bound on the LHS
This is because makeAcidic throws away kinded type variables where I suspect it should treat them the same way it does plain type variables. Now that I poke around, it looks like I proposed a solution in #53, now I have pull request #56 as well.
from acid-state.
This is still an issue.
{-# LANGUAGE KindSignatures, TemplateHaskell #-}
module Main where
import Data.Acid
import Data.SafeCopy
import Data.Typeable
----------------------
data Bad q = Bad
{ foo :: ()
, bar :: ()
} deriving (Show, Typeable)
$(deriveSafeCopy 0 'base ''Bad)
serverUpdate :: q -> Update (Bad q) ()
serverUpdate = undefined
$(makeAcidic ''Bad [ 'serverUpdate ])
breaks with
Test.hs:21:3-36: The exact Name ‘q_a5STR’ is not in scope …
Probable cause: you used a unique Template Haskell name (NameU),
perhaps via newName, but did not bind it
If that's it, then -ddump-splices might be useful
Compilation failed.
generated splice:
makeAcidic ''Bad ['serverUpdate]
======>
instance IsAcidic Bad where
acid-state-0.13.0:Data.Acid.Common.acidEvents
= [acid-state-0.13.0:Data.Acid.Common.UpdateEvent
(\ (ServerUpdate arg_a9tH) -> serverUpdate arg_a9tH)]
newtype ServerUpdate (q_a6dl :: *)
= ServerUpdate q_a6dl
deriving (Typeable)
instance SafeCopy ServerUpdate where
putCopy (ServerUpdate arg_a9tG)
= contain
(do { safePut arg_a9tG;
return () })
getCopy = contain ((return ServerUpdate) <*> safeGet)
instance Data.Acid.Core.Method ServerUpdate where
type Data.Acid.Core.MethodResult ServerUpdate = ()
type Data.Acid.Core.MethodState ServerUpdate = Bad q_a6dl
instance UpdateEvent ServerUpdate
from acid-state.
With or without my patch in pull request #56?
from acid-state.
from acid-state.
Looks like this has long been fixed (#56 was merged), and I've added a basic test in #105.
from acid-state.
Related Issues (20)
- Get size of acid-state? HOT 3
- Failed to build acid-state-0.15.1 HOT 8
- acid-state fails to build with GHC 8.8.1 HOT 1
- Changelog entry for 0.16 is missing HOT 1
- Test suite fails on macOS HOT 8
- build fails on ghc 9.0.1 HOT 1
- Hackage release needed for GHC 9.0.2 support HOT 2
- Benchmark `loading-benchmark` fails to build with GHC 7.10 HOT 3
- GHC versions covered by AppVeyor CI HOT 3
- acid-state on cluster HOT 1
- Haddocks for Data.Acid.Memory.Pure.AcidState are misleading HOT 1
- Database seems empty after ctrl+c HOT 4
- Build failures with mtl-2.3
- Support GHC 9.4 HOT 1
- README: possibly outdated irc link
- Build failure with unix-2.8 (GHC 9.6)
- Support GHC 9.6
- Build failure with template-haskell-2.21 (GHC 9.8)
- Benchmarks fail to build on GHC 9.8 due to `system-filepath`
- Unnecessary use of strict bytestrings in Data.Acid.Log HOT 1
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 acid-state.