ambiguous types although 'asTypeOf'

I thought I understand monomorphism restriction. But it seems, I don't. I have boilt down my problem to the following test. Don't try to make any sense of it, it is just the smallest code I could come up with. test :: (Integral a, RealFrac a) => a test = let c = undefined in asTypeOf (round c) c When compiling I get: Compiling StorableInstance ( src/StorableInstance.hs, interpreted ) src/StorableInstance.hs:38:17: Warning: Defaulting the following constraint(s) to type `Double' `RealFrac a' arising from use of `round' at src/StorableInstance.hs:38:17-21 In the first argument of `asTypeOf', namely `(round c)' In the definition of `test1': test1 = let c = undefined in asTypeOf (round c) c

As i understand it, the monomorphism restriction applies to "constrained
type variables", but c :: forall a. a, so it remains polymorphic and each of
its uses can be instantiated to a different type.
2007/12/25, Henning Thielemann
I thought I understand monomorphism restriction. But it seems, I don't. I have boilt down my problem to the following test. Don't try to make any sense of it, it is just the smallest code I could come up with.
test :: (Integral a, RealFrac a) => a test = let c = undefined in asTypeOf (round c) c
When compiling I get:
Compiling StorableInstance ( src/StorableInstance.hs, interpreted )
src/StorableInstance.hs:38:17: Warning: Defaulting the following constraint(s) to type `Double' `RealFrac a' arising from use of `round' at src/StorableInstance.hs:38:17-21 In the first argument of `asTypeOf', namely `(round c)' In the definition of `test1': test1 = let c = undefined in asTypeOf (round c) c _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Dec 25, 2007 4:27 PM, Henning Thielemann
test :: (Integral a, RealFrac a) => a test = let c = undefined in asTypeOf (round c) c
When compiling I get:
Compiling StorableInstance ( src/StorableInstance.hs, interpreted )
src/StorableInstance.hs:38:17: Warning: Defaulting the following constraint(s) to type `Double' `RealFrac a' arising from use of `round' at src/StorableInstance.hs:38:17-21 In the first argument of `asTypeOf', namely `(round c)' In the definition of `test1': test1 = let c = undefined in asTypeOf (round c) c
Interesting, I don't see this behaviour at all. $ cat t.hs module Main where instance Integral Double test :: (Integral a, RealFrac a) => a test = let c = undefined in asTypeOf (round c) c main = print (test :: Double) $ ghc --make t.hs [1 of 1] Compiling Main ( t.hs, t.o ) t.hs:3:0: Warning: No explicit method nor default method for `quotRem' In the instance declaration for `Integral Double' t.hs:3:0: Warning: No explicit method nor default method for `toInteger' In the instance declaration for `Integral Double' Linking t ... $ ./t t: Prelude.undefined $ ghc --version The Glorious Glasgow Haskell Compilation System, version 6.6.1 -- Felipe.

On Tue, 25 Dec 2007, Felipe Lessa wrote:
On Dec 25, 2007 4:27 PM, Henning Thielemann
wrote: test :: (Integral a, RealFrac a) => a test = let c = undefined in asTypeOf (round c) c
When compiling I get:
Compiling StorableInstance ( src/StorableInstance.hs, interpreted )
src/StorableInstance.hs:38:17: Warning: Defaulting the following constraint(s) to type `Double' `RealFrac a' arising from use of `round' at src/StorableInstance.hs:38:17-21 In the first argument of `asTypeOf', namely `(round c)' In the definition of `test1': test1 = let c = undefined in asTypeOf (round c) c
Interesting, I don't see this behaviour at all.
Of course, I use -Wall all the time. :-)
participants (3)
-
Andrea Vezzosi
-
Felipe Lessa
-
Henning Thielemann