Differences in pattern matching syntax?

Han Joosten han.joosten at atosorigin.com
Thu Jan 15 16:57:12 EST 2009


I wrote a little wrapper around ghc to see how what parameters were used:
ghc --make -odir "C:\prive\eclipseworkspace\ADL trunk\out" -hidir
"C:\prive\eclipseworkspace\ADL trunk\out" -o "C:\prive\eclipseworkspace\ADL
trunk\bin\ADL" -dcore-lint Main.hs
So this is only some paths and -dcore-lint. I remember trying that after I
had ran into the bug. 

I used your hints and this is what happend. I did not use eclipsefp, but
compiled directly from the command line. Also, inbetwean builds I deleted
all intermediate files, just to make sure that everything was built with the
same options. 

a1) First I compiled everything (with the original alternative 1) again with
ghc --make -odir "C:\prive\eclipseworkspace\ADL trunk\out" -hidir
"C:\prive\eclipseworkspace\ADL trunk\out" -o "C:\prive\eclipseworkspace\ADL
trunk\bin\ADL" -dcore-lint -O Main.hs

Then I ran the executable. It didn't mention a stack overflow, but it said:
ADL.exe: <<loop>>
after which it stoped. 

a2) Now I put the original alternative 2 in place, and compiled everything
from scratch :
ghc --make -odir "C:\prive\eclipseworkspace\ADL trunk\out" -hidir
"C:\prive\eclipseworkspace\ADL trunk\out" -o "C:\prive\eclipseworkspace\ADL
trunk\bin\ADL" -dcore-lint -O Main.hs

Again I ran the executable, but it terminated as before, doing what I
expected it to do. No stack overflow, no loop whatsoever. 

b) Now I tried the modified alternative 1:

   antecedent :: Rule -> Expression
   antecedent r = case r of
                   Ru{} -> if (rrsrt r == AlwaysExpr)  then error ("(Module
ADLdataDef:) illegal call to antecedent of rule "++show r)
                                                                   else
rrant r
                   Sg{} -> antecedent (srsig r)
                   Gc{} -> let x = grspe r in r `seq` Tm r
                   Fr{} -> frcmp r

Compiled again with: 
ghc --make -odir "C:\prive\eclipseworkspace\ADL trunk\out" -hidir
"C:\prive\eclipseworkspace\ADL trunk\out" -o "C:\prive\eclipseworkspace\ADL
trunk\bin\ADL" -dcore-lint -O Main.hs

it said:
ADLdataDef.hs:41:57:
    Couldn't match expected type `Morphism'
           against inferred type `Rule'
    In the first argument of `Tm', namely `r'
    In the second argument of `seq', namely `Tm r'
    In the expression: r `seq` Tm r

I hardly use any let expressions (shame on me??) and I am not very familiar
with them. But I figured out you might have mistaken, so I changed the bit
to:
   antecedent :: Rule -> Expression
   antecedent r = case r of
                   Ru{} -> if (rrsrt r == AlwaysExpr)  then error ("(Module
ADLdataDef:) illegal call to antecedent of rule "++show r)
                                                                   else
rrant r
                   Sg{} -> antecedent (srsig r)
                   Gc{} -> let x = grspe r in r `seq` Tm x
                   Fr{} -> frcmp r

Compiled again with: 
ghc --make -odir "C:\prive\eclipseworkspace\ADL trunk\out" -hidir
"C:\prive\eclipseworkspace\ADL trunk\out" -o "C:\prive\eclipseworkspace\ADL
trunk\bin\ADL" -dcore-lint -O Main.hs

Again, it sais 
ADL.exe: <<loop>>


My conclusion is until now that I have here two variants of a piece of code
that should be semantically equivalent. In the same context (the rest of the
program hasn't changed) however, they behave different. Hence I suspect a
bug in ghc... 8-((

Since my first posting of this thread, I have been searching around, and I
have learnt that there are some pragma's that could be used. Are there any
of them that I should have used when using this kind of pattern matching? I
might have omitted them. 

Han Joosten.

-- 
View this message in context: http://www.nabble.com/Differences-in-pattern-matching-syntax--tp21416338p21487742.html
Sent from the Haskell - Glasgow-haskell-users mailing list archive at Nabble.com.



More information about the Glasgow-haskell-users mailing list