#4459: Polymorphic Data.Dynamic
-----------------------------------------------------+----------------------
    Reporter:  vivian                                |        Owner:  vivian    
  
        Type:  feature request                       |       Status:  new       
  
    Priority:  normal                                |    Milestone:  7.4.1     
  
   Component:  GHC API                               |      Version:  7.1       
  
    Keywords:  polymorphic, dynamic, class, linking  |     Testcase:            
  
   Blockedby:                                        |   Difficulty:            
  
          Os:  Unknown/Multiple                      |     Blocking:  4316      
  
Architecture:  Unknown/Multiple                      |      Failure:  
None/Unknown
-----------------------------------------------------+----------------------

Comment(by vivian):

 Replying to [comment:14 simonpj]:
 >
 >  * When unwrapping an overloaded polymorphic value at runtime, you'd
 need to build a suitable dictionary to apply it to.  This is no easy
 matter: you might need the dictionary for `(Ord (Tree [Maybe Int]))`, say.
 That is, you need to invoke the full type-constraint solver, in the
 correct type environment.

 If you wanted to solve the latter problem, I think you could get close
 like this
     * Construct the `HsSyn` syntax tree for
 {{{
 \(x :: forall a. Ord a => [a] -> [a]) -> (x :: [ty] -> [ty]
 }}}
       where `ty` is the type you want to instantiate `sort` at.
     * Use GHCi to typecheck and compile this
     * Apply it to the polymorphic `sort`.  That will give you a sort of
 type `[ty] -> [ty]`.
 >
 >
 >
 e.g.
 {{{
 t  :: Ord a => [a] -> [a]
 st :: [Int] -> [Int]
 }}}
 I can construct the abstract syntax tree as suggested, however, I do not
 know
   * how to correctly generate a binding/bound variable pair
   * how to generate the dictionary.
 Here is the HsExpr for the function
 {{{
 (Ord a => [a] -> [a]) -> ([Int] -> [Int])
 }}}
 {{{
       let adaptor = GHC.HsLam
                    (GHC.MatchGroup
                     [GHC.noLoc $ GHC.Match
                      [GHC.noLoc $ GHC.VarPat id] Nothing
                      (GHC.GRHSs [GHC.noLoc $ GHC.GRHS [] $
                                     GHC.noLoc $
                                  (GHC.HsApp (GHC.noLoc $ GHC.HsVar id)
                                      the_dictionary)]
                       GHC.EmptyLocalBinds)] (mkFunTy t st))
 }}}
 I.e. how do I generate `id` and `the_dictionary`?

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

_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to