
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. Regards, Zbig

On Thu, Jan 21, 2010 at 2:02 PM, 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.
I don't quite understand what you mean by "nest function". 'Mod' looks like a constructor in your code, but I somehow get the feeling that you actually indend 'Mod' to be a function... /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe

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.
Regards, Zbig
To be precise, I have list [1.20]::Int, mod function, m::Int as a input and as a result I want to get above. I have tried to play with fold family functions but no good results. Zbig

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] Much better :)
Regards, Zbig

On Thu, Jan 21, 2010 at 6:55 AM, Daniel Fischer
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 http://fixieconsulting.com
participants (4)
-
Daniel Fischer
-
Joe Van Dyk
-
Magnus Therning
-
Zbigniew Stanasiuk