我在尝试做一个程序,即需要一封信,并把这封信成为 莫尔斯电码.
莫尔斯电表给定,以及 charToCode :: [(Char, String)] -> Char -> String
我还必须使用 的查找 和 fromJust 形式的数据。也许,使这项工作。 在汇编收到的以下错误:
Couldn't match expected type [Maybe Char]
with actual type Maybe String
* In the second argument of 'map', namely '(lookup a f)'
In the expression: map (fromJust) (lookup a f)
In an equation for 'charToCode':
charToCode f a = map (fromJust) (lookup a f)
我 们 使用的地图的前奏。 这里是我的代码迄今为止:
morseTab :: [(Char, String)]
morseTab = [('A', ".-"), ('B', "-..."), ('C', "-.-."), ('D', "-.."), ('E', "."), ('F', "..-."), ('G', "--."), ('H', "...."),('I', ".."), ('J', ".---"), ('K', "-.-"), ('L', ".-.."), ('M', "--"), ('N', "-."), ('O', "---"), ('P', ".--."), ('Q', "--.-"), ('R', ".-."), ('S', "..."), ('T', "-"), ('U', "..-"), ('V', "...-"), ('W', ".--"), ('X', "-..-"), ('Y', "-.--"), ('Z', "--..")]
charToCode :: [(Char, String)] -> Char -> String
charToCode f a = map (fromJust) (lookup a f)
morseTab是一个特定功能,我不能改变它。