** this is literate haskell hoping someone can help me. What I am trying to do is
class Ba1 a
ba1 :: Ba1 a => a -> IO () ba1 x = print "helllo"
what I wish to do is declare another function
class Foo a proxy :: Foo a => a -> IO ()
so that I can do something like
proxy x = ba1 x
this does not work in hugs and gives ERROR "test.lhs":19 - Cannot justify constraints in explicitly typed binding *** Expression : proxy *** Type : Foo a => a -> IO () *** Given context : Foo a *** Constraints : Ba1 a which is entirely expected. The trick is to tell hugs that Foo and Ba1 are the same so how do I do that ? I have tried
instance Ba1 a => Foo a instance Foo a => Ba1 a
which should define equality but to no avail ?? Can this be done ? I thought the problem might be drawing the inference Foo == Ba1 and to try and force the inference i did:
class Foo a proxy1 :: (Foo a,Ba1 a) => a -> IO () proxy1 x = ba1 x
proxy2 :: Foo a => a -> IO () proxy2 x = proxy x
This typed checked but Main> :load test Main> proxy2 ERROR - *** The type checker has reached the cutoff limit while trying to *** determine whether: *** Foo a *** can be deduced from: *** () *** This may indicate that the problem is undecidable. However, *** you may still try to increase the cutoff limit using the -c *** option and then try again. (The current setting is -c40) any ideas out there ?? _________________________________________________________________ Meet Sexy Singles today @ Lavalife - Click here http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Flavalife9%2Eninemsn%2Ecom%2E...
NB the essence what I am trying to do is to define a proxy class Foo for class Ba1 I would have thought that something as simple as the following would have worked ?? class Ba1 a where dosomething :: a -> IO () ba1 :: Ba1 a => a -> IO () ba1 x = dosomething x instance Ba1 Int where dosomething x = print x instance Ba1 Char where dosomething x = print x what I wish to do is declare another function class Foo a instance Foo a => Ba1 a proxy :: Foo a => a -> IO () proxy x = ba1 x _________________________________________________________________ realestate.com.au: the biggest address in property http://ninemsn.realestate.com.au
Hi John,
NB
the essence what I am trying to do is to define a proxy class Foo for class Ba1 I would have thought that something as simple as the following would have worked ??
class Ba1 a where dosomething :: a -> IO ()
ba1 :: Ba1 a => a -> IO () ba1 x = dosomething x
instance Ba1 Int where dosomething x = print x
instance Ba1 Char where dosomething x = print x
what I wish to do is declare another function
If you implement the proxy function like below, it should work: class Ba1 a => Foo a where proxy :: a -> IO () proxy = ba1 I've made Foo a subclass of Ba1 with a member function proxy and a default implementation. I hope this will help you further.. Grt PS Use the haskell-cafe list next time for this kind of questions.
participants (2)
-
Gerrit van den Geest -
john lask