diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-09-21 18:28:08 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-09-21 18:28:08 +0000 |
commit | 0198366bba7a5f2d67338633f9eb90889ffc31b2 (patch) | |
tree | 4897d90233b333ee2092e63a4b74c7bcb2d22577 /examples/listlike.hs | |
parent | d4cb2692f9dae748da23371057a983deca4b2f80 (diff) |
add examples
Diffstat (limited to 'examples/listlike.hs')
-rw-r--r-- | examples/listlike.hs | 32 |
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 | |||
3 | import qualified Data.ListLike as LL | ||
4 | import 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 | ||