我的程序似乎无限运行,我不知道它在哪里无法继续

时间:2017-09-13 14:46:50

标签: haskell io ghci

我一直在使用I / O编写Haskell中的文件,但它只是在没有最终产品的情况下运行。

main :: IO ()
main = do
  hawkID <- getLine
  let text = "module Operations where\nimport " ++ hawkID ++ "\n\nsample :: (" ++ hawkID ++ "a)\nsample = B\n\
                                                                                        \size :: (" ++ hawkID ++ " a) -> Int\nsize x = 0\n\n\
                                                                                        \depth :: (" ++ hawkID ++ " a) -> Int\ndepth x = 0\n\n\
                                                                                        \dropN :: (" ++ hawkID ++ " a) -> (" ++hawkID ++ " a)\ndropN x = x\n\n\
                                                                                        \countB :: (" ++ hawkID ++ " a) -> Int\ncountB x = 0\n\
                                                                                        \ltoB :: (" ++ hawkID ++ " a) -> (" ++ hawkID ++ " b)\nltoB x = B\n\n\
                                                                                        \toString :: (" ++ hawkID ++ " a) -> String\ntoString x = \"\"\n\n\
                                                                                        \mapHawkid :: (a -> b) -> (" ++ hawkID++ " a) -> (" ++ hawkID ++ " b)\n\n\
                                                                                        \substB :: (" ++ hawkID ++ " a) -> (" ++ hawkID ++" a) -> (" ++ hawkID ++ " a)\n\
                                                                                        \substB x y = B"
  let file =  writeFile "Desktop/hawkID.hs"  text

  return ()

1 个答案:

答案 0 :(得分:1)

您是否正在输入文字并按Enter键以满足library(doParallel) if(!exists("Registered")){ registerDoParallel(cores = detectCores(logical = TRUE)) Registered = TRUE } AddOne<-function(x){AddOneSubroutine(x)} AddOneSubroutine <-function(x){x+1} MyList<-list() MyList$f<-AddOne # Not using parallel environments, works correctly when calling AddOne 3 times Result1 = foreach(i = 1:3) %do% AddOne(i) Result1 # Not using parallel environments, works correctly when calling MyList$f 3 times Result2 = foreach(i = 1:3) %do% MyList$f(i) Result2 # Using parallel environments, works correctly when calling AddOne 3 times, # despite not explicitly using the .export argument to export AddOneSubroutine Result3 = foreach(i = 1:3) %dopar% AddOne(i) Result3 # Using parallel environments, fails when calling MyList$f with error # "could not find function "AddOneSubroutine"", even though that function is "exported" Result4 = foreach(i = 1:3,.export = "AddOneSubroutine") %dopar% MyList$f(i) Result4 来电?没有提示。如果你想要一个提示,我认为你需要一个(例如)getLine并可能禁用输出缓冲。

此外,您的putStr来电不会被评估 - 您需要将其放在writeFile块的正文中,如:

do