小编Noa*_*els的帖子

如何在Haskell中编写Data.Vector.Unboxed实例?

我有一个数字应用程序,它使用概率的负对数做了很多工作,其中(因为概率范围从0到1)采用正双精度值或负无穷大值(如果潜在概率为零).

我使用newtype Score如下:

newtype Score = Score Double
  deriving (Eq, Ord)
 -- ^ A "score" is the negated logarithm of a probability

negLogZero :: Score -- ^ Stands in for - log 0
negLogZero = Score 10e1024

negLogOne :: Score -- ^ - log 1
negLogOne = Score 0.0

unScore :: Score -> Double
unScore (Score x) = x

instance Show Score where
  show (Score x) = show x
Run Code Online (Sandbox Code Playgroud)

现在,在Viterbi算法的实现,我已经使用Data.Vector了很多,我确实有一些Data.VectorScore秒.在尝试进行一些性能调整时,我决定尝试使用Data.Vector.Unboxed.但是,我需要编写一个Unbox …

unboxing haskell typeclass

17
推荐指数
1
解决办法
1420
查看次数

parsec类型的问题

在编写特定计算生物学文件格式的解析器时,我遇到了一些麻烦.

这是我的代码:

betaLine = string "BETA " *> p_int <*> p_int  <*> p_int <*> p_int <*> p_direction <*> p_exposure <* eol

p_int = liftA (read :: String -> Int) (many (char ' ') *> many1 digit <* many (char ' '))

p_direction = liftA mkDirection (many (char ' ') *> dir <* many (char ' '))
            where dir = oneStringOf [ "1", "-1" ]

p_exposure = liftA (map mkExposure) (many (char ' ') *> many1 (oneOf "io") <* many (char …
Run Code Online (Sandbox Code Playgroud)

haskell parsec

4
推荐指数
1
解决办法
460
查看次数

如何让Parsec让我调用`read` :: Int?

我有以下类型检查:

p_int = liftA read (many (char ' ') *> many1 digit <* many (char ' '))
Run Code Online (Sandbox Code Playgroud)

现在,正如函数名称所暗示的那样,我希望它能给我一个Int.但如果我这样做:

p_int = liftA read (many (char ' ') *> many1 digit <* many (char ' ')) :: Int
Run Code Online (Sandbox Code Playgroud)

我收到这种类型的错误:

Couldn't match expected type `Int' with actual type `f0 b0'
In the return type of a call of `liftA'
In the expression:
    liftA read (many (char ' ') *> many1 digit <* many (char ' ')) ::
      Int
In an equation for `p_int': …
Run Code Online (Sandbox Code Playgroud)

haskell parsec

2
推荐指数
2
解决办法
1424
查看次数

标签 统计

haskell ×3

parsec ×2

typeclass ×1

unboxing ×1