拼字游戏haskell代码出错 [英] Error in the scrabble haskell code
本文介绍了拼字游戏haskell代码出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个程序,用于将文件中的所有单词转换为数组并计算相应的分数,然后将它们压缩并制作字典并打印出来。
我想使用只有字典来提高性能,但它显示的错误为。
I was writing a program for converting all the words in the file into a array and calculate their corresponding scores and then zip both of them and make a dictionary and print it.
I want to use only dictionary to increase the performance but it is showing a error as .
[1 of 1] Compiling Main ( file.hs, file.o )
file.hs:21:1:
parse error (possibly incorrect indentation or mismatched brackets)
import Prelude hiding (lookup)
import Data.Map
import Data.Map (Map)
import qualified Data.Map as Map
getWordsFromFile :: String -> IO [String]
getWordsFromFile file = readFile file >>= return . words
main = do
wordList <- getWordsFromFile "wods.txt"
let words = wordList
let scores = score words
let list = zip words scores
let dic = fromList list
putStrLn $ show (dic)
score :: [String] -> [Int]
score (x : xs)
| map sum . map scrabble
mapper :: Eq k => [(k, v)] -> k -> v
mapper dict k = case lookup k dict of (Just v) -> v
scrabble :: Char -> Int
scrabble = mapper [ ('A', 1), ('B', 3),('C', 3), ('E', 1), ('D', 2), ('G', 2), ('F', 4), ('I', 1), ('H', 4), ('K', 5), ('J', 8), ('M', 3), ('L', 1), ('O', 1), ('N', 1), ('Q', 10), ('P', 3), ('S', 1), ('R', 1), ('U', 1), ('T', 1), ('W', 4), ('V', 4), ('Y', 4), ('X', 8), ('Z', 10)]
我需要做些什么修正?
What are the corrections i need to do ??
推荐答案
show(dic)
得分:: [String] - > [Int]
得分(x:xs)
|地图总和。 map scrabble
mapper :: Eq k => [(k,v)] - > k - > v
mapper dict k = case lookup k dict of(Just v) - > v
scrabble :: Char - > Int
scrabble = mapper [(' A', 1 ),(' B', 3 ),(' C', 3 ),(' E', 1 ),(' D', 2 ),(' G', 2 ),(' F', 4 ),(' 我', 1 ),(' H', 4 跨度>), (' K', 5 ), (' J', 8 ), (' M', 3 ), (' L', 1 ), (' O', 1 ), (' N', 1 ), (' Q', 10 ), (' P', 3 ), (' S', 1 ), ( ' R', 1 ),( ' U', 1 ),( ' T', 1 ),( ' W', 4 ),( ' V', 4 ),( ' Y', 4 ),( ' X', 8 ),( ' Z', 10 )]
show (dic) score :: [String] -> [Int] score (x : xs) | map sum . map scrabble mapper :: Eq k => [(k, v)] -> k -> v mapper dict k = case lookup k dict of (Just v) -> v scrabble :: Char -> Int scrabble = mapper [ ('A', 1), ('B', 3),('C', 3), ('E', 1), ('D', 2), ('G', 2), ('F', 4), ('I', 1), ('H', 4), ('K', 5), ('J', 8), ('M', 3), ('L', 1), ('O', 1), ('N', 1), ('Q', 10), ('P', 3), ('S', 1), ('R', 1), ('U', 1), ('T', 1), ('W', 4), ('V', 4), ('Y', 4), ('X', 8), ('Z', 10)]
我需要做些什么修正?
What are the corrections i need to do ??
这篇关于拼字游戏haskell代码出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文