How do I write a Data.Vector.Unboxed instance in Haskell?

前端 未结 1 497
独厮守ぢ
独厮守ぢ 2021-02-04 04:58

I\'ve got a numeric application that does a lot of work with negative logs of probabilities, which (since probabilities range from zero to one) take the values of positive doubl

相关标签:
1条回答
  • 2021-02-04 05:44

    The Unbox type class doesn't have any methods -- it's just shorthand for the Vector and MVector type classes. Derive those, and the Unbox class comes for free (either via deriving or by just writing instance U.Unbox Score on its own line somewhere).

    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    import Data.Vector.Generic.Base
    import Data.Vector.Generic.Mutable
    import qualified Data.Vector.Unboxed as U
    newtype Score = Score Double deriving (Vector U.Vector, MVector U.MVector, U.Unbox)
    
    0 讨论(0)
提交回复
热议问题