[GHC] #9819: Create typesafe method of obtaining dictionary types from class definitions, and constraint objects from dictionary types
GHC
ghc-devs at haskell.org
Sat Nov 22 21:19:45 UTC 2014
#9819: Create typesafe method of obtaining dictionary types from class
definitions, and constraint objects from dictionary types
-------------------------------------+-------------------------------------
Reporter: | Owner:
spacekitteh | Status: new
Type: feature | Milestone:
request | Version:
Priority: normal | Keywords:
Component: Compiler | Architecture: Unknown/Multiple
Resolution: | Difficulty: Moderate (less
Operating System: | than a day)
Unknown/Multiple | Blocked By:
Type of failure: | Related Tickets:
None/Unknown |
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by goldfire):
I'm not sure what you mean by "grant access"... but perhaps this will
help: When you pattern match on the `Dict` constructor, you get the `c`
constraint in the context. So, the following is conceivable:
{{{
-- this type is actually from ekmett's "constraints" package
data Dict c where
Dict :: c => Dict c
class IntLike a where
fromInt :: Int -> a
toInt :: a -> Int
dictForIntLikeString :: Dict (IntLike String)
dictForIntLikeString = ...
stringToInt :: String -> Int
stringToInt s = case dictForIntLikeString of
Dict -> toInt s
}}}
Note that there is no `instance IntLike String` around -- the reason
`toInt` can be called in `stringToInt` is because of the pattern-match on
`Dict`. Now, this example falls apart because the implementation of
`dictForIntLikeString` seems impossible without a `instance IntLike
String` dictionary available. But perhaps this answers your question about
what `Dict` can do.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9819#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list