小编ano*_*on1的帖子

Haskell错误:"缺少附带绑定"和"不在范围内"

我创建了一段代码:

intToDigit :: Char -> Int
ord :: Char -> Int
intToDigit c = ord c - ord 'a'
Run Code Online (Sandbox Code Playgroud)

但是,当我运行它时,我收到此错误消息:

ChangeVowels.hs:2:1:`ord'的类型签名缺少附带的绑定

ChangeVowels.hs:4:16:不在范围内:`ord'

ChangeVowels.hs:4:24:不在范围内:`ord'

我尝试过,Import data.char但这也不起作用.

haskell compiler-errors

8
推荐指数
2
解决办法
3万
查看次数

帮助haskell旋转代码

好的,所以我知道这有点不对,但我错过了什么?代码是用以下单词旋转单个字母:

rotate 1   "hello" "ohell"  
rotate -1  "hello" "elloh"
Run Code Online (Sandbox Code Playgroud)

我的代码是:

module Main where

import System

main = do  
        (arg1:_) <- getArgs  
        xs <- getContents  
        putStr  (rotate xs arg1)  

rotate input w1 = unlines [ process line | line <- lines input ]  
        where process line = unwords [ word | word <- words line ]  
         map rotate n xs = drop n xs ++ take n xs  
Run Code Online (Sandbox Code Playgroud)

到目前为止,这是否正确,任何线索/提示下一步去哪里?

所以有点像这样:

shift :: a -> Int -> a
rotate :: a -> …
Run Code Online (Sandbox Code Playgroud)

haskell

2
推荐指数
1
解决办法
1466
查看次数

如何在haskell中旋转文本,以便只有单个单词旋转而不是整个文本?

此文本需要使用自然数向左旋转,并在输入负数时向右旋转.所以:

rotate 1    "foo bar baz" = "ofo rba zba"
rotate (-1) "foo bar baz" = "oof arb azb"
Run Code Online (Sandbox Code Playgroud)

另外我可以将文本分解成行然后单词,我知道所有的行,unlines,words,unwords.我在向左或向右移动文本的定义方面遇到问题,我是否需要使用head函数?

haskell rotation

0
推荐指数
1
解决办法
248
查看次数

标签 统计

haskell ×3

compiler-errors ×1

rotation ×1