我希望以下代码将"15"转换为整数并打印结果,但它会引发错误.
main = print $ read "15" :: Integer
Couldn't match expected type `Integer' with actual type `IO ()'
Run Code Online (Sandbox Code Playgroud)
但只是使用main = print (read "15" :: Integer)运行良好.我的印象是$有效地围绕括号中的其余部分.为什么不在这种情况下工作?
我正在尝试编写一个类似于zip但不会丢弃额外元素的函数.我觉得我在某个地方犯了一个非常愚蠢的错误.
输入示例:
zipMaybe [1,2,3] [1,2]
Run Code Online (Sandbox Code Playgroud)
期望的输出:
[(Just 1, Just 1), (Just 2, Just 2), (Just 3, Nothing)]
Run Code Online (Sandbox Code Playgroud)
zipMaybe :: [a] -> [b] -> [(Maybe a, Maybe b)]
zipMaybe (a:as) (b:bs) = (Just a, Just b) : zip as bs -- line with error
zipMaybe (a:as) [] = (Just a, Nothing) : zip as []
zipMaybe [] (b:bs) = (Nothing, Just b) : zip [] bs
zipMaybe _ _ = []
Run Code Online (Sandbox Code Playgroud)
但是,这不会编译.
Test.hs:2:49:
Couldn't match type `a' with `Maybe a'
`a' …Run Code Online (Sandbox Code Playgroud) 我需要隐藏模块中的一些功能.如果import Graphics.UI.Gtk.Types我收到:
Could not find module `Graphics.UI.Gtk.Types'
it is a hidden module in the package `gtk-0.12.4'
Run Code Online (Sandbox Code Playgroud)
如何在不编辑和重新编译gtk的情况下导入此隐藏模块?
会话示例:
- cat myscript.sh
#!/bin/bash
tail -f example.log | grep "foobar" &
echo "code goes here"
# here is were I want tail and grep to die
echo "more code here"
- ./myscript.sh
- ps
PID TTY TIME CMD
15707 pts/8 00:00:00 bash
20700 pts/8 00:00:00 tail
20701 pts/8 00:00:00 grep
21307 pts/8 00:00:00 ps
Run Code Online (Sandbox Code Playgroud)
如您所见,tail 和 grep 仍在运行。
像下面这样的东西会很棒
#!/bin/bash
tail -f example.log | grep "foobar" &
PID=$!
echo "code goes here"
kill $PID
echo "more code here"
Run Code Online (Sandbox Code Playgroud)
但这只会杀死 …
Is there a way to have a Behavior t [a] where the values of [a] at time t are the values contained in a Behavior t [Behavior t a] at time t? I.e, a function with the type of:
Behavior t [Behavior t a] -> Behavior t [a]
Run Code Online (Sandbox Code Playgroud)
If this is not possible, is that because of a logical impossibility or a limitation in reactive-banana?
如果我有数据类型:
data Component = PositionC Double Double | HealthC Double | NameC String
Run Code Online (Sandbox Code Playgroud)
Components 的集合我可以使用什么技术,数据结构,TemplateHaskell功能来满足上述标准?
我已经尝试过Data.Set和Data.Map但没有成功.
Data.Map尝试:
import Data.Map
data Component = PositionC Double Double | HealthC Double | NameC String
-- Unacceptable code duplication
data ComponentType = PositionCT | HealthCT | NameCT
deriving (Eq, Ord)
type ComponentMap = Map ComponentType Component
foo :: ComponentMap
-- More annoying code duplication
foo = fromList [(HealthCT, HealthC 100), (NameCT, NameC "John")]
fooHealth = foo ! HealthCT -- …Run Code Online (Sandbox Code Playgroud) 英文解释:我要访问一个名为成员foo从关键元素"bar"从一个std::map<string, Parent *>地方Parent是一个抽象基类.
码:
#include <map>
#include <string>
#include <iostream>
using namespace std;
class Parent {
public:
virtual ~Parent() {}
};
class Child: public Parent {
public:
Child(): var(2) {}
int var;
};
int main() {
map<string, Parent *> children;
children["bar"] = new Child;
cout << children["bar"]->var << endl; // Erroneous line
cout << children.find("bar")->second->var << endl; // Different method, still gives the same error
return 0;
}
Run Code Online (Sandbox Code Playgroud)
错误: ‘class Parent’ …
例如,当wget完成时我将如何杀死尾巴.
#!/bin/bash
wget http://en.wikipedia.org/wiki/File:Example.jpg &
tail -f example.log
Run Code Online (Sandbox Code Playgroud)