可以同时运行多个提示实例吗? [英] Is it possible to run several instances of hint in parallel?

查看:96
本文介绍了可以同时运行多个提示实例吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以启动两个提示解释器,并且在运行时&随后将较小的计算分配给其中一个或另一个?当我调用一个小表达式(例如键入一个网站)的提示时 - 没有可靠的测试 - 在我看来,开始/加载提示的时间大约是一秒钟。如果实例已经启动,那么第二个将被剃光。



这个提示似乎没有任何功能,我可以启动它并保存好以备后用。



(Auto)插件当然是一个更进一步的选择,但我认为这对于较小的计算而言更适合模块和较不优雅的应用。 解决方案

GHC api,这个提示是用各种插件包来实现的,并不支持并发使用。

你可以让提示运行,但是。它是 MonadIO 的一个实例。

  interpreterLoop ::(MonadIO m,可键入的)a => Chan((MVar a,String)) - > InterpreterT m()
interpreterLoop ch = do
(mvar,command)< - liftIO $ readChan ch
a< - 解释命令$ argTypeWitness mvar
liftIO $ putMVar mvar a
interpreterLoop ch
其中
argTypeWitness :: MVar a - > a
argTypeWitness =未定义 - 此值仅用于类型检查,从未评估过

runInLoop :: Typeable a => Chan((MVar a,String)) - >字符串 - > IO a
runInLoop ch command = do
mvar< - newEmptyMVar
writeChan ch(mvar,command)
takeMVar mvar

(我没有测试这个,所以我可能错过了一两个细节,但基本的想法是可行的。)


Is there any way to start two hint interpreters and at runtime & subsequently assign smaller computations to either one or the other? When I invoke hint for a small expression (e.g. typed into a website) then, - without reliable testing -, it seems to me as if the time to start/load hint is approximately one second. If the instance is already started that second would be shaved.

The hint seems to have no function where I can start it and keep it nicely pending for later use.

(Auto)Plugins would be a further option of course but I think that is more suitable for modules and less elegant for smaller computations.

解决方案

The GHC api, which hint is implemented in terms of (the various plugin packages are, too), does not support concurrent use.

You can leave hint running, though. It's an instance of MonadIO.

interpreterLoop :: (MonadIO m, Typeable) a => Chan ((MVar a, String)) -> InterpreterT m ()
interpreterLoop ch = do
    (mvar, command) <- liftIO $ readChan ch
    a <- interpret command $ argTypeWitness mvar
    liftIO $ putMVar mvar a
    interpreterLoop ch
  where
    argTypeWitness :: MVar a -> a
    argTypeWitness = undefined -- this value is only used for type checking, never evaluated

runInLoop :: Typeable a => Chan ((MVar a, String)) -> String -> IO a
runInLoop ch command = do
    mvar <- newEmptyMVar
    writeChan ch (mvar, command)
    takeMVar mvar

(I didn't test this, so I may have missed a detail or two, but the basic idea will work.)

这篇关于可以同时运行多个提示实例吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆