NA values ​​in Haskell

I am doing some numerical calculations in Haskell and I would like to have values NA

inside vectors and matrices, for example in R or Matlab. The most natural way I thought was Maybe

to handle these values ​​and use Nothing

both NA

.

It works mostly with hoist operations, but I wanted to use HMatrix to get faster code. To use it correctly, I would need to make so many instances Maybe a

for the different classes defined in the code (and I'm not even sure if all of them are possible).

Is there some library that does this kind of work, or do I just need to define all the operations?

+3


source to share


1 answer


This is probably not what you want, but look NaN

("not a number"):

nan = 0/0

main = do
    print $ nan        -- NaN
    print $ nan * nan  -- NaN
    print $ nan + 0    -- NaN
    print $ nan / 2    -- NaN
    print $ isNaN 0    -- false
    print $ isNaN nan  -- true
    print $ nan == nan -- false

      



Notice the last line: NaN

not equal to yourself.

+3


source







All Articles