【问题标题】:Leksah default hello world is not working after installation Xubuntu 13.10安装 Xubuntu 13.10 后 Leksah 默认的 hello world 无法正常工作
【发布时间】:2014-01-10 13:28:46
【问题描述】:

我已经从终端在 Xubuntu 13.10 上安装了 Leksah 0.12.1.3。

sudo apt-get install leksah

打开 leksah,创建新的工作区和包。 Main.hs 默认使用“Hello world”程序创建。

module Main (
    main
) where

import Control.Monad (unless)
import Data.List (stripPrefix)
import System.Exit (exitFailure)
import Test.QuickCheck.All (quickCheckAll)

-- Simple function to create a hello message.
hello s = "Hello " ++ s

-- Tell QuickCheck that if you strip "Hello " from the start of
-- hello s you will be left with s (for any s).
prop_hello s = stripPrefix "Hello " (hello s) == Just s

-- Hello World
exeMain = do
    putStrLn (hello "World")   

-- Entry point for unit tests.
testMain = do
    allPass <- $quickCheckAll -- Run QuickCheck on all prop_ functions
    unless allPass exitFailure

-- This is a clunky, but portable, way to use the same Main module file
-- for both an application and for unit tests.
-- MAIN_FUNCTION is preprocessor macro set to exeMain or testMain.
-- That way we can use the same file for both an application and for tests.
#ifndef MAIN_FUNCTION
#define MAIN_FUNCTION exeMain
#endif
main = MAIN_FUNCTION

现在,如果我尝试在右下窗口中运行包或在编辑器中编写任何内容
========== 127 ===========================
出现。

【问题讨论】:

  • 您是否启用了CPP 扩展?此外,在 .cabal 文件中设置测试比使用语言编译指示要容易得多。有很多更好的方法可以做到这一点。至少尝试直接定义main = exeMain。此外,如果它不能用 GHC 编译,它就不能用 leksah 编译。在假定它是编辑器问题之前,请确保它不是代码问题。

标签: haskell leksah


【解决方案1】:

这种情况经常发生在我身上......我不知道原因是什么,但是(至少在我的情况下)我知道我可以通过使用命令行来解决问题。我只是“cd”到带有包的目录(带有 *.cabal 文件的目录),然后键入

cabal configure
cabal build

完成此操作后,Leksah 可以正常工作。显然这是一个 Leksah 错误,但很容易解决。

【讨论】:

    【解决方案2】:

    问题在于我天真的假设“apt-get install leksah”将安装所有需要的软件包。 但是,这是不正确的。

    安装 leksah 后,您需要:

    apt-get install cabal-install
    apt-get install ghc
    cabal update
    

    之后,正如 jamshidh 所说,你需要点击 package->cofigure。

    现在构建刹车(对于发布的程序,这是 leksah 自动生成的默认值):

    Couldn't match type `IO' with `[]'
    Expected type: String
      Actual type: IO ()
    In the first argument of `putStrLn', namely `testMain'
    In the expression: putStrLn testMain
    In an equation for `main': main = putStrLn testMain
    

    但我设法构建了更简单的版本:

    module Main (
      main
    ) where
    main = putStrLn "Hello World"
    

    【讨论】:

      【解决方案3】:

      默认的hello world的问题是下面这行:

      putStrLn (hello "World")   
      

      只是左引号不在正确的位置。将其更改为

      putStrLn ("hello World")   
      

      它应该可以工作。

      【讨论】:

        猜你喜欢
        • 2020-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-15
        相关资源
        最近更新 更多