[Haskell-beginners] Typeclasses vs. Data

Thomas haskell at phirho.com
Thu Jul 21 01:41:52 CEST 2011


Hello David!

Yes, I should have posted the signatures, too. Sorry.
I managed to simplify the problem even further. It still doesn't help me 
understand how to avoid the error, though.

class Continuation a where
    resume :: a -> Int -> Int

data BeginCont a = BeginCont a Int deriving (Show)
instance (Continuation a) => Continuation (BeginCont a) where
   resume (BeginCont k es) v = eval_begin es k

eval :: Continuation a => Int -> a -> Int
eval n k = if n < 1
	then resume k n
	else eval_begin (n - 1) k

eval_begin :: Continuation a => Int -> a -> Int
eval_begin n k = eval n (if (n < 0) then k else (BeginCont k (n - 1)))

It's pretty clear that in the mutual recursion between "eval" and 
"eval_begin" the parameter "k" is "growing" from "a" to "BeginCont a" 
and so on. But how to resolve that?
(And it works perfectly in the case of the "data" definition.)

Anyway, thank you!
Regards,
Thomas



On 21.07.2011 00:40, David Place wrote:
 > On Jul 20, 2011, at 6:26 PM, Thomas wrote:
 >
 >> Thank you for taking the time.
 >> Here is a complete fragment that shows the error:
 >
 > Hi, Thomas.
 >
 > I'm very sympathetic.  I hate it when I get an error like this.  I 
looked at your code and the solution didn't jump off the page, maybe it 
will for someone else.  In the meantime, I suggest this strategy. 
Carefully give type signatures to all of your functions.  This way you 
can help the type checker give better error messages.  The type 
inference algorithm can go away into crazy land if you give it a 
nonsense definition.
 >
 > ___________________
 > David Place
 > Owner, Panpipes Ho! LLC
 > http://panpipesho.com
 > d at vidplace.com
 >
 >




More information about the Beginners mailing list