我将数据类型定义为:
data ComitteeView = CommitteeView { committeeId :: CommitteeId
, committeeMembers :: [Person]
}
data CommitteesView = CommitteesView { committeeView :: [CommitteeView] }
Run Code Online (Sandbox Code Playgroud)
现在,就目前而言,我将Persistent模型定义为:
Person
name Text
Committee
name Text
CommitteePerson
personId PersonId
committeeId CommitteeId
Run Code Online (Sandbox Code Playgroud)
我可以很容易地使用Esqueleto创建一个填充委员会视图的查询.它会是这样的:
getCommitteeView cid =
CommitteeView <$> runDB $
select $
from (person `InnerJoin` pxc `InnerJoin` committee) -> do
on (committee ^. CommitteeId ==. pxc ^. CommitteePersonCommitteeId)
on (person ^. PersonId ==. pxc ^. CommitteePersonPersonId)
where_ (committee ^. CommitteePersonCommitteeId ==. val cid)
return person
Run Code Online (Sandbox Code Playgroud)
现在,考虑填充问题CommitteesView …
Prelude> show _
<interactive>:7:6:
Found hole ‘_’ with type: a0
Where: ‘a0’ is an ambiguous type variable
Relevant bindings include it :: String (bound at <interactive>:7:1)
In the first argument of ‘show’, namely ‘_’
In the expression: show _
In an equation for ‘it’: it = show _
Run Code Online (Sandbox Code Playgroud)
如果GHC还告诉我输入的孔具有Show类型类约束,那将是很好的.
GHC版本7.8.1
我的网站和IE有问题.我有一个文件Document.ashx,它根据查询字符串中传递的参数成为我数据库中的文档.
该文件适用于:
如果:
Windows Internet Explorer
无法从MyHostName下载Document.ashx.
无法打开此Internet站点.
请求的网站不可用或无法找到.
请稍后再试.
有没有人知道会导致这种情况的原因.当然它在Firefox中运行良好.
我在办公室里找了几个人用IE来试试,他们都遇到了同样的问题.他们都说它适用于Firefox.
我想以编程方式启用/禁用数据连接.我使用了以下代码:
void enableInternet(boolean yes)
{
ConnectivityManager iMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
Method iMthd = null;
try {
iMthd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
} catch (Exception e) {
}
iMthd.setAccessible(false);
if(yes)
{
try {
iMthd.invoke(iMgr, true);
Toast.makeText(getApplicationContext(), "Data connection Enabled", Toast.LENGTH_SHORT).show();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
dataButton.setChecked(false);
Toast.makeText(getApplicationContext(), "IllegalArgumentException", Toast.LENGTH_SHORT).show();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), "IllegalAccessException", Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
dataButton.setChecked(false);
Toast.makeText(getApplicationContext(), "InvocationTargetException", Toast.LENGTH_SHORT).show();
} …Run Code Online (Sandbox Code Playgroud) 我对Haskell禁止作为"impredicative"的类型有相当不同的直觉:即forall出现在除了类型构造函数的参数中的类型->.但究竟什么是困境?是什么让它变得重要?它与"谓词"这个词有什么关系?
我正在开发一个需要静默打印的Web应用程序 - 没有用户参与.实现这一目标的最佳方法是什么?它不喜欢它可以严格使用Javascript,也不是Flash和/或AIR.我见过的最接近的是Java applet.
我可以理解为什么只有任何一个网站能够做到这一点是一个坏主意.此特定实例适用于内部应用程序,如果用户需要将URL添加到受信任站点列表,安装插件等,则完全可以接受.
我已经将一个Java动态Web项目导入Eclipse IDE(它在Eclipse IDE中实现并正常工作).
运行项目时,我收到" getDispatcherType()未定义类型HttpServletRequest"错误.
我已根据结构将每个文件复制到IDE中,并完成了工作.
现在我只想知道为什么在导入项目时出现此错误.有人遇到过同样的问题吗?请让我知道我可能犯了什么错误.
Cirdec对一个很大程度上不相关的问题的回答让我想知道如何最好地用恒定时间加法表示自然数,减去1,并测试零.
假设我们使用
data Nat = Z | S Nat
Run Code Online (Sandbox Code Playgroud)
然后我们可以写
Z + n = n
S m + n = S(m+n)
Run Code Online (Sandbox Code Playgroud)
我们可以m+n通过放置m-r借方(对于某些常数r)在O(1)时间内计算,每个S构造函数添加一个n.为了获得O(1)isZero,我们需要确保p每个S构造函数的最多借位,对于某些常量p.如果计算的话a + (b + (c+...)),这个效果很好,但是如果计算的话,它会分崩离析((...+b)+c)+d.问题是借方在前端叠加.
最简单的方法就是直接使用可伸缩列表,例如Okasaki描述的列表.有两个问题:
O(n)空间并不是很理想.
当我们不关心列表的排序时,并不完全清楚(至少对我而言)引导队列的复杂性是必要的.
似乎直到最近几年,将额外类型传递给函数的通常方法是执行类似的操作
f (undefined :: T)
Run Code Online (Sandbox Code Playgroud)
Kiselyov和Shan甚至在他们的经典论文中使用了这种方法,该论文基于类的反思,激发了这个reflection方案.他们通过注意到从未检查过伪造的价值来原谅明显的丑陋.并且出现了一个稍微不那么丑陋的化身Data.Bits.finiteBitSize,它取了一个它忽略的值来获得它的类型.
然后有人想出代理习语,一切都改变了.现在我们总能看到更令人满意的
f (Proxy :: Proxy T)
Run Code Online (Sandbox Code Playgroud)
(在标准代码-GHC类型的应用程序是另一个故事).
是谁想出来的?这是第一次出现在某个地方的代码还是纸上?
haskell ×5
types ×2
android ×1
download ×1
eclipse ×1
esqueleto ×1
ghc ×1
gprs ×1
ip-address ×1
java ×1
linux ×1
list ×1
math ×1
networking ×1
printing ×1
servlets ×1
sql ×1
ssh ×1
type-theory ×1
web-services ×1