[Hat] Problems with hat-trans and Edison
Stephen Pitts
hat@haskell.org
Thu, 03 Apr 2003 09:40:34 -0600
--Boundary_(ID_5M+n+S7b3z0HrefDrAMO/g)
Content-type: text/plain; charset=US-ASCII; format=flowed
Content-transfer-encoding: 7BIT
Hi!
I'm trying to use hat to analyze a program I wrote that uses the Edison
libraries, but hat is choking on part of Edison. hat-trans on the
attached file seems to work OK, but ghc barfs when compiling the
generated output:
Hat/Sequence.hs:1:
Multiple declarations of `Hat.Sequence.sreverse'
Hat/Sequence.hs:62
Hat/Sequence.hs:283
Hat/Sequence.hs:1:
Multiple declarations of `Hat.Sequence.szip'
Hat/Sequence.hs:189
Hat/Sequence.hs:343
Hat/Sequence.hs:1:
Multiple declarations of `Hat.Sequence.szip3'
Hat/Sequence.hs:196
Hat/Sequence.hs:345
Hat/Sequence.hs:1:
Multiple declarations of `Hat.Sequence.sunzip'
Hat/Sequence.hs:222
Hat/Sequence.hs:355
Hat/Sequence.hs:1:
Multiple declarations of `Hat.Sequence.sunzip3'
Hat/Sequence.hs:228
Hat/Sequence.hs:357
I've attached the result of running hat-trans on Sequence.hs as
Sequence-hat.hs.
--Boundary_(ID_5M+n+S7b3z0HrefDrAMO/g)
Content-type: application/octet-stream; x-unix-mode=0644; name=Sequence-hat.hs
Content-transfer-encoding: 7bit
Content-disposition: attachment; filename=Sequence-hat.hs
module Hat.Sequence (Sequence(..),Maybe2(Just2,Nothing2),aJust2,aNothing2) where
import qualified Prelude
import qualified Hat.Hat as T
import qualified Hat.PreludeBasic
import Hat.Prelude hiding (gconcat,aconcat,hconcat,greverse,gmap,amap,hmap
,gconcatMap,aconcatMap,hconcatMap,gfoldr,afoldr,hfoldr,gfoldl,afoldl,hfoldl
,gfoldr1,afoldr1,hfoldr1,gfoldl1,afoldl1,hfoldl1,gfilter,afilter,hfilter
,gtakeWhile,atakeWhile,htakeWhile,gdropWhile,adropWhile,hdropWhile,glookup
,alookup,hlookup,gtake,atake,htake,gdrop,adrop,hdrop,gsplitAt,asplitAt
,hsplitAt,gzip,gzip3,gzipWith,azipWith,hzipWith,gzipWith3,azipWith3,hzipWith3
,gunzip,gunzip3,gnull,anull,hnull)
import Hat.Monad
import Hat.EdisonPrelude (Maybe2(Just2,Nothing2),aJust2,aNothing2)
class (Functor s,MonadPlus s) => Sequence s
where
gempty :: T.RefSrcPos -> T.RefExp -> T.R (s a)
gsingle :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun a (s a))
gcons :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun a (T.Fun (s a) (s a)))
gsnoc :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) (T.Fun a (s a)))
gappend :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) (T.Fun (s a) (s a)))
gfromList :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (T.List a) (s a))
gcopy :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun Int (T.Fun a (s a)))
gtabulate ::
T.RefSrcPos -> T.RefExp -> T.R (T.Fun Int (T.Fun (T.Fun Int a) (s a)))
glview :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) (Maybe2 a (s a)))
glhead :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) a)
gltail :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) (s a))
grview :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) (Maybe2 (s a) a))
grhead :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) a)
grtail :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) (s a))
gnull :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) Bool)
hnull :: (T.R (s a)) -> T.RefExp -> T.R Bool
gsize :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) Int)
gtoList :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) (T.List a))
gconcat :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s (s a)) (s a))
hconcat :: (T.R (s (s a))) -> T.RefExp -> T.R (s a)
greverse :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) (s a))
sreverse :: T.R (T.Fun (s a) (s a))
greverseOnto ::
T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) (T.Fun (s a) (s a)))
gmap :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (T.Fun a b) (T.Fun (s a) (s b)))
hmap :: (T.R (T.Fun a b)) -> (T.R (s a)) -> T.RefExp -> T.R (s b)
gconcatMap ::
T.RefSrcPos -> T.RefExp -> T.R (T.Fun (T.Fun a (s b)) (T.Fun (s a) (s b)))
hconcatMap :: (T.R (T.Fun a (s b))) -> T.RefExp -> T.R (T.Fun (s a) (s b))
gfoldr ::
T.RefSrcPos ->
T.RefExp -> T.R (T.Fun (T.Fun a (T.Fun b b)) (T.Fun b (T.Fun (s a) b)))
hfoldr ::
(T.R (T.Fun a (T.Fun b b))) -> (T.R b) -> (T.R (s a)) -> T.RefExp -> T.R b
gfoldl ::
T.RefSrcPos ->
T.RefExp -> T.R (T.Fun (T.Fun b (T.Fun a b)) (T.Fun b (T.Fun (s a) b)))
hfoldl ::
(T.R (T.Fun b (T.Fun a b))) -> (T.R b) -> (T.R (s a)) -> T.RefExp -> T.R b
gfoldr1 ::
T.RefSrcPos -> T.RefExp -> T.R (T.Fun (T.Fun a (T.Fun a a)) (T.Fun (s a) a))
hfoldr1 :: (T.R (T.Fun a (T.Fun a a))) -> (T.R (s a)) -> T.RefExp -> T.R a
gfoldl1 ::
T.RefSrcPos -> T.RefExp -> T.R (T.Fun (T.Fun a (T.Fun a a)) (T.Fun (s a) a))
hfoldl1 :: (T.R (T.Fun a (T.Fun a a))) -> (T.R (s a)) -> T.RefExp -> T.R a
greducer ::
T.RefSrcPos ->
T.RefExp -> T.R (T.Fun (T.Fun a (T.Fun a a)) (T.Fun a (T.Fun (s a) a)))
greducel ::
T.RefSrcPos ->
T.RefExp -> T.R (T.Fun (T.Fun a (T.Fun a a)) (T.Fun a (T.Fun (s a) a)))
greduce1 ::
T.RefSrcPos -> T.RefExp -> T.R (T.Fun (T.Fun a (T.Fun a a)) (T.Fun (s a) a))
gtake :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun Int (T.Fun (s a) (s a)))
htake :: (T.R Int) -> (T.R (s a)) -> T.RefExp -> T.R (s a)
gdrop :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun Int (T.Fun (s a) (s a)))
hdrop :: (T.R Int) -> (T.R (s a)) -> T.RefExp -> T.R (s a)
gsplitAt ::
T.RefSrcPos ->
T.RefExp -> T.R (T.Fun Int (T.Fun (s a) (T.Tuple2 (s a) (s a))))
hsplitAt :: (T.R Int) -> (T.R (s a)) -> T.RefExp -> T.R (T.Tuple2 (s a) (s a))
gsubseq ::
T.RefSrcPos -> T.RefExp -> T.R (T.Fun Int (T.Fun Int (T.Fun (s a) (s a))))
gfilter ::
T.RefSrcPos -> T.RefExp -> T.R (T.Fun (T.Fun a Bool) (T.Fun (s a) (s a)))
hfilter :: (T.R (T.Fun a Bool)) -> (T.R (s a)) -> T.RefExp -> T.R (s a)
gpartition ::
T.RefSrcPos ->
T.RefExp ->
T.R (T.Fun (T.Fun a Bool) (T.Fun (s a) (T.Tuple2 (s a) (s a))))
gtakeWhile ::
T.RefSrcPos -> T.RefExp -> T.R (T.Fun (T.Fun a Bool) (T.Fun (s a) (s a)))
htakeWhile :: (T.R (T.Fun a Bool)) -> (T.R (s a)) -> T.RefExp -> T.R (s a)
gdropWhile ::
T.RefSrcPos -> T.RefExp -> T.R (T.Fun (T.Fun a Bool) (T.Fun (s a) (s a)))
hdropWhile :: (T.R (T.Fun a Bool)) -> (T.R (s a)) -> T.RefExp -> T.R (s a)
gsplitWhile ::
T.RefSrcPos ->
T.RefExp ->
T.R (T.Fun (T.Fun a Bool) (T.Fun (s a) (T.Tuple2 (s a) (s a))))
ginBounds :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) (T.Fun Int Bool))
glookup :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) (T.Fun Int a))
hlookup :: (T.R (s a)) -> (T.R Int) -> T.RefExp -> T.R a
glookupM :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) (T.Fun Int (Maybe a)))
glookupWithDefault ::
T.RefSrcPos -> T.RefExp -> T.R (T.Fun a (T.Fun (s a) (T.Fun Int a)))
gupdate ::
T.RefSrcPos -> T.RefExp -> T.R (T.Fun Int (T.Fun a (T.Fun (s a) (s a))))
gadjust ::
T.RefSrcPos ->
T.RefExp -> T.R (T.Fun (T.Fun a a) (T.Fun Int (T.Fun (s a) (s a))))
gmapWithIndex ::
T.RefSrcPos ->
T.RefExp -> T.R (T.Fun (T.Fun Int (T.Fun a b)) (T.Fun (s a) (s b)))
gfoldrWithIndex ::
T.RefSrcPos ->
T.RefExp ->
T.R (T.Fun (T.Fun Int (T.Fun a (T.Fun b b))) (T.Fun b (T.Fun (s a) b)))
gfoldlWithIndex ::
T.RefSrcPos ->
T.RefExp ->
T.R (T.Fun (T.Fun b (T.Fun Int (T.Fun a b))) (T.Fun b (T.Fun (s a) b)))
gzip ::
T.RefSrcPos ->
T.RefExp -> T.R (T.Fun (s a) (T.Fun (s b) (s (T.Tuple2 a b))))
szip :: T.R (T.Fun (s a) (T.Fun (s b) (s (T.Tuple2 a b))))
gzip3 ::
T.RefSrcPos ->
T.RefExp ->
T.R (T.Fun (s a) (T.Fun (s b) (T.Fun (s c) (s (T.Tuple3 a b c)))))
szip3 :: T.R (T.Fun (s a) (T.Fun (s b) (T.Fun (s c) (s (T.Tuple3 a b c)))))
gzipWith ::
T.RefSrcPos ->
T.RefExp ->
T.R (T.Fun (T.Fun a (T.Fun b c)) (T.Fun (s a) (T.Fun (s b) (s c))))
hzipWith ::
(T.R (T.Fun a (T.Fun b c))) ->
(T.R (s a)) -> (T.R (s b)) -> T.RefExp -> T.R (s c)
gzipWith3 ::
T.RefSrcPos ->
T.RefExp ->
T.R
(T.Fun (T.Fun a (T.Fun b (T.Fun c d)))
(T.Fun (s a) (T.Fun (s b) (T.Fun (s c) (s d)))))
hzipWith3 ::
(T.R (T.Fun a (T.Fun b (T.Fun c d)))) ->
(T.R (s a)) -> (T.R (s b)) -> (T.R (s c)) -> T.RefExp -> T.R (s d)
gunzip ::
T.RefSrcPos ->
T.RefExp -> T.R (T.Fun (s (T.Tuple2 a b)) (T.Tuple2 (s a) (s b)))
sunzip :: T.R (T.Fun (s (T.Tuple2 a b)) (T.Tuple2 (s a) (s b)))
gunzip3 ::
T.RefSrcPos ->
T.RefExp -> T.R (T.Fun (s (T.Tuple3 a b c)) (T.Tuple3 (s a) (s b) (s c)))
sunzip3 :: T.R (T.Fun (s (T.Tuple3 a b c)) (T.Tuple3 (s a) (s b) (s c)))
gunzipWith ::
T.RefSrcPos ->
T.RefExp ->
T.R
(T.Fun (T.Fun a b)
(T.Fun (T.Fun a c) (T.Fun (s a) (T.Tuple2 (s b) (s c)))))
gunzipWith3 ::
T.RefSrcPos ->
T.RefExp ->
T.R
(T.Fun (T.Fun a b)
(T.Fun (T.Fun a c)
(T.Fun (T.Fun a d) (T.Fun (s a) (T.Tuple3 (s b) (s c) (s d))))))
ginstanceName :: T.RefSrcPos -> T.RefExp -> T.R (T.Fun (s a) String)
sempty :: T.R (s a)
ssingle :: T.R (T.Fun a (s a))
scons :: T.R (T.Fun a (T.Fun (s a) (s a)))
ssnoc :: T.R (T.Fun (s a) (T.Fun a (s a)))
sappend :: T.R (T.Fun (s a) (T.Fun (s a) (s a)))
sfromList :: T.R (T.Fun (T.List a) (s a))
scopy :: T.R (T.Fun Int (T.Fun a (s a)))
stabulate :: T.R (T.Fun Int (T.Fun (T.Fun Int a) (s a)))
slview :: T.R (T.Fun (s a) (Maybe2 a (s a)))
slhead :: T.R (T.Fun (s a) a)
sltail :: T.R (T.Fun (s a) (s a))
srview :: T.R (T.Fun (s a) (Maybe2 (s a) a))
srhead :: T.R (T.Fun (s a) a)
srtail :: T.R (T.Fun (s a) (s a))
snull :: T.R (T.Fun (s a) Bool)
ssize :: T.R (T.Fun (s a) Int)
stoList :: T.R (T.Fun (s a) (T.List a))
sconcat :: T.R (T.Fun (s (s a)) (s a))
sreverse :: T.R (T.Fun (s a) (s a))
sreverseOnto :: T.R (T.Fun (s a) (T.Fun (s a) (s a)))
smap :: T.R (T.Fun (T.Fun a b) (T.Fun (s a) (s b)))
sconcatMap :: T.R (T.Fun (T.Fun a (s b)) (T.Fun (s a) (s b)))
sfoldr :: T.R (T.Fun (T.Fun a (T.Fun b b)) (T.Fun b (T.Fun (s a) b)))
sfoldl :: T.R (T.Fun (T.Fun b (T.Fun a b)) (T.Fun b (T.Fun (s a) b)))
sfoldr1 :: T.R (T.Fun (T.Fun a (T.Fun a a)) (T.Fun (s a) a))
sfoldl1 :: T.R (T.Fun (T.Fun a (T.Fun a a)) (T.Fun (s a) a))
sreducer :: T.R (T.Fun (T.Fun a (T.Fun a a)) (T.Fun a (T.Fun (s a) a)))
sreducel :: T.R (T.Fun (T.Fun a (T.Fun a a)) (T.Fun a (T.Fun (s a) a)))
sreduce1 :: T.R (T.Fun (T.Fun a (T.Fun a a)) (T.Fun (s a) a))
stake :: T.R (T.Fun Int (T.Fun (s a) (s a)))
sdrop :: T.R (T.Fun Int (T.Fun (s a) (s a)))
ssplitAt :: T.R (T.Fun Int (T.Fun (s a) (T.Tuple2 (s a) (s a))))
ssubseq :: T.R (T.Fun Int (T.Fun Int (T.Fun (s a) (s a))))
sfilter :: T.R (T.Fun (T.Fun a Bool) (T.Fun (s a) (s a)))
spartition :: T.R (T.Fun (T.Fun a Bool) (T.Fun (s a) (T.Tuple2 (s a) (s a))))
stakeWhile :: T.R (T.Fun (T.Fun a Bool) (T.Fun (s a) (s a)))
sdropWhile :: T.R (T.Fun (T.Fun a Bool) (T.Fun (s a) (s a)))
ssplitWhile :: T.R (T.Fun (T.Fun a Bool) (T.Fun (s a) (T.Tuple2 (s a) (s a))))
sinBounds :: T.R (T.Fun (s a) (T.Fun Int Bool))
slookup :: T.R (T.Fun (s a) (T.Fun Int a))
slookupM :: T.R (T.Fun (s a) (T.Fun Int (Maybe a)))
slookupWithDefault :: T.R (T.Fun a (T.Fun (s a) (T.Fun Int a)))
supdate :: T.R (T.Fun Int (T.Fun a (T.Fun (s a) (s a))))
sadjust :: T.R (T.Fun (T.Fun a a) (T.Fun Int (T.Fun (s a) (s a))))
smapWithIndex :: T.R (T.Fun (T.Fun Int (T.Fun a b)) (T.Fun (s a) (s b)))
sfoldrWithIndex ::
T.R (T.Fun (T.Fun Int (T.Fun a (T.Fun b b))) (T.Fun b (T.Fun (s a) b)))
sfoldlWithIndex ::
T.R (T.Fun (T.Fun b (T.Fun Int (T.Fun a b))) (T.Fun b (T.Fun (s a) b)))
szip :: T.R (T.Fun (s a) (T.Fun (s b) (s (T.Tuple2 a b))))
szip3 :: T.R (T.Fun (s a) (T.Fun (s b) (T.Fun (s c) (s (T.Tuple3 a b c)))))
szipWith ::
T.R (T.Fun (T.Fun a (T.Fun b c)) (T.Fun (s a) (T.Fun (s b) (s c))))
szipWith3 ::
T.R
(T.Fun (T.Fun a (T.Fun b (T.Fun c d)))
(T.Fun (s a) (T.Fun (s b) (T.Fun (s c) (s d)))))
sunzip :: T.R (T.Fun (s (T.Tuple2 a b)) (T.Tuple2 (s a) (s b)))
sunzip3 :: T.R (T.Fun (s (T.Tuple3 a b c)) (T.Tuple3 (s a) (s b) (s c)))
sunzipWith ::
T.R
(T.Fun (T.Fun a b)
(T.Fun (T.Fun a c) (T.Fun (s a) (T.Tuple2 (s b) (s c)))))
sunzipWith3 ::
T.R
(T.Fun (T.Fun a b)
(T.Fun (T.Fun a c)
(T.Fun (T.Fun a d) (T.Fun (s a) (T.Tuple3 (s b) (s c) (s d))))))
sinstanceName :: T.R (T.Fun (s a) String)
tSequence = T.mkModule "Sequence" "Sequence.hs" Prelude.True
--Boundary_(ID_5M+n+S7b3z0HrefDrAMO/g)
Content-type: application/octet-stream; x-unix-mode=0644; name=Sequence.hs
Content-transfer-encoding: 7bit
Content-disposition: attachment; filename=Sequence.hs
-- Copyright (c) 1998-1999 Chris Okasaki.
-- See COPYRIGHT file for terms and conditions.
module Sequence (
-- class definition + method wrappers
module Sequence,
-- re-export view type from EdisonPrelude for convenience
Maybe2(..)
) where
import Prelude hiding (concat,reverse,map,concatMap,foldr,foldl,foldr1,foldl1,
filter,takeWhile,dropWhile,lookup,take,drop,splitAt,
zip,zip3,zipWith,zipWith3,unzip,unzip3,null)
import Monad
import EdisonPrelude(Maybe2(..))
-- naming convention: instances of Sequence are named Seq whenever possible
class (Functor s, MonadPlus s) => Sequence s where
-- in addition to Functor, Monad, and MonadPlus,
-- sequences should also be instances of Eq and Show
----------------------------------------------------------------------
-- Constructors
empty :: s a
single :: a -> s a
-- empty = <>
-- single x = <x>
cons :: a -> s a -> s a
snoc :: s a -> a -> s a
append :: s a -> s a -> s a
-- cons x <x0,...,xn-1> = <x,x0,...,xn-1>
-- snoc <x0,...,xn-1> x = <x0,...,xn-1,x>
-- append <x0,...,xn-1> <y0,...,ym-1> = <x0,...,xn-1,y0,...,ym-1>
fromList :: [a] -> s a
-- fromList [x0,...,xn-1] = <x0,...,xn-1>
-- initialize a sequence
copy :: Int -> a -> s a -- returns empty if size is negative
tabulate :: Int -> (Int -> a) -> s a -- returns empty if size is negative
-- copy n x = <x,...,x> -- n copies
-- tabulate f n = <f 0,...,f n-1>
----------------------------------------------------------------------
-- Destructors
-- view the left element
lview :: s a -> Maybe2 a (s a)
lhead :: s a -> a -- signals error if sequence is empty
ltail :: s a -> s a -- returns empty if sequence is empty
-- lview <x0,...,xn-1> | n==0 = Nothing2
-- | n>0 = Just2 x0 <x1,...,xn-1>
-- lhead <x0,...,xn-1> | n==0 = error "ModuleName.lhead: empty sequence"
-- | n>0 = x0
-- ltail <x0,...,xn-1> | n==0 = <>
-- | n>0 = <x1,...,xn-1>
-- view the right element
rview :: s a -> Maybe2 (s a) a
rhead :: s a -> a -- signals error if sequence is empty
rtail :: s a -> s a -- returns empty if sequence is empty
-- rview <x0,...,xn-1> | n==0 = Nothing2
-- | n>0 = Just2 <x0,...,xn-2> xn-1
-- rhead <x0,...,xn-1> | n==0 = error "ModuleName.rhead: empty sequence"
-- | n>0 = xn-1
-- rtail <x0,...,xn-1> | n==0 = <>
-- | n>0 = <x0,...,xn-2>
----------------------------------------------------------------------
-- Observers
null :: s a -> Bool
size :: s a -> Int
-- null <x0,...,xn-1> = (n==0)
-- size <x0,...,xn-1> = n
toList :: s a -> [a]
-- toList <x0,...,xn-1> = [x0,...,xn-1]
----------------------------------------------------------------------
-- Concat and revers
-- flattening a sequence
concat :: s (s a) -> s a
-- concat xss = foldr append empty xss
-- reversing a sequence
reverse :: s a -> s a
reverseOnto :: s a -> s a -> s a
-- reverse <x0,...,xn-1> = <xn-1,...,x0>
-- reverseOnto <x0,...,xn-1> <y0,...,ym-1> = <xn-1,...,x0,y0,...,ym-1>
----------------------------------------------------------------------
-- Maps and folds
map :: (a -> b) -> s a -> s b
concatMap :: (a -> s b) -> s a -> s b
-- map f <x0,...,xn-1> = <f x0,...,f xn-1>
-- concatMap f xs = concat (map f xs)
foldr :: (a -> b -> b) -> b -> s a -> b
foldl :: (b -> a -> b) -> b -> s a -> b
-- foldr (+) c <x0,...,xn-1> = x0 + (x1 + ... + (xn-1 + c))
-- foldl (+) c <x0,...,xn-1> = ((c + x0) + x1) + ... + xn-1
foldr1 :: (a -> a -> a) -> s a -> a -- signals error if sequence is empty
foldl1 :: (a -> a -> a) -> s a -> a -- signals error if sequence is empty
-- foldr1 (+) <x0,...,xn-1>
-- | n==0 = error "ModuleName.foldr1: empty sequence"
-- | n>0 = x0 + (x1 + ... + xn-1)
-- foldl1 (+) <x0,...,xn-1>
-- | n==0 = error "ModuleName.foldl1: empty sequence"
-- | n>0 = (x0 + x1) + ... + xn-1
reducer :: (a -> a -> a) -> a -> s a -> a
reducel :: (a -> a -> a) -> a -> s a -> a
reduce1 :: (a -> a -> a) -> s a -> a -- signals error if sequence is empty
-- reduce is similar to fold, but combines elements in a balanced fashion
-- the combining function should usually be associative
--
-- reducer (+) x xs = reduce1 (+) (cons x xs)
-- reducel (+) x xs = reduce1 (+) (snoc xs x)
--
-- reduce1 (+) <x> = x
-- reduce1 (+) <x0,...,xn-1> =
-- (reduce1 (+) <x0,...,xi>) + (reduce1 (+) <xi+1,...,xn-1>)
-- for some i such that 0 <= i && i < n-1
--
-- Although the exact value of i is unspecified it tends toward n/2
-- so that the depth of calls to + is at most logarithmic
----------------------------------------------------------------------
-- Subsequences
take :: Int -> s a -> s a
drop :: Int -> s a -> s a
splitAt :: Int -> s a -> (s a, s a)
-- take i xs = fst (splitAt i xs)
-- drop i xs = snd (splitAt i xs)
--
-- splitAt i xs
-- | i < 0 = (<> , <x0,...,xn-1>)
-- | i < n = (<x0,...,xi-1>, <xi,...,xn-1>)
-- | i >= n = (<x0,...,xn-1>, <> )
subseq :: Int -> Int -> s a -> s a
-- args are index/length rather than start index/end index
--
-- subseq i len xs = take len (drop i xs)
----------------------------------------------------------------------
-- Predicate-based operations
filter :: (a -> Bool) -> s a -> s a
partition :: (a -> Bool) -> s a -> (s a, s a)
-- filter p xs = foldr pcons empty xs
-- where pcons x xs = if p x then cons x xs else xs
--
-- partition p xs = (filter p xs, filter (not . p) xs)
takeWhile :: (a -> Bool) -> s a -> s a
dropWhile :: (a -> Bool) -> s a -> s a
splitWhile :: (a -> Bool) -> s a -> (s a, s a)
-- takeWhile p xs = fst (splitWhile p xs)
-- dropWhile p xs = snd (splitWhile p xs)
--
-- splitWhile p <x0,...,xn-1> = (<x0,...,xi-1>, <xi,...,xn-1>)
-- where i = min j such that p xj (or n if no such j)
----------------------------------------------------------------------
-- Index-based operations (zero-based)
inBounds :: s a -> Int -> Bool
-- inBounds <x0,...,xn-1> i = (0 <= i && i < n)
lookup :: s a -> Int -> a -- signals error if index out of bounds
lookupM :: s a -> Int -> Maybe a
lookupWithDefault :: a -> s a -> Int -> a
-- lookup xs@<x0,...,xn-1> i
-- | inBounds xs = xi
-- | otherwise = error "ModuleName.lookup: index out of bounds"
-- lookupM xs@<x0,...,xn-1> i
-- | inBounds xs = Just xi
-- | otherwise = Nothing
-- lookupWithDefault d xs@<x0,...,xn-1> i
-- | inBounds xs = xi
-- | otherwise = d
update :: Int -> a -> s a -> s a
adjust :: (a -> a) -> Int -> s a -> s a -- map a single element
-- both return original sequence if index out of bounds
--
-- update i y xs@<x0,...,xn-1>
-- | inBounds xs = <x0,...xi-1,y,xi+1,...,xn-1>
-- | otherwise = xs
-- adjust f i xs@<x0,...,xn-1>
-- | inBounds xs = <x0,...xi-1,f xi,xi+1,...,xn-1>
-- | otherwise = xs
mapWithIndex :: (Int -> a -> b) -> s a -> s b
foldrWithIndex :: (Int -> a -> b -> b) -> b -> s a -> b
foldlWithIndex :: (b -> Int -> a -> b) -> b -> s a -> b
-- mapWithIndex f <x0,...,xn-1> = <f 0 x0,...,f (n-1) xn-1>
-- foldrWithIndex f c <x0,...,xn-1> =
-- f 0 x0 (f 1 x1 (... (f (n-1) xn-1 c)))
-- foldlWithIndex f c <x0,...,xn-1> =
-- f (...(f (f c 0 x0) 1 x1)...) (n-1) xn-1)
----------------------------------------------------------------------
-- Zips and unzips
zip :: s a -> s b -> s (a,b)
zip3 :: s a -> s b -> s c -> s (a,b,c)
-- zip <x0,...,xn-1> <y0,...,ym-1> = <(x0,y0),...,(xj-1,yj-1)>
-- where j = min {n,m}
-- zip3 <x0,...,xn-1> <y0,...,ym-1> <z0,...,zk-1> =
-- <(x0,y0,z0),...,(xj-1,yj-1,zj-1)>
-- where j = min {n,m,k}
zipWith :: (a -> b -> c) -> s a -> s b -> s c
zipWith3 :: (a -> b -> c -> d) -> s a -> s b -> s c -> s d
-- zipWith f xs ys = map (uncurry f) (zip xs ys)
-- zipWith3 f xs ys zs = map (uncurry f) (zip3 xs ys zs)
unzip :: s (a,b) -> (s a, s b)
unzip3 :: s (a,b,c) -> (s a, s b, s c)
-- unzip xs = (map fst xs, map snd xs)
-- unzip3 xs = (map fst3 xs, map snd3 xs, map thd3 xs)
-- where fst3 (x,y,z) = x
-- snd3 (x,y,z) = y
-- thd3 (x,y,z) = z
unzipWith :: (a -> b) -> (a -> c) -> s a -> (s b, s c)
unzipWith3 :: (a -> b) -> (a -> c) -> (a -> d) -> s a -> (s b, s c, s d)
-- unzipWith f g xs = (map f xs, map g xs)
-- unzipWith3 f g h xs = (map f xs, map g xs, map h xs)
----------------------------------------------------------------------
-- Documentation
instanceName :: s a -> String
-- The name of the module implementing s.
----------------------------------------------------------------------
-- Other possible operations not currently included
{-
insertAt :: Int -> a -> s a -> s a
-- adds to front or rear if index out of bounds
--
-- insertAt i y xs@<x0,...,xn-1>
-- | i < 0 = cons y xs
-- | i >= n = snoc xs y
-- | otherwise = <x0,...,xi-1,y,xi,...,xn-1>
deleteAt :: Int -> s a -> s a
-- returns original sequence if index out of bounds
--
-- deleteAt i xs@<x0,...,xn-1>
-- | i < 0 = xs
-- | i >= n = xs
-- | otherwise = <x0,...,xi-1,xi+1,...,xn-1>
insertAt i x s = append before (cons x after)
where (before, after) = splitAt i s
deleteAt i s = if i < 0 then s else append before (ltail after)
where (before, after) = splitAt i s
-}
--Boundary_(ID_5M+n+S7b3z0HrefDrAMO/g)
Content-type: text/plain; charset=US-ASCII; format=flowed
Content-transfer-encoding: 7BIT
--
Stephen Pitts
smpitts@ou.edu
"This is the planet of Six Billion Dancing Monkeys. Enjoy it while it
lasts." -- poster on kuro5hin
--Boundary_(ID_5M+n+S7b3z0HrefDrAMO/g)--