Good afternoon Café, I've written a little bit of code to calculate minimal complete definitions for a class given which of its functions use which other functions.
As an example: doDependencies ord = ([],[["<="],["compare"]]) doDependencies num = (["plus","times","abs","signum","fromInteger"],[["minus"],["negate"]]) The first part of the pair is those functions which must *always* be implemented, the second part is a list of possible minimal complete definitions available for the provided list. This can help catch mistakes; a comment in the GHC source for GHC.Classes notes that compare must be implemented using (<=) and not (<) in order to give the minimal complete definition (<= OR compare). If we use the incorrect (<) then my code calculates the MCD as: doDependencies wrongOrd = ([],[["<"],["<","<=","compare"],["compare"]]) That is, the MCD is (< OR (< AND <= AND compare) OR compare). Now I have two questions: 1) Is my code correct? ;) 2) Could this be incorporated into GHC in order to detect when someone hasn't provided a sufficient definition for a class? As an example, it could detect this: > ~$ cat test2.hs > data Die d = Die d > instance Eq (Die d) where > main = do > let i = Die "stack overflow" > print (i == i) > ~$ ghc -Wall test2.hs --make > ~$ ./test2 > Stack space overflow: current size 8388608 bytes. > Use `+RTS -Ksize' to increase it. Given the following: doDependencies [("==", Just ["/="]),("/=", Just ["=="])] = ([],[["/="],["=="]]) GHC could warn that either (==) or (/=) must be implemented. Thanks, - George
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe