
2. "Fails instances", which are of the form `instance Num Char fails`;
#9334: Implement "instance chains" -------------------------------------+------------------------------------- Reporter: diatchki | Owner: diatchki Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.9 Component: Compiler | Keywords: (Type checker) | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by aavogt): Replying to [comment:6 diatchki]: they enable programmers to state explicitly that an instance should never exits. Interestingly, I just found a very related ticket asking for the same sort of thing (#7775). In some sense this can already be done: {{{ class FailHasNoInstances a => Fail a class FailHasNoInstances a -- not exported to ban Fail instances instance Fail "Char may not have a Num instance" => Num Char main = print $ '1' + '1' {- has a compile failure: No instance for (Fail "Char may not have a Num instance") arising from a use of ‘+’ In the second argument of ‘($)’, namely ‘'1' + '1'’ In the expression: print $ '1' + '1' In an equation for ‘main’: main = print $ '1' + '1' -} }}}
3. "Using instance contexts when selecting instances (aka backtracking)": currently, if the head of an instance matches a goal, GHC commits to it and then fails if it encounters an error; an alternative design would be to back-track and try a different option (e.g., next member of an instance group, or a more general matching instance).
Perhaps with a class like {{{ class HasInstance (cxt :: Constraint) (b :: Bool) | cxt -> b }}} you can encode backtracking without too much pain, and the meaning of existing programs does not change. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9334#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler