xnyhps / ghc Goto Github PK
View Code? Open in Web Editor NEWThis project forked from ghc/ghc
Mirror of ghc repository. DO NOT SUBMIT PULL REQUESTS HERE
Home Page: http://www.haskell.org/ghc/
License: Other
This project forked from ghc/ghc
Mirror of ghc repository. DO NOT SUBMIT PULL REQUESTS HERE
Home Page: http://www.haskell.org/ghc/
License: Other
Without -XNoMonomorphismRestriction
, the type of the module:
f = _?h >>= _?g
is found to be:
f :: GHC.Prim.Any (* -> *) (GHC.Prim.Any *)
(Even when interpreting GHC.Prim.Any *
as forall a. a
, this is incorrect as the Monad
constraint is not on the first * -> *
)
With -XNoMonomorphismRestriction
, the type is correctly:
f :: Monad m => m b
Opening the following module with -XNoMonomorphismRestriction
:
f = _?h >>= _?g
Causes the holes to not be reported.
One of the differences in the log:
-XNoMonomorphismRestriction
on:
solveWanteds finished with
remaining_unsolved_flats = {}
subst = [TvSubst In scope: InScope [] Type env: []]
simplifyCheck } unsolved = WC {}
Off:
solveWanteds finished with
remaining_unsolved_flats = {[W] $dMonad :: Monad
m_b {0} (CDictCan),
[W] _?h :: _?h (m_b a_c) {0} (CHoleCan),
[W] _?g :: _?g (a_c -> m_b b_d) {0} (CHoleCan)}
subst = [TvSubst In scope: InScope [] Type env: []]
simplifyCheck }
unsolved = WC {wc_flat = [W] $dMonad :: Monad m_b {0} (CDictCan)
[W] _?h :: _?h (m_b a_c) {0} (CHoleCan)
[W] _?g :: _?g (a_c -> m_b b_d) {0} (CHoleCan)}
Probably directly a consequence of #1.
With -XNoMonomorphismRestriction
the holes that are found (which are only visible in the debug messages from the constraint solver, because #1), don't share their type with the holes in other functions in the same module. For example:
f = _?h >>= _?g
g = [_?h, Just ()]
Logs:
tcRnSrcDecls: WC {wc_impl = Implic {Untouchables = No untouchables
Skolems = []
Given = _?h :: _?h (Maybe ())
Wanted = WC {wc_flat = [W] _?h :: _?h
(Maybe
()) {0} (CNonCanonical)}
Binds = EvBindsVar<auS>
the inferred type of g :: (_?h (Maybe ())) => t_a
test.hs:3:1-18}
Implic {Untouchables = No untouchables
Skolems = [m, a, b]
Given = $dMonad :: Monad m_f
_?h :: _?h (m_f a_g)
_?g :: _?g (a_g -> m_f b_h)
Wanted = WC {wc_flat = [W] $dMonad :: Monad
m_f {0} (CNonCanonical)
[W] _?h :: _?h
(m_f a_g) {0} (CNonCanonical)
[W] _?g :: _?g
(a_g
-> m_f b_h) {0} (CNonCanonical)}
Binds = EvBindsVar<avb>
the inferred type of
f :: (Monad m_f, _?h (m_f a_g), _?g (a_g -> m_f b_h)) => t_e
test.hs:1:1-15}}
Without -XNoMonomorphismRestriction
, the result is:
tcRnSrcDecls: WC {wc_flat = [W] _?h :: _?h
(Maybe ()) {0} (CNonCanonical)
[W] $dMonad :: Monad m_f {0} (CNonCanonical)
[W] _?h :: _?h (m_f a_g) {0} (CNonCanonical)
[W] _?g :: _?g (a_g -> m_f b_h) {0} (CNonCanonical)}
After that, _?h
becomes shared (and this information propagates to _?g
):
test.hs:1:13: Warning:
Found hole _?g with type () -> Maybe b0
In the second argument of `(>>=)', namely `_?g'
In the expression: _?h >>= _?g
In an equation for `f': f = _?h >>= _?g
test.hs:3:6: Warning:
Found hole _?h with type Maybe ()
In the expression: _?h
In the expression: [_?h, Just ()]
In an equation for `g': g = [_?h, Just ()]
Ok, modules loaded: Main.
With the following module:
f = _?h
and -XNoMonomorphismRestriction
on, running f
gives:
<interactive>:4:1: Warning:
Found hole _?h with type Show a0 => IO a0
In a stmt of an interactive GHCi command: it <- f
<interactive>:4:1: Warning:
No instance for (Show a0) arising from a use of `print'
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance Show Double -- Defined in `GHC.Float'
instance Show Float -- Defined in `GHC.Float'
instance Show () -- Defined in `GHC.Show'
...plus 24 others
In a stmt of an interactive GHCi command: print it
*** Exception: <interactive>:4:1:
Found hole _?h with type Show a0 => IO a0
In a stmt of an interactive GHCi command: it <- f
(deferred type error)
In short, it shows the type of the hole to be Show a0 => IO a0
, which is caused by the print it
ghci calls internally to run the expression.
This is probably related to #1 and #3.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.