summaryrefslogtreecommitdiff
path: root/examples/experiments/listlike.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-11-07 16:52:00 +0000
committerAlberto Ruiz <aruiz@um.es>2007-11-07 16:52:00 +0000
commit9e6500bf8e925b363e74e01834f81dde0810f808 (patch)
treea720c1e446944f649b2f21d619bf35b34411a072 /examples/experiments/listlike.hs
parent894344f9ef93a0ff5e2fb12f085b5c706b7aa9d9 (diff)
removed -O for 6.8.1
Diffstat (limited to 'examples/experiments/listlike.hs')
-rw-r--r--examples/experiments/listlike.hs32
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/experiments/listlike.hs b/examples/experiments/listlike.hs
new file mode 100644
index 0000000..43216cb
--- /dev/null
+++ b/examples/experiments/listlike.hs
@@ -0,0 +1,32 @@
1{-# OPTIONS_GHC -fglasgow-exts #-}
2
3import qualified Data.ListLike as LL
4import Numeric.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