嗨,我的Xmonad一直工作到几天前,然后我想我用Synaptic安装了一些东西然后开始抱怨Xmonad.Config.Gnome这里是我的xmonad.hs
import XMonad
import XMonad.Config.Gnome
myManageHook = composeAll [
(className =? "Pidgin" <&&> title =? "Buddy List") --> doFloat
, (className =? "Gnome-panel" <&&> title =? "Run Application") --> doFloat
-- , (className =? "XEyes") --> doShift "7"
]
main = xmonad $ gnomeConfig {
modMask = mod4Mask
, manageHook = myManageHook <+> manageHook gnomeConfig
}
Run Code Online (Sandbox Code Playgroud)
当我编译时,我得到这个:
ghc --make "xmonad.hs" (nella cartella: /home/giuseppe/.xmonad)
xmonad.hs:2:7:
Could not find module `XMonad.Config.Gnome':
Use -v to see a list of the files searched for. …Run Code Online (Sandbox Code Playgroud) 我写了以下文件temp.hs:
import qualified Data.Set
import System.Environment
main :: IO ()
main = do
args <- getArgs
let fname = head args
print (fname)
Run Code Online (Sandbox Code Playgroud)
它加载ghci没有错误:
$ ghci
GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> :load temp.hs
[1 of 1] Compiling Main ( temp.hs, interpreted )
Ok, modules loaded: Main.
*Main>
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,我收到以下错误:
$ …Run Code Online (Sandbox Code Playgroud) 我有两个版本的相同程序,两者之间的变化很小.我没有使用单独的文件,而是使用#if defined (PAR)- #else- #endif然后在有或没有-cpp -DPAR在两个版本之间切换的情况下进行编译.我喜欢这种方式,因为你只需要处理一个单独的hs文件.但是,由于我的目标是编写原始程序的并行/优化版本,我想知道使用#if-#else#-endif是否有任何性能影响?基本上我想解释一下这是如何工作的.谢谢
#if defined(PAR)
import Control.Parallel
import Control.Parallel.Strategies
import Control.DeepSeq
#endif
#if defined(PAR)
test = sum ( map expensiveFunc myList `using` strat )
where strat = parListChunk 100 rseq
#else
test = sum ( map expensiveFunc myList )
#endif
Run Code Online (Sandbox Code Playgroud)
注意:
-cpp您可以使用源文件中的语言选项而不是标志:
例如 {-# LANGUAGE CPP #-}
但是-Dxxx在编译时仍需要提供(或不提供),以便选择编译器应该忽略的程序部分(其中xxx是hs文件中定义的变量).
我想实现一个带有arr-member-function 的箭头,显示不同类型的函数参数的不同行为,例如arr (\x -> (x,x))应该表现得与arr id... 不同
这是代码:
{-# LANGUAGE Arrows, OverlappingInstances, IncoherentInstances, FlexibleInstances#-}
import Control.Arrow
import Control.Category
import Prelude hiding (id, (.))
class ToPredefinedStr a where
toStr :: a -> String
instance ToPredefinedStr ((->) b (b,b)) where
toStr _ = "b -> (b,b)"
instance ToPredefinedStr (a -> (b,c)) where
toStr _ = "a -> (b,c)"
instance ToPredefinedStr ((a,b) -> c) where
toStr _ = "(a,b) -> c"
instance ToPredefinedStr (a -> b) where …Run Code Online (Sandbox Code Playgroud) 为什么不能在提示(Language.Haskell.Interpreter)中将顶级模块设置为"Main"?
请允许我证明:
module Main where
import Language.Haskell.Interpreter
import Control.Monad
main = do
res <- runInterpreter (test "test")
case res of
Left e -> putStrLn (show e)
Right t -> putStrLn (show t)
return ()
test :: String -> Interpreter ()
test mname =
do
loadModules [mname ++ ".hs"]
setTopLevelModules ["Main"]
Run Code Online (Sandbox Code Playgroud)
将导致:
NotAllowed "These modules are not interpreted:\nMain\n"
Run Code Online (Sandbox Code Playgroud) 我正在尝试将作为参数(使用getArgs)给出的字符串连接到haskell程序,例如:
"rm " ++ filename ++ " filename2.txt"它在main = do块内.
问题是文件名的类型,ghc不会编译它,给出错误.
我收到一个错误 Couldn't match expected type [a] against inferred type IO ExitCode
我们试图运行的代码是:
args <- getArgs
let inputfname = head args
system "rm -f "++ inputfname ++ " functions.txt"
Run Code Online (Sandbox Code Playgroud) 作为练习,我试图手动实现前奏的有趣部分.每当我发现有机会自由点我就接受它.然而,这让我在最不可能的地方找到了一堵砖墙.使用此代码:
myelem _ [] = False
myelem x y = if x == head y then True else myelem x (tail y)
Run Code Online (Sandbox Code Playgroud)
我正在努力实施notElem.以下是我的尝试:
-- First
mynotelem = not myelem
Run Code Online (Sandbox Code Playgroud)
由于不匹配的类型,可以理解地爆炸.这很容易解决:
-- Second
mynotelem x y = not (myelem x y)
Run Code Online (Sandbox Code Playgroud)
然而,参数x和y的显式声明感觉很丑陋和不必要,所以我试着让它恢复到点自由风格.
-- Third
mynotelem = not $ myelem
Run Code Online (Sandbox Code Playgroud)
哪个失败了
Couldn't match expected type `Bool'
with actual type `a0 -> [a0] -> Bool'
In the second argument of `($)', namely `myelem'
In the expression: not $ myelem
In an …Run Code Online (Sandbox Code Playgroud) 我想用C++调用haskell函数,并使用http://www.haskell.org/ghc/docs/7.0.2/html/users_guide/ffi-ghc.html上的教程.
所以我有一个haskell文件Foo.hs:
module Foo where
foreign export ccall foo :: Int -> IO Int
foo :: Int -> IO Int
foo n = return (length (f n))
f :: Int -> [Int]
f 0 = []
f n = n:(f (n-1))
Run Code Online (Sandbox Code Playgroud)
并呼吁
ghc Foo.hs
Run Code Online (Sandbox Code Playgroud)
它创建了一个Foo_stub.h:
#include "HsFFI.h"
#ifdef __cplusplus
extern "C" {
#endif
extern HsInt foo(HsInt a1);
#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)
一个Foo_stub.c:
#define IN_STG_CODE 0
#include "Rts.h"
#include "Stg.h"
#ifdef __cplusplus
extern "C" {
#endif
extern StgClosure …Run Code Online (Sandbox Code Playgroud) 一个代码工作来自runghc,但我无法使用ghc命令编译相同的代码.为什么?
以下是我的最小代码和环境:https: //gist.github.com/1588756
效果很好:
$ runghc cat.hs
Run Code Online (Sandbox Code Playgroud)
无法编译:
$ ghc cat.hs -o cat
Run Code Online (Sandbox Code Playgroud)
Macbook air,max os x雪豹
我正在尝试编译一个包含大量错误的haskell文件.我想开始调试第一个,但不幸的是有很多它们离开了屏幕.
我想将错误消息传递给一个文件,以便我可以从顶部读取,但正常的方法似乎不起作用.
我试过了:
ghc File.hs > errors.log
ghc File.hs >> errors.log
ghc File.hs | more
Run Code Online (Sandbox Code Playgroud)
他们都没有工作.使用>并>>仅将前几行写入文件,然后将其余行写入标准输出.使用more,less,cat等不作任何差别.
是否有GHC标志可以让我输出到文件?
(我应该让你知道我正在使用Cygwin在Windows机器上工作.)