你好为什么我使用递归的反向方法不起作用?print语句显示操作正确完成,但最后看起来只有整个String的非常多的char被赋值给h.
public static String reverse(String s,String h){
if(s.length()==0){
return s;
} else {
h+=s.charAt(s.length()-1);
System.out.println(h);//FOR TEST
s=s.substring(0,s.length()-1);
reverse(s,h);
return h;
}
}
Run Code Online (Sandbox Code Playgroud)
有什么建议?
假设我们想要编写一个由IO操作支持的通用属性映射,但由于某种原因,我们需要使值类型具有多态性.
type Key = Int
get:: Key -> v -> IO v -- Takes a key and a default value, return the associated value
put:: Key -> v -> IO () -- store (Key,v) pair doing some IO
Run Code Online (Sandbox Code Playgroud)
在这种情况下,自由定理是否需要get并且put只做微不足道的事情,如果是这样,我们可以欺骗ghc的类型系统来实现真正的类型索引IO数据库吗?
这是一个树的代码.
import Control.Exception
import Control.Monad
import Control.DeepSeq
import qualified Data.List as List
import Test.HUnit
data Tree a = Empty
| Node a (Tree a) (Tree a)
deriving (Show, Eq)
insertTree :: ( Ord a, Show a ) => Tree a -> a -> Tree a
insertTree Empty x = Node x Empty Empty
insertTree ( Node v tLeft tRight ) x
| x == v = Node v tLeft tRight
| x < v = Node v (insertTree tLeft x) …Run Code Online (Sandbox Code Playgroud) 如果有数据类型
data Arith = Con Int
| Add Arith Arith
| Sub Arith Arith
| Mul Arith Arith
| Div Arith Arith
Run Code Online (Sandbox Code Playgroud)
一个实例:
instance Show Arith where
show (Con i) = show i
show (Add e1 e2) = "(" ++ show e1 ++ " + " ++ show e2 ++ ")"
show (Sub e1 e2) = "(" ++ show e1 ++ " - " ++ show e2 ++ ")"
show (Mul e1 e2) = "(" ++ show e1 ++ " …Run Code Online (Sandbox Code Playgroud) 只想澄清这是我编程的第一天,我意识到这个问题是多么愚蠢:D
1)为什么不起作用?
ghci>''hello'' ++ ''world''
<interactive>:40:1: error
* Syntax error on ''hello''
Perhaps you intended to use TemplateHaskell or TemplateHaskellQuotes
* In the Template Haskell quotation ''hello''
ghci>''hello'' ++ '' '' ++ ''world''
<interactive>:41:17: error: parse error on input '''
Run Code Online (Sandbox Code Playgroud)
我应该在texteditor中添加一些内容以使其正常工作吗?或者我只是做了一些菜鸟错误?
2)
ghci> ''Steve'' !! 2
<interactive>:42:2: error
* Syntax error on ''Steve''
Perhaps you intended to use TemplateHaskell or TemplateHaskellQuotes
* In the Template Haskell quotation ''Steve''
ghci>[1,2,3,5,8] !! 2
3
Run Code Online (Sandbox Code Playgroud)
当我使用数字执行这些命令时,它可以工作,但不能使用字符.我一定做错了什么,但我不确定是什么:/
提前致谢!
我只是有一个关于应用函子的快速问题,以帮助我掌握它们.这只是我在ghci中应用的东西.
[(+3),((-) 3),(*3)] <*> [4]
[7,-1,12]
Run Code Online (Sandbox Code Playgroud)
这对我来说很有意义.基本申请.但在尝试时:
[(Just (+3)),(Just ((-) 3)),(Just (*3))] <*> [Just 4]
Run Code Online (Sandbox Code Playgroud)
我收到了很多错误.我有点理解为什么; 有两个数据构造函数([]和Maybe),并且该<*>函数仅"剥离"其中一个.我想要帮助我理解的是,haskell正在尝试逐步进行直到失败,以及如何绕过它并将其成功计算到:
[(Just 7),(Just -1),(Just 12)]
Run Code Online (Sandbox Code Playgroud) 我正在XNA中制作游戏,我注意到当我发布游戏时运行速度比在发布模式下运行时要快.我在构建选项中启用了优化,禁用了跟踪和调试.还有什么可以在这里发生.这导致调整困难.谁看过这个吗?会发生什么事?
我有一些数据存储在矢量中;
vector<string> data ;
Run Code Online (Sandbox Code Playgroud)
我想按字母顺序对数据中的字符串进行排序.是否有任何排序算法或复杂的库可以推荐给我?
Ex;
assume in data ;
aaaa
ccc
bbb
acb
after sorting, data ;
aaaa
acb
bbb
ccc
Run Code Online (Sandbox Code Playgroud) 嘿 - 伟大的程序员和haskellers,我是一名哈斯克尔大学新生并且有一个程序问题归结为以下情况
main :: IO ()
main = do
putStrLn "\nplease give me some input"
input1 <- getLine
putStrLn "\nplease give me another input"
input2 <-getLine
putStrLn ("\nyour inputs were "++show(input1)++" and "++ show(input2)")
putStrLn "restart ?? yY or nN"
c <- getChar
restart c
where
restart c
|elem c "yY" = do
main
|elem c "nN" = putStrLn "\nExample Over"
|otherwise = do
putStrLn "\nyou must type one of Yy to confirm or nN to abort"
c'<- getChar …Run Code Online (Sandbox Code Playgroud)