File: Vector.hs

package info (click to toggle)
bali-phy 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,392 kB
  • sloc: cpp: 120,442; xml: 13,966; haskell: 9,975; python: 2,936; yacc: 1,328; perl: 1,169; lex: 912; sh: 343; makefile: 26
file content (31 lines) | stat: -rw-r--r-- 814 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{-# LANGUAGE NoImplicitPrelude #-}
module Foreign.Vector where

import Foreign.CList
import Data.Foldable
import Data.Eq
import Data.Function

data EVector a

foreign import bpcall "Vector:" get_vector_index :: EVector a -> Int -> a

foreign import bpcall "Vector:" vector_size :: EVector a -> Int

foreign import bpcall "Vector:" clist_to_vector :: CList a -> EVector a

sizedVectorToList :: EVector a -> Int -> [a]
sizedVectorToList vec size = mapFrom 0# size (\i -> get_vector_index vec i)

vectorToList :: EVector a -> [a]
vectorToList vec = sizedVectorToList vec (vector_size vec)

listToVector :: [a] -> EVector a
listToVector x = clist_to_vector (listToCList x)

instance Foldable EVector where
    toList = vectorToList
    length = vector_size
    null v = length v == 0

toVector = listToVector . toList