据推测,他们完全一样,concatMap f xs并且concat $ map f xs.为什么我会选择一个而不是另一个?
我想这可能是一个优化.如果是这样,GHC 7.8仍然如此吗?
我想在bash中编写以下函数:
go() {
cd "~/project/entry ${1}*"
}
Run Code Online (Sandbox Code Playgroud)
这样做是cd进入一个带有前缀entry(注释空格)的项目子目录,可能还有一个长后缀.我只需要给它一个部分名称,它将完成目录名称的后缀.
所以,例如,如果我有以下文件夹:
~/project/entry alpha some longer folder name
~/project/entry beta another folder name
~/project/entry gamma
Run Code Online (Sandbox Code Playgroud)
我可以跑go b,它会让我进入~/project/entry beta another folder name.
当然,问题是通配符不会在双引号内扩展.我不能省略引号,因为那时我将无法正确捕获空格.
如何在保留空格的同时扩展通配符?
ADT是免费的monad:
data Free f r = Free (f (Free f r)) | Pure r
Run Code Online (Sandbox Code Playgroud)
我希望它能够得到它,Show以便我可以在使用它时将其打印出来.例如,如果我有以下内容:
data T next = A next | B next deriving (Show)
aa = Free $ A $ Free $ B $ Pure ()
Run Code Online (Sandbox Code Playgroud)
就像现在一样,如果我添加deriving (Show)到FreeADT ,我会收到以下错误:
No instance for (Show (f (Free f r)))
arising from the first field of ‘Free’ (type ‘f (Free f r)’)
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the …Run Code Online (Sandbox Code Playgroud) 在Haskell中,我能够使用以下方法启用列表的并行评估:
map expensiveFunction list `using` parList rdeepseq
Run Code Online (Sandbox Code Playgroud)
仅添加`using` parList rdeepseq能够实现纯并行计算,并且在我的四核处理器上运行速度提高了4倍.
使用SBCL有类似的功能吗?
说我有这个:
data Animal = Dog | Cat
:t Dog
Dog :: Animal
Run Code Online (Sandbox Code Playgroud)
很公平.
:k Dog
<interactive>:1:1:
Not in scope: type constructor or class ‘Dog’
A data constructor of that name is in scope; did you mean DataKinds?
Run Code Online (Sandbox Code Playgroud)
因为狗是一种价值而不是一种类型,所以不要指望它能够发挥作用.你不能得到一种价值,只有一种类型,对吧?
但是,如果我这样做:
:set -XDataKinds
data Animal = Dog | Cat
:k Dog
Dog :: Animal
Run Code Online (Sandbox Code Playgroud)
这意味着你能获得一种价值是什么意思?
这是我的代码.它使用的CBUUID是Core Bluetooth.我们假设演员阵容v有效.
import UIKit
import CoreBluetooth
func convert(v: AnyObject) -> [String: String] {
return (v as! [CBUUID: NSData]).map { (uuid, data) in
(uuid.UUIDString, NSString(data: data, encoding: NSUTF8StringEncoding) ?? "")
}
}
Run Code Online (Sandbox Code Playgroud)
我们的想法是通过调用得到字典的字符串表示CBUUID.UUIDString的CBUUID,并通过调用适当NSString的构造函数NSData.
我已将字典转换为特定类型.为什么我在这里得到"模糊的参考成员'地图'"?
请考虑以下代码:
run = runExcept $ do
case Just 1 of
Nothing -> throwE "escape 1"
Just x -> do
case Just 2 of
Nothing -> throwE "escape 2"
Just y -> do
case Just 3 of
Nothing -> throwE "escape 3"
Just z -> return z
Run Code Online (Sandbox Code Playgroud)
假装的Just 1,Just 2,Just 3是函数调用的返回Maybe Int.
整个函数都在一个内部,ExceptT因为我想抛出异常.但内心实际上只是Maybe被操纵的很多价值观.
那么,我是否有可能利用Maybemonad 的行为来避免阶梯套管,同时仍能抛出异常?
我对Rust for循环的工作方式感到困惑。考虑以下:
#![feature(core_intrinsics)]
fn print_type_of<T>(_: T) {
println!("{}", unsafe { std::intrinsics::type_name::<T>() });
}
fn main() {
let nums = vec![1, 2, 3];
for num in &nums { print_type_of(num); }
for num in nums { print_type_of(num); }
}
Run Code Online (Sandbox Code Playgroud)
它输出以下内容:
&i32
&i32
&i32
i32
i32
i32
Run Code Online (Sandbox Code Playgroud)
传递向量for与引用向量相比是什么意思?为什么当您传递参考时,您获得对项目的参考,而当您传递实际向量时,却获得了实际项目?
I am trying to interact with Bluez 5.44 using the dbus-send command line tool. I cannot seem to get it to start discovery properly, although it works fine when I use bluetoothctl's scan on and scan off commands. I can also start and stop discovery using d-feet.
I've tried powering off and on prior to issuing the command, but it doesn't seem to get discovery started.
The command line I'm using is:
dbus-send --system --type=method_call --print-reply --dest=org.bluez \ …Run Code Online (Sandbox Code Playgroud)