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. Re: Foldl (Alexander Chen) 2. data type (Alexander Chen) 3. Re: data type (Francesco Ariis) 4. How to change base version easily? (Treee July) 5. Re: How to change base version easily? (Francesco Ariis) ---------------------------------------------------------------------- Message: 1 Date: Fri, 29 May 2020 07:22:20 +0200 (CEST) From: Alexander Chen <alexan...@chenjia.nl> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Foldl Message-ID: <1003915704.58782.1590729740...@ichabod.co-bxl> Content-Type: text/plain; charset="utf-8" May 27, 2020 11:33:58 PM CEST Tony Morris <tonymor...@gmail.com> wrote:foldl does a loop, foldr does constructor replacement https://www.youtube.com/watch?v=GPwtT31zKRY On 5/28/20 4:55 AM, Alexander Chen wrote: > Hi, > > I guess it's time to get acquainted with foldr and foldl. > > *prelude>xs = [1..5] ++ undefined* > *prelude> foldr const 0 xs* > 1 > > I assume it goes something like this: > > ( 1 `const`(2 `const`(3 `const`(4 `const`(5 `const`(undefined `const` > 0)))))) > ( > 5 `const` undefined) > (4 `const` 5) > (3 `const` 4) > ( 2 `const` 3) > (1 `const`2) > = 1 > > ======================================================================== > > > What i don't get is the opposite: > > *prelude> foldl const 0 xs* > error > > > in my mind this should go like this: > ((((((0`const`1)`const` 2) `const` 3 )`const` 4)`const` 5) > `const` undefined) > (0 `const`2) > (0`const` 3) > ( 0`const`4) > > (0`const` 5) > > (0 `const` undefined ) > = 0 > > > > I have been told that the main difference between foldl and foldr is > that foldl needs to evaluate the whole spline before it continues. And i > guess that has something to do with it. What I don't understand is WHY > foldl need to do this and foldr doesn't. > > > thanks in advance! > > best, > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200529/081e1225/attachment-0001.html> ------------------------------ Message: 2 Date: Fri, 29 May 2020 11:55:31 +0200 (CEST) From: Alexander Chen <alexan...@chenjia.nl> To: beginners@haskell.org Subject: [Haskell-beginners] data type Message-ID: <615928762.72602.1590746131...@ichabod.co-bxl> Content-Type: text/plain; charset="utf-8" import Data.Time data DatabaseItem = DbString String | DbNumber Integer | DbDate UTCTime deriving (Eq, Ord, Show) theDatabase :: [DatabaseItem] theDatabase = [ DbDate (UTCTime (fromGregorian 1911 5 1) (secondsToDiffTime 34250)) , DbNumber 9001 , DbString "Hello, world!" , DbDate (UTCTime (fromGregorian 1921 5 1) (secondsToDiffTime 34123)) ] My question: I want to get the UTCTime. So, thisFunction :: [DatabaseItem] -> [UTCTime] I don't need the answer but more the intuition (a link to a youtube etc. is also possible) how to handle these types of situations. Because i keep trying to think in terms of key:values (Python,Julia) which doesn't seem the right paradigm to approach this. thanks in advance! best, -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200529/0c160d43/attachment-0001.html> ------------------------------ Message: 3 Date: Fri, 29 May 2020 12:03:48 +0200 From: Francesco Ariis <fa...@ariis.it> To: beginners@haskell.org Subject: Re: [Haskell-beginners] data type Message-ID: <20200529100348.GA20444@extensa> Content-Type: text/plain; charset=utf-8 Hello Alexander. Il 29 maggio 2020 alle 11:55 Alexander Chen ha scritto: > import Data.Time > > data DatabaseItem = DbString String > | DbNumber Integer > | DbDate UTCTime > deriving (Eq, Ord, Show) > > theDatabase :: [DatabaseItem] > theDatabase = > [ DbDate (UTCTime > (fromGregorian 1911 5 1) > (secondsToDiffTime 34250)) > , DbNumber 9001 > , DbString "Hello, world!" > , DbDate (UTCTime > (fromGregorian 1921 5 1) > (secondsToDiffTime 34123)) > ] > > My question: > > I want to get the UTCTime. > > So, thisFunction :: [DatabaseItem] -> [UTCTime] This is an excellent first step. A good candidate function is `map` λ> :t map map :: (a -> b) -> [a] -> [b] and if we fill in the arguments we are sure of and leave the rest out, ghc will — on reload/recompile — tell us what is missing. E.g: thisFunction :: [DatabaseItem] -> [UTCTime] thisFunction ds = map _ ds will lead to • Found hole: _ :: DatabaseItem -> UTCTime • In the first argument of ‘map’, namely ‘_’ Can you write a function with `DatabaseItem -> UTCTime` signature? ------------------------------ Message: 4 Date: Fri, 29 May 2020 18:35:18 +0800 From: Treee July <julytr...@gmail.com> To: beginners@haskell.org Subject: [Haskell-beginners] How to change base version easily? Message-ID: <CAGfc3Ot6OfR9YMdGDegvEeRvXiiStLYhYKS=l25medd1do0...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hello, I installed the latest version of ghc, which caused one of my packages does not satisfy the constraint of the version. I just wondering if there exists a convenient way to degrade the version of the base. I use Arch Linux, which is not easy to install an elder version. Thanks, July -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200529/0fb93e24/attachment-0001.html> ------------------------------ Message: 5 Date: Fri, 29 May 2020 12:56:42 +0200 From: Francesco Ariis <fa...@ariis.it> To: beginners@haskell.org Subject: Re: [Haskell-beginners] How to change base version easily? Message-ID: <20200529105642.GA15236@extensa> Content-Type: text/plain; charset=utf-8 Hello July, Il 29 maggio 2020 alle 18:35 Treee July ha scritto: > Hello, > I installed the latest version of ghc, which caused one of my packages does > not satisfy the constraint of the version. I just wondering if there exists > a convenient way to degrade the version of the base. I use Arch Linux, > which is not easy to install an elder version. if you are using cabal, --allow-newer can ease some of the pain. Failing that, -w will work — but you need to download and locally install the appropriate ghc first. Let us know if that’s enough ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 143, Issue 17 ******************************************