所以我正在学习Haskell并想写一个简单的代码,它只是在字符串中重复两个字母.所以我想出了这个:
repl :: String->String
repl " " = " "
repl (x:xs) = x:x:repl xs
Run Code Online (Sandbox Code Playgroud)
现在编译时我没有收到任何警告,但是当我这样做时发生了运行时错误repl "abcd":
"abcd*** Exception: repl.hs:(2,1)-(3,23): Non-exhaustive patterns in function repl
Run Code Online (Sandbox Code Playgroud)
那么为什么编译器从来没有报告过这个问题,为什么在有很多像OCaml这样的语言在编译时清楚地报告这个问题时Haskell会忽略它呢?
我正在尝试安装自定义内核,一切正常,除了当我运行 make 时会产生modules_install以下结果:
ln: target \xe2\x80\x98/lib/modules/4.2.0-rc4/source\xe2\x80\x99 is not a directory\nMakefile:1120: recipe for target '_modinst_' failed\nmake: *** [_modinst_] Error 1\nRun Code Online (Sandbox Code Playgroud)\n\n我在 Makefile 中查找了第 1120 行,其中包含以下内容:
\n\n_modinst_:\n @rm -rf $(MODLIB)/kernel\n @rm -f $(MODLIB)/source\n @mkdir -p $(MODLIB)/kernel\nRun Code Online (Sandbox Code Playgroud)\n\n我用谷歌搜索了很多,我发现它的发生(主要是我发现的)是由于EXTRAVERSIONMakefile 中的变量中有额外的空间,但我的 Makefile 中没有空间。
有人能指出我正确的方向吗?
\n\n编辑 :
\n\n我遵循下面评论中的建议并执行了 \n ls -al /lib/modules/4.2.0-rc4/。\n没有源文件或源目录存在并且运行modules_install时会产生make --trace以下结果:
Makefile:1120: target '_modinst_' does not exist\nrm -rf /lib/modules/4.2.0-rc4/kernel\nrm -f /lib/modules/4.2.0-rc4/source\nmkdir -p /lib/modules/4.2.0-rc4/kernel\nln -s `cd . && …Run Code Online (Sandbox Code Playgroud) 我需要为我的一个分配编写一个简单的函数,它应该删除给定列表中的所有重复项,除了列表中第一个出现的元素.这是我写的:
remDup :: [Int]->[Int]
remDup []=[]
remDup (x:xs)
| present x xs==True = remDup xs
| otherwise = x:remDup xs
where
present :: Int->[Int]->Bool
present x [] = False
present x (y:ys)
| x==y =True
| otherwise = present x ys
Run Code Online (Sandbox Code Playgroud)
但是这个代码删除了重复项,除了元素的最后一次出现.也就是说,如果给定的列表是[1,2,3,3,2]生成[1,3,2]而不是[1,2,3].怎么做反过来呢?
出租车编号被定义为正整数,其可以以至少两种不同方式表示为两个立方体的总和.
1729=1^3+12^3=9^3+10^3
我写了这个代码来生成一个出租车编号,在运行时会给出第n个最小的出租车编号:
taxicab :: Int -> Int
taxicab n = [(cube a + cube b)
| a <- [1..100],
b <- [(a+1)..100],
c <- [(a+1)..100],
d <- [(c+1)..100],
(cube a + cube b) == (cube c + cube d)]!!(n-1)
cube x = x * x * x
Run Code Online (Sandbox Code Playgroud)
但是我得到的输出并不是我所期望的.对于数字一至三,代码产生正确的输出但taxicab 4产生39312而不是.20683另一个奇怪的事情39312是原来是第六小的出租车数字 - 而不是第四!
那为什么会这样呢?我的代码中的缺陷在哪里?
所以我正在学习编写设备驱动程序并编写了这个简单的驱动程序:
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
static int __init gotemp_init(void)
{
printk(KERN_DEBUG "Hello world");
return 0;
}
static void __exit gotemp_exit(void)
{
}
module_init(gotemp_init);
module_exit(gotemp_exit);
MODULE_AUTHOR("Abhinav Jain");
MODULE_DESCRIPTION("Simple driver");
MODULE_LICENSE("GPL");
Run Code Online (Sandbox Code Playgroud)
生成文件是这样的:
obj-m := hello.o
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD)
Run Code Online (Sandbox Code Playgroud)
但是 的输出dmesg不打印"Hello world". 我也尝试过,KERN_INFO但结果仍然相同,尽管lsmod显示hello正在加载模块。
那么为什么没有记录消息呢?
所以我正在研究共享库,我读到dlclose()在进程终止时执行隐式。我想知道谁负责这个电话。例如,如果我写:
#include <stdio.h>
int main() {
printf("Hello World\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后如果我这样做了,ldd ./a.out我会得到这些库的列表:
linux-vdso.so.1 => (0x00007ffd6675c000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2569866000)
/lib64/ld-linux-x86-64.so.2 (0x0000562b69162000)
Run Code Online (Sandbox Code Playgroud)
链接器负责加载这些权限,那么./a.out对于dlclose()这些库的隐式,在终止此可执行文件时谁负责?