<br><div class="gmail_quote">On Dec 3, 2007 7:43 AM, Peter Padawitz <<a href="mailto:peter.padawitz@udo.edu">peter.padawitz@udo.edu</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000">
What is wrong here? ghci tries (and fails) to deduce certain types for
the comp functions that I did not expect.<br>
<br>
<code>type Block = [Command]<br>
data Command = Skip | Assign String IntE | Cond BoolE Block Block |<br>
Loop BoolE Block<br>
data IntE = IntE Int | Var String | Sub IntE IntE | Sum [IntE] |
Prod [IntE]<br>
data BoolE = BoolE Bool | Greater IntE IntE | Not BoolE<br>
<br>
class Java block command intE boolE<br>
where block_ :: [command] -> block<br>
skip :: command<br>
assign :: String -> intE -> command<br>
cond :: boolE -> block -> block -> command<br>
loop :: boolE -> block -> command<br>
intE_ :: Int -> intE<br>
var :: String -> intE<br>
sub :: intE -> intE -> intE<br>
sum_ :: [intE] -> intE<br>
prod :: [intE] -> intE<br>
boolE_ :: Bool -> boolE<br>
greater :: intE -> intE -> boolE<br>
not_ :: boolE -> boolE<br>
<br>
compBlock :: Block -> block<br>
compBlock = block_ . map compCommand<br>
<br>
compCommand :: Command -> command<br>
compCommand Skip = skip<br>
compCommand (Assign x e) = assign x (compIntE e)<br>
compCommand (Cond be c c') = cond (compBoolE be) (compCommand
c)<br>
(compCommand
c')<br>
compCommand (Loop be c) = loop (compBoolE be) (compCommand
c)-}<br>
<br>
compIntE :: IntE -> intE<br>
compIntE (IntE i) = intE_ i<br>
compIntE (Var x) = var x<br>
compIntE (Sub e e') = sub (compIntE e) (compIntE e')<br>
compIntE (Sum es) = sum_ (map compIntE es)<br>
compIntE (Prod es) = prod (map compIntE es)<br>
<br>
compBoolE :: BoolE -> boolE<br>
compBoolE (BoolE b) = boolE_ b<br>
compBoolE (Greater e e') = greater (compIntE e) (compIntE e')<br>
compBoolE (Not be) = not_ (compBoolE be)<br>
</code><br>
</div>
</blockquote><br>Well, first of all, the definition of compCommand should use calls to compBlock, not recursive calls to compCommand. But that's not the main source of your problems.<br><br>What exactly are you trying to accomplish? And why do you need a type class?
<br><br>-Brent<br></div>