[GHC] #11715: Constraint vs *

GHC ghc-devs at haskell.org
Tue Aug 23 12:54:26 UTC 2016


#11715: Constraint vs *
-------------------------------------+-------------------------------------
        Reporter:  bgamari           |                Owner:
            Type:  bug               |               Status:  new
        Priority:  high              |            Milestone:  8.2.1
       Component:  Compiler (Type    |              Version:  8.0.1-rc1
  checker)                           |
      Resolution:                    |             Keywords:  Typeable
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by goldfire):

 Ah. I suppose comment:40 was clear from the beginning, but your

 {{{
 f :: Int -> ...
 helper :: Int => ...
 }}}

 (without bodies) confused me.

 Perhaps we can phrase your intent in terms of implicit parameters: a
 "type" (as opposed to a constraint) appearing left of `=>` is just like an
 implicit parameter with a distinguished name `""`. Now, understanding
 `with 3 $ with 4 $ ...` is easy: the `...` will have access to `4`, which
 shadows `3`. I'm not saying it would necessarily be ''implemented'' like
 implicit parameters, but our understanding of IPs can inform this new
 feature.

 As for your suggestion

 > if a function is ill-typed, try replacing the first -> with a =>. If
 this makes the function well-typed, adjust the error message accordingly.

 I'm afraid this would be hard to implement, because types can appear in so
 many different contexts. But here's an idea: We add a "validity" check --
 something not really part of the type system -- that looks for types like
 `Ord a -> a -> Set a`. The validity check will fail if it sees a type to
 the left of an `->` that is headed by a class. To disable the validity
 check, enable `-XExplicitDictionaries`. But the error message would
 suggest using `=>` more prominently than enabling
 `-XExplicitDictionaries`! This validity check might not catch all cases
 all the time, but it would catch the common newbie error Edward brought
 up.

 Thinking about `Int =>` as a special implicit parameter makes this more
 palatable to me, somehow.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11715#comment:41>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list