Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
haskell我的最后一行“;putStr";抛出错误_Haskell - Fatal编程技术网

haskell我的最后一行“;putStr";抛出错误

haskell我的最后一行“;putStr";抛出错误,haskell,Haskell,我的最后一行使编译器抛出错误。有什么问题吗?2个问题: 缩进对您的if语句不利 您没有将2个操作链接起来(参见下面的示例) 您的代码已修复: import Data.List import Data.Char isIn :: (Eq a) => [a] -> [a] -> Bool needle `isIn` haystack = any (needle `isPrefixOf` ) (tails haystack) encode :: Int -> Strin

我的最后一行使编译器抛出错误。有什么问题吗?

2个问题:

  • 缩进对您的if语句不利
  • 您没有将2个操作链接起来(参见下面的示例)
您的代码已修复:

import Data.List
import Data.Char

isIn :: (Eq a) => [a] -> [a] -> Bool
needle `isIn` haystack = any (needle `isPrefixOf` ) (tails haystack)


encode :: Int -> String -> String
encode offset msg = map (\c -> chr $ ord c + offset) msg

main :: IO()
main =
     if "arts" `isIn` "artsisgood" then 
        putStrLn "is in"
     else
        putStrLn "not in"

     putStr (encode 3 "hey")
2个问题:

  • 缩进对您的if语句不利
  • 您没有将2个操作链接起来(参见下面的示例)
您的代码已修复:

import Data.List
import Data.Char

isIn :: (Eq a) => [a] -> [a] -> Bool
needle `isIn` haystack = any (needle `isPrefixOf` ) (tails haystack)


encode :: Int -> String -> String
encode offset msg = map (\c -> chr $ ord c + offset) msg

main :: IO()
main =
     if "arts" `isIn` "artsisgood" then 
        putStrLn "is in"
     else
        putStrLn "not in"

     putStr (encode 3 "hey")

从缩进的角度看,似乎您正在尝试使用
do
符号进行编写。只需添加关键字
do
即可修复代码:

import Data.List
import Data.Char

isIn :: (Eq a) => [a] -> [a] -> Bool
needle `isIn` haystack = any (needle `isPrefixOf` ) (tails haystack)


encode :: Int -> String -> String
encode offset = map (\c -> chr $ ord c + offset)
-- encode offset msg = map (\c -> chr $ ord c + offset) msg

main :: IO()
main = do
     if "arts" `isIn` "artsisgood" 
       then putStrLn "is in"
       else putStrLn "not in"
     putStr (encode 3 "hey")

main2 =
   if "arts" `isIn` "artsisgood" 
   then putStrLn "is in"
   else putStrLn "not in"
   >> putStr (encode 3 "hey")

从缩进的角度看,似乎您正在尝试使用
do
符号进行编写。只需添加关键字
do
即可修复代码:

import Data.List
import Data.Char

isIn :: (Eq a) => [a] -> [a] -> Bool
needle `isIn` haystack = any (needle `isPrefixOf` ) (tails haystack)


encode :: Int -> String -> String
encode offset = map (\c -> chr $ ord c + offset)
-- encode offset msg = map (\c -> chr $ ord c + offset) msg

main :: IO()
main = do
     if "arts" `isIn` "artsisgood" 
       then putStrLn "is in"
       else putStrLn "not in"
     putStr (encode 3 "hey")

main2 =
   if "arts" `isIn` "artsisgood" 
   then putStrLn "is in"
   else putStrLn "not in"
   >> putStr (encode 3 "hey")

如果你遇到错误/你可能害怕/但不要匆忙/请复制并粘贴(你的错误)。如果你遇到错误/你可能害怕/但不要匆忙/请复制并粘贴(你的错误)。