[Haskell] Forcing Type Class Equality

john lask jvlask at hotmail.com
Thu Jun 29 00:26:09 EDT 2006

** 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
*** 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 

More information about the Haskell mailing list