#4459: How to apply one type to another
Vivian McPhail
haskell.vivian.mcphail at gmail.com
Tue Jul 5 06:08:02 CEST 2011
Hi,
I think the `forall a` is binding `[Int]` which explains the previous error.
I now have
`st :: [Int] -> [Int]` -- result of unification and substitution
`tx :: [Int] -- argument type
I can `mkAppTy st tx` which gives an unapplied application
`mkAppTy st tx` --> [Int] -> [Int] [Int]
how do I get that application to be applied?
Vivian
On 4 July 2011 14:51, Vivian McPhail <haskell.vivian.mcphail at gmail.com>wrote:
> Hi,
>
> I have two variables
>
> spin :: forall a. [a] -> [a]
> alist :: [GHC.Types.Int]
>
> I can dynamically load and apply them. What I cannot figure out how to do
> is apply the type of `spin` to the type of `alist` to get
>
> (spin alist) :: [GHC.Types.Int]
>
> When I use `Type.applyTy` I get the erronious type
>
> [[GHC.Types.Int]] -> [[GHC.Types.Int]].
>
> Code:
>
> dynApply :: DynamicHValue -> DynamicHValue -> DynType (Maybe DynamicHValue)
> dynApply (DynamicHValue tf f) (DynamicHValue tx x) =
> GHC.gcatch (do
> liftIO $ putStrLn $ showSDoc $ pprType tf
> liftIO $ putStrLn $ showSDoc $ pprType tx
> if not (isForAllTy tf)
> then do
> liftIO $ putStrLn "not ForAllTy"
> return Nothing
> else do
> liftIO $ putStrLn "ForAllTy"
> let (_,typ) = splitForAllTys tf
> liftIO $ putStrLn $ showSDoc $ pprType typ
> let ((at:_),_) = splitFunTys typ
> liftIO $ putStrLn $ showSDoc $ pprType at
> let vars = tyVarsOfTypes [at]
> let um = tcMatchTy vars at tx
> case um of
> Just ts -> do
> liftIO $ putStrLn $ "Type matched"
> (DynamicHValue aft af) <- dynAdaptor ts tf
> liftIO $ putStrLn $ "App Type"
> let ty = applyTy tf tx
> liftIO $ putStrLn $ showSDoc $ pprType ty
> return $ Just $ DynamicHValue ty
> (((unsafeCoerce af) f) x)
> Nothing -> return Nothing
> )
> (\(e :: GHC.GhcException) -> return Nothing)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/cvs-ghc/attachments/20110705/9be5e49f/attachment.htm>
More information about the Cvs-ghc
mailing list