Skip to content

Instantly share code, notes, and snippets.

@alios
Created January 3, 2011 15:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alios/763597 to your computer and use it in GitHub Desktop.
Save alios/763597 to your computer and use it in GitHub Desktop.
problems with happstack templates on class methods
{-# LANGUAGE TemplateHaskell,
DeriveDataTypeable,
TypeFamilies,
MultiParamTypeClasses #-}
module Test where
import Data.Data
import Happstack.State
data TestComponent a b =
TestComponent {
next_id :: Integer,
foo :: [(a,b)]
} deriving (Show, Data, Typeable)
instance Version (TestComponent a b)
$(deriveSerialize ''TestComponent)
instance (Serialize a, Serialize b) => Component (TestComponent a b) where
type Dependencies (TestComponent a b) = End
initialValue = TestComponent 0 []
class TestComponentC a b where
test :: Update (TestComponent a b) ()
test = do
next_id_ <- fmap next_id getState
foo_ <- fmap foo getState
putState $ TestComponent (next_id_ + 1) foo_
$(mkMethods ''TestComponent ['test])
{--
with ghc-7.0.1 and happstack-state-0.5.0.4 when trying to load into ghci I get:
test.hs:1:1:
Exception when trying to run compile-time code:
Method is not a function: test is a Class op from Test.TestComponentC: Test.test :: forall a_0 b_1 . Test.TestComponentC a_0
b_1 =>
Happstack.State.Types.Update (Test.TestComponent a_0
b_1)
()
Code: mkMethods 'TestComponent ['test]
Failed, modules loaded: none.
--}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment