我试图弄清楚如何编写一个函数取决于具有参数类型的模块,但我无法在任何地方找到类似的东西.我试图尽可能地减少问题,最后得到了这个虚拟的例子.
module type Mappable = sig
type 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
end
let plus (type m) (module M : Mappable with type 'a t = 'a m) (xs : int m) =
M.map (fun x -> x + 1) xs
Run Code Online (Sandbox Code Playgroud)
这会产生错误Error: Syntax error: module-expr expected.
如果我放弃'a,我最终得到以下错误.
Error: In this `with' constraint, the new definition of t
does not match its original definition in the constrained signature: …Run Code Online (Sandbox Code Playgroud) 虽然如此,但我对第一个并不感兴趣.
Customer foundCustomer = context.Set<Customer>().Include(e => e.Orders.Select ( d => d.OrderLines)).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
这很有效,我找到了我正在努力的比赛.
string custKey = "VINET";
Customer foundCustomer = context.Set<Customer>().Include(e => e.Orders.Select(d => d.OrderLines)).Where(c => c.CustomerID.Equals(custKey, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
这工作,并按我的意愿读取数据库,但没有我想要的包含.
Customer foundCustomer = context.Set<Customer>().Find(custKey);
Run Code Online (Sandbox Code Playgroud)
这不起作用....但是我实际上是在追求
Customer foundCustomer = context.Set<Customer>().Include(e => e.Orders.Select(d => d.OrderLines)).Find(custKey);
Run Code Online (Sandbox Code Playgroud)
有什么方法结合起来Include()使用Find()?
这是上下文.典型的Northwind Customer/Order(s)/ OrderDetails方案.
public partial class WindyContext : DbContext
{
static WindyContext()
{
//Database.SetInitializer<WindyContext>(null);
}
public WindyContext()
: base("Name=NorthwindContext")
{
}
public DbSet<Customer> Customers { get; set; }
public DbSet<OrderLine> DbSetOrderLines { get; set; …Run Code Online (Sandbox Code Playgroud) 我尝试将一个临时但不是那么临时的文件添加到Git存储库而不将其添加到索引中.我不想将它添加到.gitignore,也不想添加到〜/ .gitignore_global这样的文件,因为它只适用于特定的存储库.
有没有办法忽略要在特定存储库中编制索引的文件而不索引我想忽略它的事实?
我试图匹配Seq包含的情况Nothing.
models.Tasks.myTasks(idUser.toInt) match {
case tasks => tasks.map {
task => /* code here */
}
case _ => "" //matches Seq(models.Tasks)
}
Run Code Online (Sandbox Code Playgroud)
如何Seq[Nothing]在模式匹配中表示?
我正在学习haskell,我试图编写自己的反向函数而不使用递归.
解决方案是这个功能:
myreverse = foldl (flip (:)) []
Run Code Online (Sandbox Code Playgroud)
我试图了解评估过程中发生的事情,比如说:
myreverse [1..5]
Run Code Online (Sandbox Code Playgroud)
我无法理解这里有什么翻盖.有人可以通过逐步解释来记下这里发生的事情吗?
我有这样一棵树:
data Tree a
= Empty
| Leaf a
| Node a (Tree a) (Tree a) String
deriving (Show)
Run Code Online (Sandbox Code Playgroud)
我需要一个找到树顶的函数.我写了这个:
root :: Tree a -> a
root (Leaf a) = a
root (Node a _ _ _) = a
Run Code Online (Sandbox Code Playgroud)
哪个完美有效,但当我有一个空树时,我有一个错误信息.
如果我加
root Empty = Empty
Run Code Online (Sandbox Code Playgroud)
我再次出错,因为它没有返回类型的值a.我能做什么 ?