From t-otto-news at gmx.de Sun Feb 6 18:00:41 2022 From: t-otto-news at gmx.de (Torsten Otto) Date: Sun, 6 Feb 2022 19:00:41 +0100 Subject: [Haskell-beginners] Evaluation oddity Message-ID: <7345CFA8-899B-4331-88A6-6D5E8F04F7A5@gmx.de> 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) From fa-ml at ariis.it Sun Feb 6 19:02:47 2022 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 6 Feb 2022 20:02:47 +0100 Subject: [Haskell-beginners] Evaluation oddity In-Reply-To: <7345CFA8-899B-4331-88A6-6D5E8F04F7A5@gmx.de> References: <7345CFA8-899B-4331-88A6-6D5E8F04F7A5@gmx.de> Message-ID: 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