From 9e6500bf8e925b363e74e01834f81dde0810f808 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Wed, 7 Nov 2007 16:52:00 +0000 Subject: removed -O for 6.8.1 --- examples/experiments/listlike.hs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 examples/experiments/listlike.hs (limited to 'examples/experiments/listlike.hs') 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 @@ +{-# OPTIONS_GHC -fglasgow-exts #-} + +import qualified Data.ListLike as LL +import Numeric.LinearAlgebra +import Data.Monoid +import Data.Packed.Internal.Vector +import Foreign + +instance (Storable a) => Monoid (Vector a) where + mempty = V { dim = 0, fptr = undefined, ptr = undefined } + mappend a b = mconcat [a,b] + mconcat = j . filter ((>0).dim) + where j [] = mempty + j l = join l + +instance Storable a => LL.FoldableLL (Vector a) a where + foldl f x v = foldl f x (toList v) + foldr f x v = foldr f x (toList v) + +instance Storable a => LL.ListLike (Vector a) a where + singleton a = fromList [a] + head a = a @> 0 + tail a | dim a == 1 = mempty + | otherwise = subVector 1 (dim a -1) a + genericLength = fromIntegral.dim + + +v k = fromList [1..k] :: Vector Double + +f k = k+(3::Double) + +main = print $ (LL.map f [1..5] :: Vector Double) \ No newline at end of file -- cgit v1.2.3