diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-11-07 16:52:00 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-11-07 16:52:00 +0000 |
commit | 9e6500bf8e925b363e74e01834f81dde0810f808 (patch) | |
tree | a720c1e446944f649b2f21d619bf35b34411a072 /examples/experiments/listlike.hs | |
parent | 894344f9ef93a0ff5e2fb12f085b5c706b7aa9d9 (diff) |
removed -O for 6.8.1
Diffstat (limited to 'examples/experiments/listlike.hs')
-rw-r--r-- | examples/experiments/listlike.hs | 32 |
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 | |||
3 | import qualified Data.ListLike as LL | ||
4 | import Numeric.LinearAlgebra | ||
5 | import Data.Monoid | ||
6 | import Data.Packed.Internal.Vector | ||
7 | import Foreign | ||
8 | |||
9 | instance (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 | |||
16 | instance 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 | |||
20 | instance 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 | |||
28 | v k = fromList [1..k] :: Vector Double | ||
29 | |||
30 | f k = k+(3::Double) | ||
31 | |||
32 | main = print $ (LL.map f [1..5] :: Vector Double) \ No newline at end of file | ||