gpt4 book ai didi

haskell - 为什么 GHC 不导入 Semigroup ((<>))

转载 作者:行者123 更新时间:2023-12-02 21:05:23 26 4
gpt4 key购买 nike

我的讲师给我的代码不是在 GHCI 中构建的。据我所知,我的同学们的构建是正确的。

我引用的代码是

import Data.Semigroup  (Semigroup ((<>)))

GHCI 向我抛出此错误

Module ‘Data.Semigroup’ does not export ‘Semigroup((<>))’

这应该有效吗?我的 GHC 版本可能有问题吗?所有其他导入语句均有效。

最佳答案

最终编辑

Is there perhaps something wrong with my version of GHC?

绝对是的,有一些问题,准确地说是太旧了:

GHC-6.12 / base-4.2 (从 2010 年开始,即 Semigroup 包的时间)——非常感谢 @leftaroundabout 和 @Thomas M. DuBuisson 的贡献!

那个包没有 (Semigroup ((<>)))功能。因此您会看到错误。

Edit 2

评论后,我尝试重现OP环境来重现该错误,我在堆栈中安装了ghc版本7.10.3 ,这是 stack.yaml 文件的外观:

resolver: lts-6.27 
system-ghc: false
packages:
- .

在使用包含以下内容的 Main.hs 文件破坏基础堆栈项目之后:

module Main where

import Data.Semigroup

main :: IO ()
main = do
putStrLn "Hello"
putStrLn "World"

我得到的错误是

/home/damian/test-semigroup/app/Main.hs:3:8:

Could not find module ‘Data.Semigroup’

Use -v to see a list of the files searched for.    
-- While building package test-semigroup-0.1.0.0 using:
/home/damian/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_1.22.5.0_ghc-7.10.3 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.22.5.0 build lib:test-semigroup exe:test-semigroup-exe --ghc-options ""
Process exited with code: ExitFailure 1

旧版本也发生了同样的情况:

  • 适用于 ghc-7.10.2 的 LTS 3.22,

我无法尝试:

  • ghc-7.8.4 的 LTS 2.22,4 年前发布因为他们太老了,不能和 cabal 一起行动

和 - ghc-7.8.3 的 LTS 0.7,5 年前发布因为他们我无法将其安装在 64 位操作系统中...

所以,为了绝对确定,我一一尝试了所有较新的 LTS 版本,是的...一一,这花了一些时间,但值得一试:

  • 今天发布 ghc-8.6.5 的 LTS 13.29
  • ghc-8.6.4 的 LTS 13.19,3 个月前发布
  • ghc-8.6.3 的 LTS 13.11,4 个月前发布
  • ghc-8.4.4 的 LTS 12.26,7 个月前发布
  • ghc-8.4.3 的 LTS 12.14,9 个月前发布
  • ghc-8.2.2 的 LTS 11.22,11 个月前发布
  • ghc-8.0.2 的 LTS 9.21,一年前发布
  • ghc-8.0.1 的 LTS 7.24,2 年前发布

这些 ghc 版本都无法重现您的日志错误,所以我想尝试一下拼写错误:

import Data.Semigroup (Semigroup ((<$>)))

import Data.Semigroup (Semigroup ((=>>)))

这些给了我你的错误:

/home/damian/test-semigroup/app/Main.hs:3:24:错误:

Module ‘Data.Semigroup’ does not export ‘Semigroup(())’

  1. 这意味着 Data.Semigroup模块存在于您的ghc
  2. Semigroup((<>))不属于该模块

意思是,你必须拥有最古老的 ghc 之一版本...

所以,我认为你可以尝试:

  • 重新安装 ghc,并尝试再次运行。
  • 请考虑使用一些工具,例如 stack
  • 检查您的代码,注意是否有拼写错误或奇怪的内容

我认为我的第一个答案很接近:

Edit 1

已在ghc版本8.0.1中添加

在 hoogle 中快速搜索总是有帮助的:

Here第一个链接是半群 <>, (<>) :: Semigroup a => a -> a -> a

它说:

enter image description here

该版本自2016年5月起可用,其ghc版本为8.0.1 .

要查看 ghc 的所有版本及其基本版本:

https://wiki.haskell.org/Base_package

关于haskell - 为什么 GHC 不导入 Semigroup ((<>)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57118927/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com