[project @ 1996-01-18 16:33:17 by partain]
[ghc-hetmet.git] / ghc / lib / prelude / FoldrBuild.hs
1 module PreludeFoldrBuild where
2
3 import Builtin (error)
4
5 -----------------------------------------------------------------
6 -- This needs to be in a sperate module, other than in List.hs
7 -- NOTE: no foldr/build's are done on the module that foldr is defined in.
8
9 {-# MAGIC_UNFOLDING foldr foldr #-}
10 {-# GENERATE_SPECS foldr a b #-}
11 foldr                   :: (a -> b -> b) -> b -> [a] -> b
12 foldr f z []            =  z
13 foldr f z (x:xs)        =  f x (foldr f z xs)
14
15 {-# MAGIC_UNFOLDING foldl foldl #-}
16 {-# GENERATE_SPECS foldl a b #-}
17 foldl                   :: (a -> b -> a) -> a -> [b] -> a
18 foldl f z []            =  z
19 foldl f z (x:xs)        =  foldl f (f z x) xs
20
21
22 -- HACK: Magic unfoldings not implemented for unboxed lists
23 --       Need to define a _build to avoid undefined symbol
24
25 {-# GENERATE_SPECS _build a #-}
26 _build          :: ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
27 _build g        = g (:) []
28
29