ฉันกำลังพยายามทำให้โปรแกรมนั่นต้องใช้จดหมายและกลายเป็นว่าจดหมายเข้า รหัส.
ที่ Morse โต๊ะก็คือให้เช่นเดียว 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)
ฉัน ต้อง ใช้แผนที่จาก Prelude. นี่คือของฉันรหัสดังนั้นห่างไกล:
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 คือให้ฟังก์ชันฉันไม่สามารถทำให้เกิดการเปลี่ยนแปลงไปมันเหมือนกัน