2015-04-01 63 views
0

我写了这个代码,它是关于两个字符串是另一个每个字谜:错误 - 在输入语法错误(意外符号“大”)

anagram :: String->String->Bool    
anagram w1 w2 = anagram1 x1 x2 
where 
    y1 = break w1 
    y2 = break w2 
    x1 = quicksort y1 
    x2 = quicksort y2 


anagram1 :: [String]->[String]->Bool 
anagram1 (h1:t1)(h2:t2) 
    | h1!=h2 = False 
    | h1==h2 = anagram1 t1 t2 
    | otherwise = True 

我找到了快速排序有http://c2.com/cgi/wiki?QuickSortInHaskell

代码
quicksort :: [String]->[String] 
quicksort [] = [] 
quicksort (h:t) = quicksort small ++ (h : quicksort(large)) 
    where 
     small = [y | y <- t, y <= h] 
     large = [y | y <- t, y > h] 


break :: String->[String] 
break s = map (\c -> [c]) s 

当我运行它,我采取错误输入语法错误(意外符号“大”)

为什么我错了?

+0

[无法重现]( http://coliru.stacked-crooked.com/a/97a4e24a70de478d)。你可能打破了你的缩进。 – 2015-04-01 10:16:55

回答

5

如果我将它加载到ghci中,它会完美运行。

也许你的缩进在where子句中是不正确的。

anagram WHERE关键字必须缩进和Haskell中“不等于”是/=!=

请使用空格到处

它必须是YourModule.breakanagram所以它不会与Prelude.break冲突。

刚刚看过的错误信息,计算机正试图向你说话,所以听;)

测试大量的代码GHCI,你会得到更多的舒适与哈斯克尔