小编mca*_*dre的帖子

Haskell错误:输入`='时解析错误

眼镜

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甚至更多.没有骰子.

(不受欢迎的)解决方案

我获得编译代码的唯一方法是

  1. 用空格替换硬标签.
  2. let子句替换该where子句.

syntax haskell indentation ghc ghci

7
推荐指数
2
解决办法
2万
查看次数

Haskell Stack溢出

我正在写一个遗传算法来生成字符串"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)

memory stack-overflow random haskell genetic-algorithm

7
推荐指数
1
解决办法
385
查看次数

如何在Free Pascal中使用匿名方法?

我尝试使用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的匿名方法,如果有的话?

delphi lambda closures freepascal anonymous-methods

7
推荐指数
1
解决办法
3476
查看次数

如何在Racket中获取程序名称?

我想以编程方式检测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中模仿这个?

racket

7
推荐指数
1
解决办法
194
查看次数

为什么我的线程Perl脚本会出现段错误?

我正在编写一个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)

linux perl multithreading segmentation-fault

6
推荐指数
1
解决办法
2134
查看次数

在GHC中指定arch?

我正在写一个多平台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?

x86 haskell x86-64 ncurses ghc

6
推荐指数
1
解决办法
882
查看次数

你如何在Mathematica中访问ARGV?

我想在Mathematica中编写命令行脚本,但我似乎找不到Argv[i_Integer]类似的功能.(否则,这些文件很神奇.)

wolfram-mathematica argv command-line-arguments

6
推荐指数
2
解决办法
1843
查看次数

什么是Scala的shebang系列,它不会破坏mimetype?

我一直在使用它,但它将mimetype更改为text/x-shellscript,这使得像Emacs这样的编辑器会像Shell脚本那样对待我的代码.

#!/bin/sh
exec scala "$0" "$@"
!#
Run Code Online (Sandbox Code Playgroud)

scala shebang

6
推荐指数
1
解决办法
1728
查看次数

怎么做go linters忽略供应商/?

我们如何制作go vet,gofmt和其他Go linter工具忽略第三方文件vendor/,最好具有准确的累积退出状态?

例如,是否会find . -name vendor -prune -o -name '*.go' -exec gofmt -s -w {} \;提供有意义的退出状态?

go

6
推荐指数
2
解决办法
4814
查看次数

如何禁用SMLNJ警告?

我正在尝试编写命令行脚本,但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)

command-line interface sml smlnj

5
推荐指数
1
解决办法
832
查看次数