<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Reading the <a href="http://dl.acm.org/citation.cfm?id=1017481">implicit configurations paper</a> (Kiselyov & Shan), I couldn't figure out how this bit of code (section 3.2) was meant to work:<div><br></div><div><div> class Modular s a | s -> a where modulus :: s -> a</div><div><br></div><div> normalize :: (Modular s a, Integral a) => a -> M s a</div><div> normalize a :: M s a = M (mod a (modulus (undefined :: s)))</div><div><br></div><div>Here, `M` is just a type representing a modulus, with a phantom parameter that's going to make the magic happen:</div><div><br></div><div> data M s a = M a deriving (Eq, Show)</div><div><br></div><div>Running this in GHC 7.4.2, with the extensions for scope typed variables, multi parameter type classes, and functional dependencies enabled, I get a parse error on the type signature on the LHS of the definition of `normalize`. Having moved the deprecated LHS result annotation to the RHS, I think this should be equivalent:</div><div><br></div><div><div> normalize :: (Modular s a, Integral a) => a -> M s a</div><div> normalize x = (M (mod x (modulus (undefined :: s)))) :: M s a</div></div><div><br></div><div>But indeed this won't type-check. I've tried annotating the argument (x :: a) and the result of `modulus` (modulus (undefined :: s) :: a), as well as various other terms, but GHC always tells me the phantom type is ambiguous or the type of the argument of `normalize` can't be unified with the parameter `a` in the result type.</div><div><br></div><div>Now, like I said, I didn't see how this could work in the first place, so I'm at a loss as to what the problem is. Can someone show me how to get this to compile with a recent version of GHC? I'd also appreciate any insight into what `normalize` is meant to do, if the working code turns out to differ in just a type annotation or two. ...</div></div><div><br></div><div>Regards,</div><div><br></div><div>Eric</div><div><br></div><div>PS: The literate Haskell version of the paper is <a href="http://www.cs.rutgers.edu/~ccshan/prepose/prepose.lhs">here</a>.</div></body></html>