小编jei*_*iea的帖子

如何使用REPL和CPS功能?

我刚刚遇到withSession :: (Session -> IO a) -> IO awreq包.我想逐行评估延续,但我找不到任何方法.

import Network.Wreq.Session as S
withSession $ \sess -> do
  res <- S.getWith opts sess "http://stackoverflow.com/questions"
  -- print res
  -- .. other things
Run Code Online (Sandbox Code Playgroud)

在上面的代码片段中,如何print res在ghci中进行评估?换句话说,我可以Session输入ghci吗?

haskell

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

这个 YesodAuth 实例有什么问题?

我刚刚从当前的 yesod 脚手架迁移到了最新的yesod-1.6.0, yesod-auth-1.6.2.

instance YesodAuth App where
    type AuthId App = UserId

    -- ....

    authenticate creds = runDB $ do
        x <- getBy $ UniqueUser $ credsIdent creds
        case x of
            Just (Entity uid _) -> return $ Authenticated uid
            Nothing -> return $ UserError InvalidUsernamePass
Run Code Online (Sandbox Code Playgroud)

在迁移之前,此代码运行良好。但是之后出现以下错误。

.../src/Foundation.hs:212:26: error:
    • Could not deduce: m ~ HandlerFor site8
      from the context: (MonadHandler m, HandlerSite m ~ App)
        bound by the type signature for:
                   authenticate :: forall (m …
Run Code Online (Sandbox Code Playgroud)

haskell yesod

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

如何将结构引用转换为isize?

我想进入b以下代码.

unsafe {
    struct Test {
        num: i32,
    }
    let a = Test { num: 0 };
    let b = &mut a as isize;
}
Run Code Online (Sandbox Code Playgroud)

但它会导致以下错误消息.

error: casting `&on_create::Test` as `isize` is invalid
   --> main.rs:181:15
    |
181 |       let b = &a as isize;
    |    
Run Code Online (Sandbox Code Playgroud)

我认为它会被强制执行*const _,然后应用ptr-addr-cast.我错过了什么?我应该用mem::transmute吗?

rust

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

我可以只使用类型而不是具体变量来获取Rust数组的长度吗?

我想将以下C++代码重写为Rust:

using storage = array<int, 3>;
const size_t storage_len = sizeof(storage) / sizeof(storage::value_type);
Run Code Online (Sandbox Code Playgroud)

如何在没有具体变量的情况下获得恒定长度值?

作为动机,尽管看起来似乎微不足道,但我想在不声明变量的情况下打印数组的元素数.我知道我可以使用常量值或声明一个虚拟变量,但我想知道Rust如何保存C++代码.

我承认没有具体变量尚不清楚.我想实现上述C++功能,但这种解释可能会产生误导.我很好奇是否有任何方法可以获得数组的元素类型.

arrays constant-expression rust dependent-type

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