眼镜
GHC 6.12.1
Mac OS X 10.6.4 x64
MacBook Pro
问题
我在使用let语法时遇到了麻烦.以下代码拒绝编译:
module Main where
main = let x = 1
y = 2
z = 3
in putStrLn $ "X = " ++ show x ++ "\nY = " ++ show y ++ "\nZ = " ++ show z
Run Code Online (Sandbox Code Playgroud)
我尝试了进入y = 2,z = 3甚至更多.没有骰子.
(不受欢迎的)解决方案
我获得编译代码的唯一方法是
let子句替换该where子句.我正在写一个遗传算法来生成字符串"helloworld".但是当n为10,000或更多时,evolve函数会创建堆栈溢出.
module Genetics where
import Data.List (sortBy)
import Random (randomRIO)
import Control.Monad (foldM)
class Gene g where
-- How ideal is the gene from 0.0 to 1.0?
fitness :: g -> Float
-- How does a gene mutate?
mutate :: g -> IO g
-- How many species will be explored?
species :: [g] -> Int
orderFitness :: (Gene g) => [g] -> [g]
orderFitness = reverse . sortBy (\a b -> compare (fitness a) (fitness b))
compete :: (Gene …Run Code Online (Sandbox Code Playgroud) 我尝试使用Delphi的匿名方法语法:
type
fun = reference to function(): Integer;
Run Code Online (Sandbox Code Playgroud)
Fpc显示语法错误:
Error: Identifier not found "reference"
Run Code Online (Sandbox Code Playgroud)
什么是免费Pascal相当于Delphi的匿名方法,如果有的话?
我想以编程方式检测Racket代码中的程序名称.这可以在鸡计划中完成:
#!/bin/sh
#|
exec csi -ss $0 ${1+"$@"}
exit
|#
(define (main)
(display (format "Program: ~a\n" (program-name)))
(exit))
(if (not (equal? (program-name) "csi"))
(main))
Run Code Online (Sandbox Code Playgroud)
我怎么能在Racket中模仿这个?
我正在编写一个curses脚本,它需要在处理SIGINT后进行清理,以便将终端恢复到原始状态.
启用信号处理程序时,我得到一个段错误.
为了支持,我删除了所有的curses代码以解决问题.
码:
#!/usr/bin/env perl
use strict;
use warnings;
use threads;
sub cleanup { exit 0; }
sub run { while (1) {} }
# comment this line and the problem disappears
$SIG{INT} = \&cleanup;
foreach my $i (1..100) {
print "Creating this thread\n";
my $t = threads->create(\&run);
print "Created that thread\n";
}
while (1) { print "Looping\n"; }
Run Code Online (Sandbox Code Playgroud)
示例错误跟踪(90%的时间段为segfaults):
$ ./threadtest.perl
...
Creating this thread
Creating that thread
Detaching this thread
Detaching that thread
Creating this thread
^CSegmentation …Run Code Online (Sandbox Code Playgroud) 我正在写一个多平台ncurses文本冒险游戏.所需的C库ncursesw是为x86配置的,但我的操作系统是Mac OS X 10.6.6 x86_64.
ghc --make -o rogue rogue.hs
[1 of 2] Compiling Dungeon ( Dungeon.hs, Dungeon.o )
[2 of 2] Compiling Main ( rogue.hs, rogue.o )
Linking rogue ...
ld: warning: in /usr/local/lib/libncursesw.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
Run Code Online (Sandbox Code Playgroud)
我认为强制编译x86比说服Homebrew,MinGW和Aptitude存储库包含x86_64 ncursesw库要容易得多.
是否有命令行选项我可以传递给ghc来指定架构,类似于-marchGCC?
我想在Mathematica中编写命令行脚本,但我似乎找不到Argv[i_Integer]类似的功能.(否则,这些文件很神奇.)
我一直在使用它,但它将mimetype更改为text/x-shellscript,这使得像Emacs这样的编辑器会像Shell脚本那样对待我的代码.
#!/bin/sh
exec scala "$0" "$@"
!#
Run Code Online (Sandbox Code Playgroud) 我们如何制作go vet,gofmt和其他Go linter工具忽略第三方文件vendor/,最好具有准确的累积退出状态?
例如,是否会find . -name vendor -prune -o -name '*.go' -exec gofmt -s -w {} \;提供有意义的退出状态?
我正在尝试编写命令行脚本,但SML的警告会混淆接口.
文档说使用:
Compiler.Control.printWarnings := false;
Run Code Online (Sandbox Code Playgroud)
但是SMLNJ已将这些重命名为:
Control.printWarnings := false;
Run Code Online (Sandbox Code Playgroud)
这实际上产生了更多的打印输出.
例:
$ cat hello.sml
print "Hello World!\n";
OS.Process.exit(OS.Process.success);
$ sml hello.sml
Standard ML of New Jersey v110.72 [built: Mon Nov 14 17:30:10 2011]
[opening hello.sml]
Hello World!
val it = () : unit
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[autoloading done]
hello.sml:2.1-2.36 Warning: type vars not generalized because of
value restriction are instantiated to dummy types (X1,X2,...)
Run Code Online (Sandbox Code Playgroud)
与:
$ cat hello.sml
Control.printWarnings := false;
print "Hello World!\n";
OS.Process.exit(OS.Process.success);
$ sml hello.sml …Run Code Online (Sandbox Code Playgroud)