
26 Jan
2010
26 Jan
'10
3:56 p.m.
On Tue, Jan 26, 2010 at 5:04 AM, Xingzhi Pan
myFoldl :: (a -> b -> a) -> a -> [b] -> a myFoldl f z xs = foldr step id xs z where step x g a = g (f a x)
Btw, is there a way I can observe the type signature of 'step' in this code?
Here is how I do it: Prelude> :t \[f] -> \x g a -> g (f a x) \[f] -> \x g a -> g (f a x) :: [t1 -> t -> t2] -> t -> (t2 -> t3) -> t1 -> t3 The [] are unnecessary but help me differentiate the "givens" from the actual arguments to the function. Here's a way that gives better type variables and properly constrains the type of f: Prelude> let test [f] x g a = g (f a x) where typeF = f `asTypeOf` const Prelude> :t test test :: [a -> b -> a] -> b -> (a -> t) -> a -> t -- ryan