Re: Implicit parameter constraints not inferred
On Saturday 06 November 2004 17:57, you wrote: > Benjamin Franksen wrote: > > My question: Is this as it should be or is it a bug? > > The Monomorphism Restriction. Grumble... I almost suspected it. Only the context in which I got the error originally didn't _look_ as if MR would apply, and when I fumbled with the simple test program I just forgot about it. Sorry to have bothered you and thanks a lot for the answer. Your explanation of the MR is the best I've seen so far. Ben ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Implicit parameter constraints not inferred
Benjamin Franksen wrote: main = let ?b = True in use_b --use_b :: (?g::Bool) => IO () use_b = print ?b It isn't: ghc -fimplicit-params says Unbound implicit parameter (?b :: a) arising from use of implicit parameter `?b' at TestBug.hs:4 In the first argument of `print', namely `?b' In the definition of `use_b': use_b = print ?b It works if I uncomment the signature. Using ghc-6.2.2, btw. My question: Is this as it should be or is it a bug? The Monomorphism Restriction. It's intended to prevent people from shooting themselves in the foot by defining things that look like constants (like use_b) but really are polymorphic values that still depend on some context and therefore are not constant. So in this case (use_b defined with no arguments), you need to specify a type signature. The monomorphism restriction would be useful in situations like: foo = expensiveOp bar How often will foo be evaluated? With the monomorphism restriction, at most once. Without it, well, that depends on the type of bar. With bar :: (?g :: Bool) => Int, foo also gets the (?g :: Bool) => context, and it's reevaluated whenever it's used; but you won't be able to tell that by looking at foo alone. Cheers, Wolfgang ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Implicit parameter constraints not inferred
To be fair, the ghc docs do not mention constraint inference for implicit parameters. OTOH they do not say that signatures must be given explicitly if I use implicit parameters. However, I always thought that this would be ok: > main = let ?b = True in use_b > --use_b :: (?g::Bool) => IO () > use_b = print ?b It isn't: ghc -fimplicit-params says Unbound implicit parameter (?b :: a) arising from use of implicit parameter `?b' at TestBug.hs:4 In the first argument of `print', namely `?b' In the definition of `use_b': use_b = print ?b It works if I uncomment the signature. I also tried > use_b = print (?b :: Bool) but to no avail. Using ghc-6.2.2, btw. My question: Is this as it should be or is it a bug? Ben ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users