Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Evaluation oddity (Torsten Otto) 2. Re: Evaluation oddity (Francesco Ariis) ---------------------------------------------------------------------- Message: 1 Date: Sun, 6 Feb 2022 19:00:41 +0100 From: Torsten Otto <t-otto-n...@gmx.de> To: beginners@haskell.org Subject: [Haskell-beginners] Evaluation oddity Message-ID: <7345cfa8-899b-4331-88a6-6d5e8f04f...@gmx.de> Content-Type: text/plain; charset=utf-8 Hi all, maybe one of you sees a difference, I sure don’t… The full code for this is below. When I call *Main> diffieH 23 16 20 13 and use the result in *Main> encipher "abc" 13 „nop" I get the letters to be expected. However, when I combine these into > start text p a b = encipher text (diffieH p a b) *Main> start "abc" 23 16 20 „efg" the result changes. Any hints are most welcome. Thank you and regards Torsten > import Data.Char > diffieH p a b = (b ^ a) `mod` p > number2letter number = chr (number + 96) > letter2number letter = (ord letter) - 96 > start text p a b = encipher text (diffieH p a b) > encipher [] _ = [] > encipher (b:rest) key = (number2letter (((letter2number b)+key) `mod` 26)) > : (encipher rest key) ------------------------------ Message: 2 Date: Sun, 6 Feb 2022 20:02:47 +0100 From: Francesco Ariis <fa...@ariis.it> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Evaluation oddity Message-ID: <ygabvz7hbu1lx...@mkiii.casa> Content-Type: text/plain; charset=utf-8 Hello Otto, Il 06 febbraio 2022 alle 19:00 Torsten Otto ha scritto: > When I call > > *Main> diffieH 23 16 20 > 13 > > and use the result in > > *Main> encipher "abc" 13 > „nop" > > I get the letters to be expected. However, when I combine these into > > > start text p a b = encipher text (diffieH p a b) > > *Main> start "abc" 23 16 20 > „efg" > > the result changes. You should always write top level signatures by hand in your code. What is the signature that you want for `diffieH`? This is the inferred one λ> :t diffieH diffieH :: (Integral a, Integral b) => a -> b -> a -> a ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 163, Issue 1 *****************************************