[Haskell-beginners] Function nesting

Joe Van Dyk joe at fixieconsulting.com
Thu Jan 21 21:28:52 EST 2010

On Thu, Jan 21, 2010 at 6:55 AM, Daniel Fischer
<daniel.is.fischer at web.de> wrote:
> Am Donnerstag 21 Januar 2010 15:02:11 schrieb Zbigniew Stanasiuk:
>> Hi all,
>> I've just started learning Haskell and I have no idea how to nest
>> function in following structure:
>> Mod(5*Mod(4*Mod(3*Mod(2*Mod(1, m), m), m), m), m) ... etc.
>> Could someone help me.
> Instead of func(a,b), write func a b. Arguments which are compund
> expressions themselves must be parenthesized, so
> mod (5*mod (4*mod (3*mod (2*mod 1 m) m) m) m) m
> But that is completely unreadable.
> foldl' (\z x -> (x*z) `mod` m) 1 [1 .. 5]

To the untrained eye, the first version contains a lot less weird
syntax.  You only have to know what mod does, and how parenthesis
work, both of which you learn in the third grade or so.

Joe Van Dyk

More information about the Beginners mailing list