问题标签 [deriving]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
haskell - Haskell 为 Existentials 类型类派生 Eq 实例
有没有办法自动为 Eq (和显示)派生实例Power
?我设法找到http://www.haskell.org/ghc/docs/7.4.2/html/users_guide/deriving.html但我找不到与下面代码相关的任何解释。
此外,如果对下面创建的效果有更好的实践,我愿意接受建议,因为我是 Haskell 和函数式编程的新手。
编辑:我知道这是一种 hack,但由于它几乎都是用前奏函数完成的,它应该得到正确的结果,除非存在完全恶意代码(这是“开放世界假设”最常见的情况) .
haskell - 如何在 Haskell 中为 GADT 派生数据实例?
我有一个 GADT,它只与两个不同的参数 ForwardPossible 和 () 一起使用:
我想派生足够的 Data.Data 实例来涵盖 OrForward t () 和 OrForward t ForwardPossible。我认为一般 (Data t, Data forward) => OrForward t forward 实例是不可能的,除非它普遍忽略 OFForward,但是 Data t => OrForward t ForwardPossible 和 (Data t, Data forward) => 的重叠实例如果有办法让 ghc 派生这些实例,OrForward t 前向实例可能是一个解决方案。
我试过定义:
但随后 ghc 给了我一个这样的错误:
c++ - 错误:无效的基类 C++
请任何人解释一下可能导致此错误的原因?
我有两个类,其中一个派生自第二个:
CGameObject 看起来像这样:
我尝试清理我的项目但徒劳无功。
haskell - 如何为具有非 * 类型幻像类型参数的 GADT 导出 Eq
例如,尝试编译以下代码
给出类型错误
我可以看到为什么这不起作用,但是有一些解决方案不需要我手动编写 Eq(和 Ord)实例吗?
sql - 当前派生贷款项目
我有一张贷款信息表。
例子:
如您所见,用户 605 被借了一天设备,然后在第二天归还。然后设备在之后的第二天被借给了另一个用户。
考虑到该表具有跟踪移动的条目(包括跨日期的退货),我将如何尝试查找当前有哪些设备当前借给他们的用户。
任何有关如何解决此问题的想法将不胜感激。伪代码、SQL 或 LINQ 也可以。
谢谢
haskell - 模板 Haskell 引用中的独立派生声明
为什么模板 Haskell 忽略引用中的独立派生声明?
generics - 使用记录 Haskell 的泛型派生
我基本上是想看看我是否可以在 Haskell 中模拟 ORM 框架,这样如果用户想要制作数据库模型,他们会做这样的事情
表格是“汽车”,列是公司、型号、年份
要在 Haskell 中执行此操作,您必须使用类和泛型的组合,这就是我遇到的问题。使用本教程(http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/generic-programming.html),我想出了这个(基本上是复制和重命名,所以我可以得到代码工作)
上面的代码会产生错误
我有点卡在这一点上,我相信我已经实例化了所有必需的通用类型来覆盖记录
javascript - js_of_ocaml and Deriving_Json
I need some help to get js_of_ocaml working. There's not much information about it on the net, and the manual is very sparse (no snippets or usage examples, no comment sections).
I have a Card
module on the server with a card
record. I'm sending a card list
to the client using Ajax, and there I want to read and traverse this list. What I end up with is this:
...where json
has type 'a
, according to documentation (not when I run it, of course).
I can log json##length
and get the correct length of the list. Where do I go from here? Ideally, I'd like to use Deriving_Json
to type-safe get a card list
again, but I could also use a for-loop (not as elegant, but whatever).
haskell - Haskell:以字符串形式获取数据构造函数名称
让我们说我们有
我希望有一个功能getDConst
根据用于其输入的数据构造函数返回“X”、“Y”或“Z”。有没有一种通用的方法来编写这个而不必case
对每个数据构造函数都做?(我可以接受依赖Data.Typeable
或类似的解决方案)
haskell - Haskell Deriving Show Instance
I am playing with a Red-Black tree:
If I execute the following statement in GHCi:
The following error message tells me there is not an instance of show for Set Char
:
I know the tree is working because by calling member 'b' ...
where ...
is the previously executed statement, the returned value is True
. I've been reading the other SO posts on this problem but the solutions found for them (e.g.:Haskell: Deriving Show for custom type) does not work.
For example, by adding:
I get the following error message when I try to load using :l
:
:l red-black-tree.hs [1 of 1] Compiling RedBlackTree ( red-black-tree.hs, interpreted )
I think there are a few problems going on with what I'm trying to do but I can't seem to figure it out from the available documentation.