所以我遇到了这个特殊的错误。在网上搜索但没有找到任何匹配的内容。奇怪的是我不明白它怎么可能不详尽。
以下是 Cause 中的函数:
myand :: [Bool] -> Bool
myand (x:xs) | null (x:xs) = True
| null xs = x
| otherwise = x && myand xs
Run Code Online (Sandbox Code Playgroud)
myor :: [Bool] -> Bool
myor (x:xs) | null(x:xs) = False
| null xs = x
| otherwise = x || myor xs
Run Code Online (Sandbox Code Playgroud)
safetail :: [a] -> [a]
safetail (x:xs) |null (x:xs) = []
|otherwise = xs
Run Code Online (Sandbox Code Playgroud)
这些都是非常简单的函数,在文件中定义,当我尝试使用空列表运行它们时,所有函数都会生成异常。
运行示例:
*Main> myor [True]
True
*Main> myor []
*** Exception: tp2.hs:(10,1)-(12,38): Non-exhaustive patterns in …Run Code Online (Sandbox Code Playgroud) 我的任务是实现这个镜像 Linux shell 的 myshell 程序。这是我大学操作系统入门课程的范围。他们向我们提供了基本的 shell 代码并要求我们篡改它。
练习之一是实现终止自定义 shell 的退出命令。我使用 strcmp 做到了这一点。然而我觉得这是一个非常hacky的解决方案——感觉就像作弊。
这是源代码:
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
int main(int argc, char* argv[]){
char buf[1024];
char* args[256];
pid_t pid;
for( ; ; ){
char* command;
fprintf(stdout, "$ ");
if((command = fgets(buf, sizeof(buf), stdin)) == NULL){
break;
}
command[strlen(buf) -1] = '\0';
//saving commands to a memory file so I can
//print them out later on with tail (through
//myhistory)
FILE* f = …Run Code Online (Sandbox Code Playgroud)