我想在for-loop中注释一个变量类型.我试过这个:
for i: int in range(5):
pass
Run Code Online (Sandbox Code Playgroud)
但显然它没有用.
我期望在PyCharm 2016.3.2中进行自动完成工作.像这样的预注释:
i: int
for i in range(5):
pass
Run Code Online (Sandbox Code Playgroud)
没有帮助.
PS预注释适用于PyCharm> = 2017.1
假设,我有一个可能从另一个线程中取消的任务.该任务在C函数中执行,另一个线程运行C++代码.我怎么做?
粗略的例子.
C:
void do_task(atomic_bool const *cancelled);
Run Code Online (Sandbox Code Playgroud)
C++:
std::atomic_bool cancelled;
…
do_task(&cancelled);
Run Code Online (Sandbox Code Playgroud)
现在,我创建了一个atomics.h包含以下内容的文件:
#ifdef __cplusplus
#include <atomic>
using std::atomic_bool;
#else
#include <stdatomic.h>
#endif
Run Code Online (Sandbox Code Playgroud)
它似乎有效,但我没有看到任何保证.我想知道,如果有更好的(正确的)方式.
为什么范围如此具体?为什么不是 29 位宽或 32 位宽,为什么是 30 位宽?
理由是什么?标准(1)似乎没有给出它
假设我有一个简单的 GADT。
\ndata Expr a where\n Int\' :: Integer -> Expr Int\n Fun :: Text -> Expr a\n (:*) :: Expr (a -> b) -> Expr a -> Expr b\nRun Code Online (Sandbox Code Playgroud)\n现在,我可以定义以下遍历:
\ntransform :: Applicative f => (forall b. Expr b -> f (Expr b)) -> Expr a -> f (Expr a)\ntransform f (a :* b) = (:*) <$> transform f a <*> transform f b\ntransform f v = f v\nRun Code Online (Sandbox Code Playgroud)\n奇怪的是,从镜头上看,这种类型很像Traversal。然而,不完全是,它的排名更高。
我仍然可以定义 \xc2\xabconventional\xc2\ …
I made two pattern views for a list-like class.
infixr 5 :<
pattern (:<) :: Stream s => Token s -> s -> s
pattern b :< bs <- (uncons -> Just (b, bs))
where b :< bs = cons b bs
pattern Nil :: Stream s => s
pattern Nil <- (uncons -> Nothing)
where Nil = empty
Run Code Online (Sandbox Code Playgroud)
uncons signature: uncons :: (Stream s) => s -> Maybe (Token s, s).
Suppose I also have function that uses …
假设我有以下代码
\ndata F a where\n F :: Typeable a => F a\n\nasType :: forall b a. Typeable b => F a -> Maybe (a :~: b, F b)\nasType e@F{} = case eqT @b @a of\n Just Refl -> Just (Refl, e)\n Nothing -> Nothing\n\npattern AsType :: forall a b. Typeable a => (a ~ b) => F a -> F b\npattern AsType e <- (asType @a -> Just (Refl, e))\n\npattern AsInt :: Typeable b\' => (Int ~ b\') => …Run Code Online (Sandbox Code Playgroud) 为什么在签名中使用关联的类型同义词并不意味着相应的约束?
例如,为什么以下内容不能编译:
{-# LANGUAGE TypeApplications, ScopedTypeVariables, TypeFamilies, AllowAmbiguousTypes #-}
class MyClass a where
type AssociatedType a
bar :: Int
foo :: forall a. AssociatedType a -> Int
foo _ = bar @a
Run Code Online (Sandbox Code Playgroud)
ghc 8.6.5 给出以下错误:
error:
* No instance for (MyClass a) arising from a use of `bar'
Possible fix:
add (MyClass a) to the context of
the type signature for:
foo :: forall a. AssociatedType a -> Int
* In the expression: bar @a
In an equation for `foo': …Run Code Online (Sandbox Code Playgroud) 有很多方法可以从一个char创建一个std :: string.
std::string(1, ch)std::string() + chstd::string(&ch, 1)std::string {ch} \\ c++11我想知道哪一个我更喜欢.
haskell ×5
c++ ×2
atomic ×1
c ×1
c++11 ×1
for-loop ×1
ghc ×1
haskell-lens ×1
pycharm ×1
python ×1
python-3.6 ×1
type-hinting ×1