summaryrefslogtreecommitdiff
path: root/examples/listlike.hs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/listlike.hs')
-rw-r--r--examples/listlike.hs32
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/listlike.hs b/examples/listlike.hs
new file mode 100644
index 0000000..6c54f17
--- /dev/null
+++ b/examples/listlike.hs
@@ -0,0 +1,32 @@
1{-# OPTIONS_GHC -fglasgow-exts #-}
2
3import qualified Data.ListLike as LL
4import LinearAlgebra
5import Data.Monoid
6import Data.Packed.Internal.Vector
7import Foreign
8
9instance (Storable a) => Monoid (Vector a) where
10 mempty = V { dim = 0, fptr = undefined, ptr = undefined }
11 mappend a b = mconcat [a,b]
12 mconcat = j . filter ((>0).dim)
13 where j [] = mempty
14 j l = join l
15
16instance Storable a => LL.FoldableLL (Vector a) a where
17 foldl f x v = foldl f x (toList v)
18 foldr f x v = foldr f x (toList v)
19
20instance Storable a => LL.ListLike (Vector a) a where
21 singleton a = fromList [a]
22 head a = a @> 0
23 tail a | dim a == 1 = mempty
24 | otherwise = subVector 1 (dim a -1) a
25 genericLength = fromIntegral.dim
26
27
28v k = fromList [1..k] :: Vector Double
29
30f k = k+(3::Double)
31
32main = print $ (LL.map f [1..5] :: Vector Double) \ No newline at end of file