Problems with mkMethods

0 views
Skip to first unread message

Paul Visschers

unread,
Aug 10, 2008, 11:30:42 AM8/10/08
to HAppS
I've come to the point where I have state in my application and I'm
relatively comfortable with using happs. I've run into a problem with
using mkMethods though, which is that it seems to disallow polymorphic
functions. I get a "Method too general" error whenever I try to use
one. I've tried adding Serialize class constraints, but that didn't
help.

So my question is: am I doing something wrong, or is it just not
possible to use polymorphic functions? If it's the latter, I hope this
will change soon, since my design uses polymorpism a lot.

Lemmih

unread,
Aug 10, 2008, 4:11:41 PM8/10/08
to HA...@googlegroups.com

Polymorphic functions are indeed not allowed. This is due to the
design of HAppS and cannot change. It is unfortunately not possible to
deserialise polymorphic values.
It should, however, be noted that a certain level of polymorphism is
allowed. That is, components can have all the type variables they
want. So this is allowed:
> method :: a -> Update (Component a) ()
but this isn't:
> method :: a -> Update Component ()

--
Cheers,
Lemmih

Paul Visschers

unread,
Aug 10, 2008, 7:11:18 PM8/10/08
to HA...@googlegroups.com
Ok, thanks. That latter bit should really help. I will try to split up
my state tomorrow and see what I can do with that.

Paul Visschers

unread,
Aug 11, 2008, 7:56:57 AM8/11/08
to HA...@googlegroups.com
I've tried the method you described and it works partially. I can define
everything properly and it compiles. But now when I try to use it I get
the following error in the browser:

Server error: Emitted event to unknown component. Ev: Main.TestQuery [Char]

I guess this means that it can't link the query to the proper component,
but I'm not sure how to fix this. I'm sure there is a fix, or you
wouldn't have suggested it. Below is some of the code I used:

instance (Serialize a) => Component (CMap a) where
type Dependencies (CMap a) = End
initialValue = empty

instance Component (CMap String) where
type Dependencies (CMap String) = End
initialValue = empty

testQuery :: Query (CMap a) (CMap a)
testQuery = ask

testAdd x = modify (add (const x))

$(mkMethods ''CMap ['testQuery, 'testAdd])

controller :: [ServerPart Response]
controller = [
dir "list" [anyRequest $ liftM (toResponse . show) $ (webQuery
TestQuery :: Web (CMap String))],
dir "add" [anyRequest $ liftM (toResponse . show) $ (webUpdate $
TestAdd "hello")]
]

Note that I tried the instances of Component in all combinations.

What am I doing wrong, and how can I fix it?

Lemmih

unread,
Aug 11, 2008, 8:06:51 AM8/11/08
to HA...@googlegroups.com

Did you start the HAppS state system? That is, did you call
'startStateSystem' and, if so, which entry point did you use?

--
Cheers,
Lemmih

Paul Visschers

unread,
Aug 11, 2008, 9:15:10 AM8/11/08
to HAppS
That was indeed the problem. I was still using the previous state
type. I got it working with CMap String.

However that still isn't very useful. What do I need to do if I want
to use multiple types at the same time (for example a CMap String and
a CMap Int), since this is why I required polymorphism in the first
place?
Reply all
Reply to author
Forward
0 new messages