[Haskell-beginners] Using Debug.Trace

legajid legajid at free.fr
Sun Jan 31 04:25:58 EST 2010


Hi,

Starting with trace, i have trouble  with my calcul'' function while 
calcul' is ok.
When afftrace in calcul'' is commented, the program compiles.
When uncommented (            afftrace ("    calcul'' vide") ), i get 
the following messages :

-------------------------------------------------------------------------------------------
 *Main> :r
[1 of 1] Compiling Main             ( sud3c.hs, interpreted )

sud3c.hs:62:3:
    Couldn't match expected type `[Char]'
           against inferred type `(Plateau, Char)'
    In a stmt of a 'do' expression: afftrace ("    calcul'' vide")
    In the expression:
        do afftrace ("    calcul'' vide")
           (pxv, False)
    In the definition of `calcul''':
        calcul'' pxv _ []
                   = do afftrace ("    calcul'' vide")
                        (pxv, False)
Failed, modules loaded: none.
-------------------------------------------------------------------------------------------

I don't understand why, in calcul', it's ok and why, in calcul'', it's 
problematic. Because return value of calcul'' is a tuple ?

When my program is ok, should i remove all trace instructions (and 
associated do commands too) or just set  my modetrace value to False ?
 

Thanks for helping,
Didier

Below my code :


calcul' :: Plateau -> [Cellule] -> Plateau
calcul' pxv  [] = do
            afftrace ("  Calcul' vide")
            pxv
calcul' pxv  (c:cs)=    do
            afftrace ("  Calcul' ok1="++show ok1++" c:cs= "++show (c:cs))
            afftrace ("  "++show xv1)
               
            if ok1  then do
                    afftrace ("  Calcul' suite")
                    calcul' xv1 cs   
                else do
                    afftrace ("  Calcul' pas de valeur")
                    pxv
    where
        vallib=[1..length pxv]++[5..7]
        nbvlib=length vallib
        (xv1,ok1)=calcul'' pxv c vallib



calcul'' :: Plateau -> Cellule -> [Valeur] -> (Plateau, Bool)
calcul'' pxv  _ [] = do
            --afftrace ("    calcul'' vide")
            (pxv, False)

calcul'' pxv  c (li : lis) = do
                --afftrace ("    "++show pxv)
                --afftrace ("    "++show c ++ "   "++show(li:lis))
                v2
                where
                  v2= if (elem li pxv || li==4)
                    then    
                        calcul'' pxv  c lis
                    else do
                        --afftrace ("      calcul'''")
                        (calcul''' pxv c li, True)

calcul''' :: Plateau -> Cellule -> Valeur -> Plateau
calcul''' pxv c li =
    take (c-1) pxv ++ [li] ++ drop c pxv

afftrace x= if modetrace then trace x " "
             else " "


More information about the Beginners mailing list