这个程序是关于计算单词的,但它在标题中给出了一个错误,我无法修复它。它说没有找到并要求我使用的编译器,-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