summaryrefslogtreecommitdiff
path: root/examples/listlike.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-09-21 18:28:08 +0000
committerAlberto Ruiz <aruiz@um.es>2007-09-21 18:28:08 +0000
commit0198366bba7a5f2d67338633f9eb90889ffc31b2 (patch)
tree4897d90233b333ee2092e63a4b74c7bcb2d22577 /examples/listlike.hs
parentd4cb2692f9dae748da23371057a983deca4b2f80 (diff)
add examples
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