OCaml:签名中的类型约束(OCaml : type constraints in signatures)
在我的代码中,我有一个数据库访问上下文 ,它提供了基本的读/写操作,称为
CouchDB.ctx
。 然后,我的应用程序中的各个模块将使用其他功能扩展该类,如Async.ctx
。我正在实现一个环绕
Source
模块的Cache
模块。Cache
模块函数使用上下文参数并操作数据库。 然后将一些调用与上下文一起转发到Source
模块。我需要定义一个仿函数:
module CouchDB = struct class ctx = object method get : string -> string option monad method put : string -> string -> unit monad end end module AsyncDB = struct class ctx = object inherit CouchDB.ctx method delay : 'a. float -> (ctx -> 'a monad) -> 'a monad end end module type SOURCE = sig class ctx = #CouchDB.ctx (* <-- incorrect *) type source val get : source -> ctx -> string monad end module Cache = functor(S:SOURCE) -> struct class ctx = S.ctx type source = S.source let get source ctx = bind (ctx # get source) (function | Some cache -> return cache | None -> bind (S.get source ctx) (fun data -> bind (ctx # put source data) (fun () -> return data)) end module SomeSource = struct class ctx = AsyncDB.ctx type source = string let get s ctx = ctx # async 300 (some_long_computation s) end module SomeCache = Cache(SomeSource)
问题是,我无法表达
Source
模块使用的上下文应该是CouchDB.ctx
的子类型的CouchDB.ctx
。 上面的代码返回错误:A type variable is unbound in this type declaration. In type #CouchDB.ctx as 'a the variable 'a is unbound
我如何表达这种类型约束?
In my code, I have a database access context that provides elementary read/write operations, called
CouchDB.ctx
. Various modules in my application then extend that class with additional functionality, such asAsync.ctx
.I am implementing a
Cache
module which is wrapped around aSource
module. TheCache
module functions take a context argument and manipulate the database. Some calls are then forwarded to theSource
module along with the context.I need to define a functor along the lines of this:
module CouchDB = struct class ctx = object method get : string -> string option monad method put : string -> string -> unit monad end end module AsyncDB = struct class ctx = object inherit CouchDB.ctx method delay : 'a. float -> (ctx -> 'a monad) -> 'a monad end end module type SOURCE = sig class ctx = #CouchDB.ctx (* <-- incorrect *) type source val get : source -> ctx -> string monad end module Cache = functor(S:SOURCE) -> struct class ctx = S.ctx type source = S.source let get source ctx = bind (ctx # get source) (function | Some cache -> return cache | None -> bind (S.get source ctx) (fun data -> bind (ctx # put source data) (fun () -> return data)) end module SomeSource = struct class ctx = AsyncDB.ctx type source = string let get s ctx = ctx # async 300 (some_long_computation s) end module SomeCache = Cache(SomeSource)
The problem is that I cannot express the fact that the context used by the
Source
module should be a subtype ofCouchDB.ctx
. The above code returns the error:A type variable is unbound in this type declaration. In type #CouchDB.ctx as 'a the variable 'a is unbound
How do I express this type constraint ?
原文:https://stackoverflow.com/questions/10588382
最满意答案
尝试
mesh.lookAt( camera.position );
网格的局部z轴应该指向相机。
Try
mesh.lookAt( camera.position );
The local z-axis of the mesh should then point toward the camera.
相关问答
更多-
尝试 mesh.lookAt( camera.position ); 网格的局部z轴应该指向相机。 Try mesh.lookAt( camera.position ); The local z-axis of the mesh should then point toward the camera.
-
使用Face API识别用户(Using Face API To Identify Users)[2024-03-19]
目前,是的,这是唯一的方法。 考虑到每秒10个事务限制,这显然使扫描100万人的情况不太理想。 有一些即将推出的功能可以改善这种情况,但是现在我没有为他们提供ETA: 每人组的人数限制显着增加 Face API的其他层,允许显着更高的每秒事务速率限制。 Currently, yes, that is the only way to do it. Which obviously makes scanning 1 million persons a less than ideal scenario given ... -
@font-face不允许多个src属性。 像这样缩小它: @font-face { font-family: BigNoodleTitling; src: url('../Files/Fonts/big_noodle_titling.eot?#iefix') format('embedded-opentype'), url('../Files/Fonts/big_noodle_titling.woff2') format('woff2'), url('../Files/ ...
-
如果要检查本地文件,首先要做: @font-face { font-family: 'Green Sans Web'; src: local('Green Web'), local('GreenWeb-Regular'), url('GraublauWeb.ttf'); } 有一个更详细的描述,在这里做什么 。 If you want to check for local files first do: @font-face { font-family: 'Green Sans W ...
-
使用@ font-face和ABCPDF?(Using @font-face with ABCPDF? Or other way of getting fonts into PDF?)[2023-06-20]
WebSuperGoo回应道: ABCpdf目前不支持使用@ font-face添加的字体。 所以,从ABCpdf的9.0版本开始,就是这样。 NOTE: As of ABCpdf 11, this works. Font files must either be at an accessible HTTP/HTTPS url (works with either AddImageHTML() or AddImageURL() or, if you wish to use a file:/// URL, y ... -
有没有办法检测用户的浏览器是否支持@ font-face?(Is there a way to detect whether a user's browser is supporting @font-face?)[2023-08-28]
Modernizr有这个内置。 这是一个只检查@ font-face支持的构建的链接。 http://modernizr.com/download/#-fontface-shiv-cssclasses-teststyles-load 然后你可以检查JS for Modernizr.fontface或css for .fontface { } 。 以下是对如何操作的精彩解释: http : //paulirish.com/2009/font-face-feature-detection/ 要清楚,除了某些版本 ... -
jQuery有一个函数fontAvailable,你可以检查是否加载了fontface字体: $(document).ready(function() { if(!$.fontAvailable('FontFaceFontName')) { // Your Cufon Replace Code } }); jQuery has a function fontAvailable where you can check if the fontface font is loade ...
-
iOS11 ARKit:ARKit是否也可以捕捉用户脸部的纹理?(iOS11 ARKit: Can ARKit also capture the Texture of the user's face?)[2023-03-08]
你想要一个面部的纹理贴图风格的图像? 没有API能够完全实现这一目标,但您需要的所有信息都在那里: ARFrame.capturedImage您提供相机图像。 ARFaceGeometry您提供脸部的3D网格。 ARAnchor和ARCamera一起告诉您脸部相对于相机的位置,以及相机与图像像素的关系。 因此,完全可以使用当前视频帧图像来纹理人脸模型。 对于网格中的每个顶点... 将顶点位置从模型空间转换为相机空间(使用锚点的变换) 用该矢量乘以相机投影以得到标准化的图像坐标 除以图像宽度/高度以获得像素坐 ... -
Android有面部检测API 。 您只需为位图调用findFaces方法即可。 您还可以使用外部库和OpenCV等框架。 根据你的观点 - 你用于面部检测的framefork? Android have face detection api. You can just call findFaces method for bitmap. Also you cat use external libs and frameworks like OpenCV. According your points - whi ...
-
如果您不关心调用基本updateMatrix函数,这可以是一个解决方案 yourShapeGeometry.prototype.updateMatrix = function(){ // THREE.Object3D.prototype.updateMatrix.call(this); fixOrientation(this.textValue); } function fixOrientation(mesh){ mesh.setRotationFromQuaternion(camera.qua ...