The interactive loop of ghci displays an interesting evaluation fault
to do with derived equality. In the attached source file, there is
a simple guard which tests some equalities, and basically the same
value is given on the left and right of the (==). Yet, it evaluates
to False in interactive mode, whereas it (correctly) evaluates to True
when compiled.
$ ghci
___ ___ _
/ _ \ /\ /\/ __(_)
/ /_\// /_/ / / | | GHC Interactive, version 5.04.2, for Haskell 98.
/ /_\\/ __ / /___| | http://www.haskell.org/ghc/
\____/\/ /_/\____/|_| Type :? for help.
Loading package base ... linking ... done.
Loading package haskell98 ... linking ... done.
Prelude> :l Small
Compiling Main ( Small.hs, interpreted )
Ok, modules loaded: Main.
*Main> main
"*** Exception: Four.bceFour: precondition fails:arrows not parallel
f = E
g = E
$ ghc -o Small Small.hs
$ ./Small
"it works"
I have verified that the fault exists at least as far back as 5.02.3.
Regards,
Malcolm
module Main where
data FourArrow = A | B | C | D | E | ABE | AC | BD | CDE
deriving (Eq, Show)
data Category a
= Category
{ src :: a -> a
, tgt :: a -> a
, equal :: a -> a -> Bool
}
categoryFour :: Category FourArrow
categoryFour = Category
{src = dom,
tgt = cod,
equal = (==)
}
where
dom A = ABE
dom B = ABE
dom C = AC
dom D = BD
dom E = ABE
dom ABE = ABE
dom AC = AC
dom BD = BD
dom CDE = CDE
cod A = AC
cod B = BD
cod C = CDE
cod D = CDE
cod E = CDE
cod ABE = ABE
cod AC = AC
cod BD = BD
cod CDE = CDE
----
bceFour :: FourArrow -> FourArrow -> String
bceFour f g
| srcF == srcFour g && tgtF == tgtFour g
= "it works"
| otherwise = error ("Four.bceFour: precondition fails:"
++ "arrows not parallel"
++ "\nf = " ++ (show f)
++ "\ng = " ++ (show g)
++ "\n")
where
srcFour = src categoryFour
tgtFour = tgt categoryFour
srcF = srcFour f
tgtF = tgtFour f
main = print (bceFour E E)