小编maj*_*zak的帖子

为什么必须在proc-macro crate中定义proc-macros?

我试图为我的特征创建一个派生宏,以简化一些内容。

我遇到了一些问题:

the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type
Run Code Online (Sandbox Code Playgroud)

并且,在进行小规模修复后proc-macro=true

proc-macro` crate types cannot export any items other than functions tagged with `#[proc_macro_derive]` currently
functions tagged with `#[proc_macro_derive]` must currently reside in the root of the crate`
Run Code Online (Sandbox Code Playgroud)

这种行为的原因是什么?

language-lawyer rust rust-macros

5
推荐指数
1
解决办法
970
查看次数

在 Haskell 中处理事件流

我想处理通过 MQTT 接收到的事件流。我正在使用的库使用回调来提供结果。我正在做的处理取决于以前的状态,而不仅仅是最新的事件。此外,未来的事件可能会从其他来源收集。

一开始我决定把它组合成一个听起来是个好主意的清单。我有一个小问题,因为 IO 阻止了延迟评估并且等待无限流可能很长,但我用交错 IO 解决了它。

stream :: IO [Event]允许我做的不错的东西一样foldlfoldM mapmapM,等...不幸的是这种方法我宁愿将无法在两个流合并,原因是没有更多的锁定功能存在。

我正在挖掘许多库,例如找到了带有 TQueue 的 STM。不幸的是,这不是我真正想要的。

我决定创建自定义类型并制作它,Foldable以便我能够折叠它。由于 IO,我失败了。

import Control.Concurrent.STM

newtype Stream a = Stream (STM a)

runStream
  :: ((a -> IO ()) -> IO i)
  -> IO (Stream a)
runStream block = do
  queue <- newTQueueIO
  block (atomically . writeTQueue queue)
  return $ Stream (readTQueue queue)

foldStream :: (a -> b -> IO b) -> b -> Stream a …
Run Code Online (Sandbox Code Playgroud)

concurrency haskell mqtt event-stream-processing

5
推荐指数
1
解决办法
323
查看次数

是否可以在kotlin中嵌套数据类?

我正在尝试实现类似以下C的类似数据类定义:

struct A {
  int b;
  struct {
     int d;
  } c; 
};
Run Code Online (Sandbox Code Playgroud)

According to Dmitry Jemerov it is possible, but he didn't provide any code sample. https://discuss.kotlinlang.org/t/is-there-a-reason-for-not-allowing-inner-data-classes/2526/5

You can simply make it nested inside another class. Nested classes can be data classes.

How it should be done if it is true?

kotlin data-class

3
推荐指数
1
解决办法
50
查看次数

Writing or generating lenses for nonrecord datatypes

I have a nonrecord newtype which I would like to generate the lenses for:

newtype Foo = Foo (Int, String)
Run Code Online (Sandbox Code Playgroud)

I would like to make a named lenses for it, currently I'm doing manually like follows:

bar :: Lans' Foo Int
bar = lens
  (\(Foo (x, y)) -> x)
  (\(Foo (x,y)) x' -> Foo (x', y))
Run Code Online (Sandbox Code Playgroud)

我更喜欢在这里使用一些 TH 魔法,或者至少使用更复杂的语法,例如:

bar :: Lens' Foo Int
bar = Foo <$> _1
Run Code Online (Sandbox Code Playgroud)

这有可能吗?

haskell haskell-lens

2
推荐指数
1
解决办法
55
查看次数

如何强制 Maven 使用 jcenter 存储库

我试图获得与 mvn 的依赖关系,但问题是其中一个包不在官方仓库中。我已经设法将 jcenter 添加到源代码中,但是 maven 似乎不适合在那里查看。

在这里它正确地寻找下一个回购

Downloading from central: https://repo.maven.apache.org/maven2/io/ktor/ktor-client-core/1.2.5/ktor-client-core-1.2.5.pom
Downloading from central: https://jcenter.bintray.com/io/ktor/ktor-client-core/1.2.5/ktor-client-core-1.2.5.pom
Run Code Online (Sandbox Code Playgroud)

但这里没有:

Downloading from central: https://repo.maven.apache.org/maven2/io/ktor/ktor-http/1.2.5/ktor-http-1.2.5.pom
[WARNING] Missing POM for io.ktor:ktor-http:jar:1.2.5
Run Code Online (Sandbox Code Playgroud)

mvn -Dartifact=io.ktor:ktor-client-core:1.2.5 -DremoteRepositories=central::default::https://jcenter.bintray.com/ dependency:get

maven jcenter

1
推荐指数
1
解决办法
1770
查看次数

种类 * 的函子实例

我有新类型:

newtype Foo = Foo ([Int])
Run Code Online (Sandbox Code Playgroud)

我想简单地Int -> Int在它上面应用函数,就像 fmap 一样。

我认为派生或实现Functor实例就足够了,但它需要* -> *一种类型。

是否有一些内置方法可以使我的类型部分fmap可用?

haskell

1
推荐指数
1
解决办法
88
查看次数