[Haskell-cafe] foldl in terms of foldr

Luke Palmer lrpalmer at gmail.com
Tue Jan 26 16:06:40 EST 2010


On Tue, Jan 26, 2010 at 1:56 PM, Ryan Ingram <ryani.spam at gmail.com> wrote:
> On Tue, Jan 26, 2010 at 5:04 AM, Xingzhi Pan <vengeance.storm at gmail.com> wrote:
>> 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.
>

This is the only thing I use -XImplicitParams for:

{--} :t \x g a -> g (?f a x)
\x g a -> g (?f a x)
  :: (?f::t -> t1 -> t2) => t1 -> (t2 -> t3) -> t -> t3

Which differentiates the givens and gives them names :-)

Luke


More information about the Haskell-Cafe mailing list