這個程序是關於計算單詞,但它給頭中的錯誤,我無法修復它。它說沒有找到編譯器,並要求我使用-v
,但這也給出了一個錯誤。什麼是我需要用於向量的其他文件?導入未找到
這裏是我想要編譯代碼:
{-# LANGUAGE BangPatterns, MagicHash #-}
import qualified Data.Vector.Unboxed as VU
import Data.Vector.Unboxed ((!))
import qualified Data.Vector.Generic as VG --this one
import GHC.Base (Int(..), quotInt#, remInt#)
ones, tens, teens :: [String]
ones = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
tens = ["", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
teens = ["ten", "eleven", "twelve", "thirteen",
"fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
wordify :: Int -> String
wordify n
| n < 10 = ones !! n
| n < 20 = teens !! (n-10)
| n < 100 = splitterTen
| n < 1000 = splitter 100 "hundred"
| n < 1000000 = splitter 1000 "thousand"
| otherwise = splitter 1000000 "million"
where
splitterTen = let (t, x) = n `quotRem` 10
in (tens !! t) ++ wordify x
splitter d suffix = let (t, x) = n `quotRem` d
in (wordify t) ++ suffix ++ wordify x
wordLength :: Int -> Int
wordLength i = go 0 i
where
go !pad !n
| n < 10 = lenOnes `VG.unsafeIndex` n + pad
| n < 20 = lenTeens `VG.unsafeIndex` (n-10) + pad
| n < 100 = go (lenTens `VG.unsafeIndex` (n//10) + pad) (n%10)
| n < 1000 = go (go (7+pad) (n//100)) (n%100)
| n < 1000000 = go (go (8+pad) (n//1000)) (n%1000)
| otherwise = go (go (7+pad) (n//1000000)) (n%1000000)
(I# a) // (I# b) = I# (a `quotInt#` b)
(I# a) % (I# b) = I# (a `remInt#` b)
!lenOnes = VU.fromList [0,3,3,5,4,4,3,5,5,4] -- "", "one","two", ...
!lenTens = VU.fromList [0,3,6,6,5,5,5,7,6,6]
!lenTeens = VU.fromList [3,6,6,8,8,7,7,9,8,8] -- first element is "ten" 3
你應該向你的問題添加你得到的錯誤,你用來編譯和/或運行你使用的代碼和操作系統的命令行。 – nponeccop
你也應該添加你的編譯器的版本。 –
錯誤是無法找到模塊'Data.Vector.Generic' 使用-v查看搜索文件的列表。我的操作系統是Windows我的編譯器是ghci 2012.2.0.0 – user1664205