我最近一直在玩RankNTypes并想知道是否可以在实例声明中使用它们.
这是一个使用open数据类型的简单示例
data (Expr a, Expr b) => Add a b = Add a b deriving(Show)
instance (Expr a, Expr b) => Expr (Add a b)
instance (Evaluation a, Evaluation b) => Evaluation (Add a b) where
eval (Add x y) = eval x + eval y
Run Code Online (Sandbox Code Playgroud)
在这里,我必须编写约束(评估a,评估b),但基本上我只想写一些像(forall a.评估a).这甚至可能吗?
问候,raichoo
public class Sample<T>{
T data;
Sample(){
data = ????;
}
}
Run Code Online (Sandbox Code Playgroud)
如何为数据分配默认值?
对于嵌入式应用程序,我试图使用ANSI C实现结构的先进先出(FIFO)队列.最直接的方法似乎是通过实现链表,以便每个结构包含指向队列中下一个的指针.因此我将结构本身定义为:
typedef enum { LED_on, LED_off, etc } Action;
typedef struct Queued_Action QueuedAction;
struct Queued_Action
{
Action action;
int value;
QueuedAction *nextAction;
};
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.如果我将指向队列中第一个和最后一个项目的指针定义为:
QueuedAction *firstAction;
QueuedAction *lastAction;
Run Code Online (Sandbox Code Playgroud)
...然后我希望能够通过声明(例如)向队列添加新动作:
if (!add_action_to_queue(LED_on, 100, &lastAction))
printf("Error!\n);
Run Code Online (Sandbox Code Playgroud)
...所以在返回时,lastAction将是指向队列中新创建的最后一个操作的指针.因此,将操作添加到队列的例程如下所示:
int add_action_to_queue(Action newAction, int newValue, QueuedAction **lastAction)
{
QueuedAction *newQueuedAction;
// Create a new action in memory
if ((newQueuedAction = (QueuedAction *)malloc(sizeof(QueuedAction))) == NULL)
return 0;
// Make the old 'lastAction' point to the new Action,
// and the new Action to point to …Run Code Online (Sandbox Code Playgroud) 如何在创建xml文件时在createElement中使用空格
我必须使用
$main = $doc->createElement("$cname"."Data" );
Run Code Online (Sandbox Code Playgroud)
哪里
$cname="Company Name"
Run Code Online (Sandbox Code Playgroud)
但由于空格$cname,我收到以下错误,
致命错误:file.php中带有消息'无效字符错误'的未捕获异常'DOMException':50堆栈跟踪:#0 file.php(50):DOMDocument-> createElement('geosoft company ...')#1 {main在第50行的file.php中抛出
如何纠正这个?
此致,Rekha
给出一组数字n[1], n[2], n[3], .... n[x]
和一个数字M.
我想找到最好的组合
n[a] + n[b] + n[c] + ... + n[?] >= M
Run Code Online (Sandbox Code Playgroud)
组合应该达到达到或超过M所需的最小值,没有其他组合可以获得更好的结果.
将在PHP中执行此操作,因此可以使用PHP库.如果没有,只需一般算法即可.谢谢!
是否存在为以用户身份运行的守护程序存储pid文件的首选位置?/ var/run是标准位置,但这适用于用户守护程序,因此它没有写入权限.据推测,我的守护进程将从.profile或.bashrc或其他东西开始.只是把它保存到/ tmp一个坏主意?
以char字节为单位的整数类型(或任何类型)的大小很容易计算为sizeof(type).一个常见的习惯用法是乘以CHAR_BIT找到该类型占用的位数,但是在使用填充位的实现中,这将不等于值位的宽度.更糟糕的是,代码如下:
x>>CHAR_BIT*sizeof(type)-1
Run Code Online (Sandbox Code Playgroud)
如果CHAR_BIT*sizeof(type)大于实际宽度,实际上可能有未定义的行为type.
为简单起见,我们假设我们的类型是无符号的.那么宽度type是ceil(log2((type)-1).有没有办法将此值计算为常量表达式?
10-18 10:26:39.382: ERROR/global(13919): Deprecated Thread methods are not supported.
10-18 10:26:39.382: ERROR/global(13919): java.lang.UnsupportedOperationException
10-18 10:26:39.382: ERROR/global(13919): at java.lang.VMThread.stop(VMThread.java:85)
10-18 10:26:39.382: ERROR/global(13919): at java.lang.Thread.stop(Thread.java:1379)
10-18 10:26:39.382: ERROR/global(13919): at java.lang.Thread.stop(Thread.java:1344)
10-18 10:26:39.382: ERROR/global(13919): at spexco.hus.camera.Camera.cancel(Camera.java:273)
10-18 10:26:39.382: ERROR/global(13919): at spexco.hus.cepvizyon.ViewCam.onStop(ViewCam.java:83)
10-18 10:26:39.382: ERROR/global(13919): at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1169)
10-18 10:26:39.382: ERROR/global(13919): at android.app.Activity.performStop(Activity.java:3797)
10-18 10:26:39.382: ERROR/global(13919): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3416)
10-18 10:26:39.382: ERROR/global(13919): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3487)
10-18 10:26:39.382: ERROR/global(13919): at android.app.ActivityThread.access$2800(ActivityThread.java:119)
10-18 10:26:39.382: ERROR/global(13919): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1896)
10-18 10:26:39.382: ERROR/global(13919): at android.os.Handler.dispatchMessage(Handler.java:99)
10-18 10:26:39.382: ERROR/global(13919): at android.os.Looper.loop(Looper.java:123)
10-18 10:26:39.382: …Run Code Online (Sandbox Code Playgroud) 我知道这个工具在URL上查找并将repsponse转换为pdf.我如何转换
<html> content.. </html>
Run Code Online (Sandbox Code Playgroud)
成为PDF格式?
我正在查看wkhtml2pdf上的帮助文件,看起来它提供了stdin的选项,但我无法弄清楚如何模拟stdin.
此外,如果你知道一个更好的工具,请建议我一些.
非常感谢!
以下是一些测试itertools.tee:
li = [x for x in range(10)]
ite = iter(li)
==================================================
it = itertools.tee(ite, 5)
>>> type(ite)
<type 'listiterator'>
>>> type(it)
<type 'tuple'>
>>> type(it[0])
<type 'itertools.tee'>
>>>
>>> list(ite)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(it[0]) # here I got nothing after 'list(ite)', why?
[]
>>> list(it[1])
[]
====================play again===================
>>> ite = iter(li)
it = itertools.tee(ite, 5)
>>> list(it[1])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> …Run Code Online (Sandbox Code Playgroud)