haskell - Haskell Stack 显示错误“找不到包 unix 的包 ID”。如何修复此错误?
问题描述
我正在尝试运行使用unix
包 using的 Haskell 脚本,stack
但它显示错误Could not find package id of package unix
。
命令提示符:
PS D:\Programming\Haskell> stack helpful_math.hs
Could not find package id of package unix
PS D:\Programming\Haskell> stack --version
Version 2.3.3, Git revision cb44d51bed48b723a5deb08c3348c0b3ccfc437e x86_64 hpack-0.33.0
PS D:\Programming\Haskell> stack ghc -- --version
The Glorious Glasgow Haskell Compilation System, version 8.10.4
Haskell 脚本help_math.hs是:
#!stack
{- stack runghc
--package split --package extra --package unix
-}
import Data.Char (toLower)
import Data.List (sort, intercalate)
import Data.List.Split (splitOn)
import Data.List.Extra (trim)
import Control.Monad (forever)
import Control.Monad.Extra (whileM)
import Control.Concurrent (myThreadId, throwTo)
import Control.Exception (UserInterrupt)
import System.IO (hFlush, stdout)
import System.Posix.Signals (Catch, installHandler, keyboardSignal)
promptString = "\n> "
prompt :: String -> IO String
prompt msg = do
putStr (msg ++ promptString)
hFlush stdout
trim <$> getLine
exitOnCtrlC :: IO String
exitOnCtrlC = do
tid <- myThreadId
installHandler keyboardSignal (Catch (throwTo tid UserInterrupt)) Nothing
solve :: String -> String
solve = intercalate " + " . map show . sort . map readNum . splitOn "+"
where readNum :: String -> Int
readNum = read . trim
main = do
putStrLn "Welcome to Helpful Math Program!"
--putStrLn "Press Ctrl-C to exit at any point"
whileM $ do
input <- prompt "Enter sum expression"
putStr "Answer is: "
putStrLn . solve $ input
line <- map toLower <$> prompt "Do you want to quit? (y | n)"
return $ line != "y"
解决方案
我自己找到了答案。这是一个愚蠢的错误——我忘记了 Windows 不支持 unix。所以代码无论如何都不会在 Windows 上运行。
推荐阅读
- amazon-web-services - AWS API Gateway 访问私有子网
- java - EMR 上的 Flink Job 使用类型安全配置作为依赖项给出 NoSuchMethodError: Config.getEnum
- soap - 如何在 ASMX Web 服务响应中添加自定义肥皂头
- go - 设置拨号器的拨号功能
- php - 从 Cakephp 中的非关联控制器访问变量
- html - 如何使用 CSS flexbox 创建此布局?
- javascript - 开玩笑:尝试导入本机模块时出错;无法用 Mock 预防
- sas - SAS:如何重复计算和更改值?
- javascript - 在函数内部使用“this”从视图模型列表中获取视图模型属性
- c - 寻找元素平均值的问题