Coder Social home page Coder Social logo

xnyhps / ghc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ghc/ghc

2.0 2.0 1.0 94.81 MB

Mirror of ghc repository. DO NOT SUBMIT PULL REQUESTS HERE

Home Page: http://www.haskell.org/ghc/

License: Other

Haskell 81.80% Shell 0.17% Perl 0.25% C 12.92% Puppet 1.18% TeX 2.53% Racket 0.05% C++ 0.26% Objective-C 0.18% CSS 0.01% Assembly 0.03% D 0.02% Python 0.60% Haxe 0.01% Emacs Lisp 0.01%

ghc's People

Contributors

andygill avatar autc04 avatar batterseapower avatar benl23x5 avatar catamorphism avatar clefru avatar dcoutts avatar donsbot avatar dreixel avatar ezyang avatar ggreif avatar hvr avatar igfoo avatar julian-seward1 avatar kgardas avatar krangelov avatar lemmih avatar mainland avatar mchakravarty avatar monoidal avatar nomeata avatar nominolo avatar pcapriotti avatar pepeiborra avatar rrthomas avatar simonmar avatar thoughtpolice avatar tibbe avatar twanvl avatar yav avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ghc's Issues

No -XNoMonomorphismRestriction: GHC.Prim.Any * types show up

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

-XNoMonomorphismRestriction: Holes aren't reported

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)}

-XNoMonomorphismRestriction: Named holes aren't shared

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.

-XNoMonomorphismRestriction: Show and IO leak to the type of the hole

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.