I'm trying to interface OpenMP with another language that emits C code (a C code generator). From my perspective (I'm not the designer of the other language), it will be easiest to do this by calling a C function or function-like macro instead of using #pragma or _Pragma directly. I do not have much experience with the C preprocessor, but I have gotten a simple example found on wikipedia to work in a non-satisfactory way. Here is the original C …
是否可以在 Python 3.6+ 中实现自定义的自动/隐式转换(又名强制转换),而不会让mypy其他静态分析器感到难过?一个例子是 a def(foo: A),并给出def b_to_a(b: B) -> A,有没有办法我可以写foo(some_b)(where some_b: B) 而不是foo(b_to_a(some_b))?
我认为在 Python 的动态中肯定有一些很好的方法可以做到这一点(例如,将成员添加到包含转换器的类),甚至将此类转换器添加到函数对象本身,以便它可以处理选定类型的转换,但我目前对 Python 类型的理解让我觉得它不会满足mypy等等。
要进行比较,请参阅 Scala 的隐式转换。
我在解析这个问题时遇到了一些麻烦。但当我把它写出来时,我想我可能拥有它。
let add = { __functor = self: x: x + self.x; };
inc = add // { x = 1; };
in inc 1
Run Code Online (Sandbox Code Playgroud)
首先,是self像许多面向对象语言中那样的关键字还是只是一个常规名称?
其次,我试图理解 的:定义中的倍数在做什么__functor,但这可能是我对 Nix 表达式基本熟悉的失败,但我想发生的事情是 和self都是x参数__functor,即,它看起来就像它可能是一个柯里化函数。
所以实际上,我认为__functor这就是fmapHaskell 中的内容,并且self( add) 是函子本身,并且是Haskell 中x: x + self.x映射的函数。fmap
我想将我的项目组织到不同的库中,因为最终我可能会将一些拆分到外部存储库中。
在一个.cabal文件中,我可以有多个库(我相信一个未命名,多个命名):
library
import: servant-deps
exposed-modules:
App
other-modules:
Paths_cow_streamer
hs-source-dirs:
src
build-depends:
servant-server >= 0.15
library sxapi
import: servant-deps
exposed-modules:
SxClient
other-modules:
Paths_cow_streamer
hs-source-dirs:
sxapi
build-depends:
http-client
Run Code Online (Sandbox Code Playgroud)
最初我在我的 hpack 中尝试这样package.yaml:
library:
bar:
source-dirs:
- src
dependencies:
- servant-server >= 0.14
- wai
- warp
foo:
source-dirs:
- sxapi
dependencies:
- servant-server >= 0.14
- wai
- warp
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,似乎没有一个条目被正确解释,因为例如 source-dirs 不存在于生成的 cabal 文件中。
我也试过这个,但不出所料,库定义之一被覆盖:
library:
source-dirs:
- src
dependencies:
- servant-server >= 0.14
- wai
- warp …Run Code Online (Sandbox Code Playgroud) 我认为唯一有趣的是我的导入和我的 cabal 文件。以下是导入以及我将如何使用有问题的导入 ( Database.CQL.IO.Log) 的演示。
module FDS.Database.Cassandra where
import Prelude hiding(init)
import Database.CQL.IO as Client hiding(Logger)
import Database.CQL.IO.Log as CQLLog
import qualified Database.CQL.Protocol as CQL
import Numeric.Natural
import System.Logger (Logger)
cqlLogger :: Logger -> CQLLog.Logger
cqlLogger logger = undefined
Run Code Online (Sandbox Code Playgroud)
但是,我收到错误:
src/FDS/Database/Cassandra.hs:7:1: error:
Could not load module `Database.CQL.IO.Log'
It is a member of the hidden package `cql-io-1.1.0'.
Perhaps you need to add `cql-io' to the build-depends in your .cabal file.
Use -v to see a list of the files …Run Code Online (Sandbox Code Playgroud) 我确信我已经能够在其他情况下执行类似的操作,并且我相信这应该是可能的(/sf/answers/3513516331/):
{-# LANGUAGE TypeApplications #-}
module FDS.Database where
import Data.Typeable
import RIO (RIO)
-- other imports omitted
cowRecsByMark :: IsCowRec r => CowMark -> RIO FdsEnv [r]
cowRecsByMark markIn = do
cs <- initCass
liftIO $ cassGetRecsByMark cs tblName markIn
where tblName = type2tblName $ typeRep $ Proxy @r
Run Code Online (Sandbox Code Playgroud)
但是有了这段代码,我得到:
: error: Not in scope: type variable ‘r’
|
24 | where tblName = type2tblName $ typeRep $ Proxy @r
| ^
Run Code Online (Sandbox Code Playgroud) 签名应为:
tailMay :: Foldable f => f a -> Maybe (f a)
Run Code Online (Sandbox Code Playgroud)
为我提供了的定义headMay,这很有意义,并且(对我而言)非常聪明:
headMay :: Foldable f => f a -> Maybe a
headMay = foldr (const . Just) Nothing
Run Code Online (Sandbox Code Playgroud)
不幸的是,我还没有想到类似的东西tailMay,并且类似的实现似乎使用了魔术或不安全的函数。
如果这不可能,那么(Applicative t, Foldable t)对我有用的东西也可以满足我的目的(我收集的内容也暗示Traversable t)。
首先,我很抱歉没有一个最小的例子(我可以尝试构建一个,但现在我有一个“之前和之后”的例子):
首先是具有内存泄漏的“之后”:
protoReceiver :: RIO FdsEnv ()
protoReceiver = do
logItS Info ["Entering FarmPCMessage protoReceiver"]
tMap <- liftIO $ newThreadMap
fdsEnv <- ask
let lgr = fdsLogger fdsEnv
loopBody <- pure $ bracketOnError
(runResourceT $ protoServe fdsEnv tMap readFarmPCMessage)
(\(_,w) -> do
logLogItS Debug lgr ["Entering cleanup for protoReceiver"]
)
(\(server,_) -> do
logLogItS Debug lgr ["Entering FarmPCMessage protoReceiver bracket"]
server
.| mapMC (liftIO . traverse_ (persistFarmEntry fdsEnv))
.| mapMC ((logLogIt Info lgr) . pure)
.| sinkUnits & runConduitRes
) …Run Code Online (Sandbox Code Playgroud) 这是 IntelliJ 中该功能的演示(https://www.youtube.com/watch?v=EtnI2doW6XE)?
如果视频不可见,基本上用户按下组合键,然后弹出一个对话框,该对话框将根据用户开始输入的字符串进行响应和过滤。它将显示类和文件(以及许多更多)匹配您输入的内容。我不会详细介绍所有细节,因为我不是在寻找与此功能完全匹配的内容 - 如果它只是根据文件名搜索,我会很高兴首发!当我想切换到给定文件时,任何可以防止我在项目资源管理器中浏览文件名以在 vs 代码中打开文件的方法。
我看到了如何在 Visual Studio Code 中搜索文件?- 对我来说(在 Linux 上)Ctrl-E只显示我目前在项目资源管理器下打开的文件(有时很有用,但不是我要找的)。
我希望能够做到这样的事情:import qualified Data.Massiv.Array (qualified map).
这给了error: parse error on input `map'.
或者更好的import qualified Data.Massiv.Array (qualified map) as AM,所以我还可以访问foo如任一foo或者AM.foo,除非foo== map,那么我必须使用AM.map.这是为了避免与之发生冲突Prelude.map.