在Java Concurrency in Practice的第65和66页上,Brian Goetz列出了以下代码:
@ThreadSafe
public class DelegatingVehicleTracker {
private final ConcurrentMap<String, Point> locations;
private final Map<String, Point> unmodifiableMap;
public DelegatingVehicleTracker(Map<String, Point> points) {
locations = new ConcurrentHashMap<String, Point>(points);
unmodifiableMap = Collections.unmodifiableMap(locations);
}
public Map<String, Point> getLocations() {
return unmodifiableMap;
}
public Point getLocation(String id) {
return locations.get(id);
}
public void setLocation(String id, int x, int y) {
if (locations.replace(id, new Point(x, y)) == null)
throw new IllegalArgumentException("invalid vehicle name: " + id);
}
// Alternate version of getLocations …Run Code Online (Sandbox Code Playgroud) Haskell 教程(https://www.fpcomplete.com/haskell/tutorial/monad-transformers/)说,如果我们假设以下定义
newtype State s a = State (s -> (s, a))
Run Code Online (Sandbox Code Playgroud)
那么下面的定义
newtype StateEither s e a = StateEither (State s (Either e a))
Run Code Online (Sandbox Code Playgroud)
是一个重写
newtype StateEither s e a = StateEither (s -> (s, Either e a))
Run Code Online (Sandbox Code Playgroud)
哪些替代步骤使这成为可能?
我想同步我的本地存储库,以便使本地成为主服务器的精确副本.检查后我已经添加了几个文件到我的本地,而不是主文件,我不想提交.不过,在这个过程中,我想删除本地与master的所有差异:当我完成后,本地的其他文件将被删除.
早期的问题提供了一种使本地像master一样的策略:将 本地存储库分支重置为远程存储库HEAD
但这对我不起作用.推荐的命令,git fetch origin git reset --hard origin/master
不要擦除本地的其他文件,即使git status表示local和master相同.而且,在一种情况下,主文件版本的文件并没有取代我的本地版本.
关于如何做到这一点的任何想法?
虽然是 Haskell 新手,但我之前使用过记录。它们易于使用。但是现在,当我希望从记录中提取一些数据时,出现“发现漏洞”错误。违规代码是:
let theSchemaId = _schemaId schema
Run Code Online (Sandbox Code Playgroud)
其中记录是这样定义的:
data Schema = Schema
{ _schemaId :: !SchemaId
, [ other fields ... ]
}
Run Code Online (Sandbox Code Playgroud)
这对我来说似乎非常直接,类似于我以前使用过的记录。但是,在运行上面的代码行时,出现以下错误。所有进口都到位。关于其原因的任何想法?
错误:
src/master/haskell-service/src/Handler/Strategy/Components/View.hs:695:34: error:
src/master/haskell-service/src/Handler/Strategy/Components/View.hs:695:34: error:
• Found hole: _schemaId :: Schema -> SchemaId
Or perhaps ‘_schemaId’ is mis-spelled, or not in scope
• In the expression: _schemaId
In the expression: _schemaId schema
In a pattern binding: theSchemaId :: SchemaId = _schemaId schema
• Relevant bindings include
theSchemaId :: SchemaId
Run Code Online (Sandbox Code Playgroud)