From borgauf at gmail.com Thu Jun 3 22:40:41 2021 From: borgauf at gmail.com (Galaxy Being) Date: Thu, 3 Jun 2021 17:40:41 -0500 Subject: [Haskell-beginners] Data constraint? Message-ID: If I have a type type WaterChem = CaHardness NaturalChem | Alkalinity NaturalChem and I want to have the values of CaHardness and Alkalinity constrained to positive Int and between certain high and low values, I could do a newtype to creater a NaturalChem number, thus never less than 0, but what is the best practice to insure these values are between a certain range? Types in Haskell can't go that far, can they? Reading this tells me I can have some of what I want. How are type values that need to be constrained handled best practices? Again, the type world of Haskell seems to do some of the lifting, but I'd like some advice if I want to have both of my constraints. -- ⨽ Lawrence Bottorff Grand Marais, MN, USA borgauf at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Fri Jun 4 15:58:51 2021 From: fa-ml at ariis.it (Francesco Ariis) Date: Fri, 4 Jun 2021 17:58:51 +0200 Subject: [Haskell-beginners] Data constraint? In-Reply-To: References: Message-ID: <20210604155851.GA29481@extensa> Il 03 giugno 2021 alle 17:40 Galaxy Being ha scritto: > If I have a type > > type WaterChem = CaHardness NaturalChem | Alkalinity NaturalChem > > and I want to have the values of CaHardness and Alkalinity constrained to > positive Int and between certain high and low values, I could do a newtype to > creater a NaturalChem number, thus never less than 0, but what is the best > practice to insure these values are between a certain range? Types in > Haskell can't go that far, can they? Reading this Mhhh you could create a smart constructor data Prova = ProvConst Int -- ProvConst does not get exported. mkProva :: Int -> Prova -- This does get exported. mkProva i | i > 100 = 100 -- or error "… ⁝ In a «Parse, don’t validate» [1] fashion. If you need (as I suspect) to operate on those values, you will need to define a few typeclasses (`numbers` [2] is a good example from Hackage). Would that do? —F [1] https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ [2] https://hackage.haskell.org/package/numbers-3000.2.0.2/docs/Data-Number-Natural.html From borgauf at gmail.com Fri Jun 4 16:13:33 2021 From: borgauf at gmail.com (Galaxy Being) Date: Fri, 4 Jun 2021 11:13:33 -0500 Subject: [Haskell-beginners] Data constraint? In-Reply-To: <20210604155851.GA29481@extensa> References: <20210604155851.GA29481@extensa> Message-ID: Yes, I just discovered the HaskellWiki article on smart constructors! Will give it a try. On Fri, Jun 4, 2021, 11:01 AM Francesco Ariis wrote: > Il 03 giugno 2021 alle 17:40 Galaxy Being ha scritto: > > If I have a type > > > > type WaterChem = CaHardness NaturalChem | Alkalinity NaturalChem > > > > and I want to have the values of CaHardness and Alkalinity constrained to > > positive Int and between certain high and low values, I could do a > newtype to > > creater a NaturalChem number, thus never less than 0, but what is the > best > > practice to insure these values are between a certain range? Types in > > Haskell can't go that far, can they? Reading this > > Mhhh you could create a smart constructor > > data Prova = ProvConst Int -- ProvConst does not get exported. > > mkProva :: Int -> Prova -- This does get exported. > mkProva i | i > 100 = 100 -- or error "… > ⁝ > > In a «Parse, don’t validate» [1] fashion. > If you need (as I suspect) to operate on those values, you will need > to define a few typeclasses (`numbers` [2] is a good example from > Hackage). > Would that do? > —F > > [1] https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ > [2] > https://hackage.haskell.org/package/numbers-3000.2.0.2/docs/Data-Number-Natural.html > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From borgauf at gmail.com Fri Jun 4 21:48:11 2021 From: borgauf at gmail.com (Galaxy Being) Date: Fri, 4 Jun 2021 16:48:11 -0500 Subject: [Haskell-beginners] import not working Message-ID: I go to a directory. I run stack install Safe I start up ghci and get the Prelude prompt. I run import Safe and I get import Safe | ^^^^^^^^^^^ Failed, no modules loaded. I'm once again frustrated. I try to load this hs file {-# LANGUAGE ViewPatterns #-} {-# LANGUAGE NoMonomorphismRestriction #-} import Safe lookupDefault :: Eq a => a -> b -> [(a,b)] -> b lookupDefault k _ (lookup k -> Just s) = s lookupDefault _ d _ = d headTup :: (a, [t]) -> [t] headTup (headMay . snd -> Just n) = [n] headTup _ = [] headNil :: [a] -> [a] headNil (headMay -> Just x) = [x] headNil _ = [] with the same result. What do I need to do? -- ⨽ Lawrence Bottorff Grand Marais, MN, USA borgauf at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jesse.rudel at gmail.com Fri Jun 4 22:18:27 2021 From: jesse.rudel at gmail.com (Jesse Rudel) Date: Fri, 4 Jun 2021 22:18:27 +0000 Subject: [Haskell-beginners] import not working In-Reply-To: References: Message-ID: How are you invoking ghci? If it's a stack project you can try stack ghci if you haven't already. On Fri, 4 Jun 2021 at 21:51, Galaxy Being wrote: > I go to a directory. I run > > stack install Safe > > I start up ghci and get the Prelude prompt. I run > > import Safe > > and I get > > import Safe > | ^^^^^^^^^^^ > Failed, no modules loaded. > > I'm once again frustrated. I try to load this hs file > > {-# LANGUAGE ViewPatterns #-} > {-# LANGUAGE NoMonomorphismRestriction #-} > > import Safe > > lookupDefault :: Eq a => a -> b -> [(a,b)] -> b > lookupDefault k _ (lookup k -> Just s) = s > lookupDefault _ d _ = d > > headTup :: (a, [t]) -> [t] > headTup (headMay . snd -> Just n) = [n] > headTup _ = [] > > headNil :: [a] -> [a] > headNil (headMay -> Just x) = [x] > headNil _ = [] > > with the same result. What do I need to do? > -- > ⨽ > Lawrence Bottorff > Grand Marais, MN, USA > borgauf at gmail.com > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From borgauf at gmail.com Sat Jun 5 03:47:57 2021 From: borgauf at gmail.com (Galaxy Being) Date: Fri, 4 Jun 2021 22:47:57 -0500 Subject: [Haskell-beginners] import not working In-Reply-To: References: Message-ID: I run ghci with > stack ghci On Fri, Jun 4, 2021 at 5:19 PM Jesse Rudel wrote: > How are you invoking ghci? If it's a stack project you can try stack ghci > if you haven't already. > > On Fri, 4 Jun 2021 at 21:51, Galaxy Being wrote: > >> I go to a directory. I run >> >> stack install Safe >> >> I start up ghci and get the Prelude prompt. I run >> >> import Safe >> >> and I get >> >> import Safe >> | ^^^^^^^^^^^ >> Failed, no modules loaded. >> >> I'm once again frustrated. I try to load this hs file >> >> {-# LANGUAGE ViewPatterns #-} >> {-# LANGUAGE NoMonomorphismRestriction #-} >> >> import Safe >> >> lookupDefault :: Eq a => a -> b -> [(a,b)] -> b >> lookupDefault k _ (lookup k -> Just s) = s >> lookupDefault _ d _ = d >> >> headTup :: (a, [t]) -> [t] >> headTup (headMay . snd -> Just n) = [n] >> headTup _ = [] >> >> headNil :: [a] -> [a] >> headNil (headMay -> Just x) = [x] >> headNil _ = [] >> >> with the same result. What do I need to do? >> -- >> ⨽ >> Lawrence Bottorff >> Grand Marais, MN, USA >> borgauf at gmail.com >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- ⨽ Lawrence Bottorff Grand Marais, MN, USA borgauf at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Sat Jun 5 10:48:05 2021 From: toad3k at gmail.com (David McBride) Date: Sat, 5 Jun 2021 06:48:05 -0400 Subject: [Haskell-beginners] import not working Message-ID: Spam detection software, running on the system "mail.haskell.org", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: safe is a non core package. You will have to install it by using the command stack exec --package safe ghci You can do that with multiple packages. And I believe you can write a shebang at the top of you're script so that these packages are installed automatically when you run the script. [...] Content analysis details: (5.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (toad3k[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 5.0 UNWANTED_LANGUAGE_BODY BODY: Message written in an undesired language -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 HTML_MESSAGE BODY: HTML included in message 0.0 T_DKIM_INVALID DKIM-Signature header exists but is not valid 1.9 FREEMAIL_REPLY From and body contain different freemails The original message was not completely plain text, and may be unsafe to open with some email clients; in particular, it may contain a virus, or confirm that your address can receive spam. If you wish to view it, it may be safer to save it to a file and open it with an editor. -------------- next part -------------- An embedded message was scrubbed... From: David McBride Subject: Re: [Haskell-beginners] import not working Date: Sat, 5 Jun 2021 06:48:05 -0400 Size: 9743 URL: From borgauf at gmail.com Sat Jun 5 22:23:32 2021 From: borgauf at gmail.com (Galaxy Being) Date: Sat, 5 Jun 2021 17:23:32 -0500 Subject: [Haskell-beginners] import not working In-Reply-To: References: Message-ID: Let me reiterate, I'm not creating a stack project formally. I'm just going to some directory at the command prompt and firing up ghci, which I presume just uses the global installs. Then I'm creating .hs files in a text editor and trying to load them at the REPL. How can I install stuff in this instance? On Fri, Jun 4, 2021 at 10:47 PM Galaxy Being wrote: > I run ghci with > > > stack ghci > > > > On Fri, Jun 4, 2021 at 5:19 PM Jesse Rudel wrote: > >> How are you invoking ghci? If it's a stack project you can try stack ghci >> if you haven't already. >> >> On Fri, 4 Jun 2021 at 21:51, Galaxy Being wrote: >> >>> I go to a directory. I run >>> >>> stack install Safe >>> >>> I start up ghci and get the Prelude prompt. I run >>> >>> import Safe >>> >>> and I get >>> >>> import Safe >>> | ^^^^^^^^^^^ >>> Failed, no modules loaded. >>> >>> I'm once again frustrated. I try to load this hs file >>> >>> {-# LANGUAGE ViewPatterns #-} >>> {-# LANGUAGE NoMonomorphismRestriction #-} >>> >>> import Safe >>> >>> lookupDefault :: Eq a => a -> b -> [(a,b)] -> b >>> lookupDefault k _ (lookup k -> Just s) = s >>> lookupDefault _ d _ = d >>> >>> headTup :: (a, [t]) -> [t] >>> headTup (headMay . snd -> Just n) = [n] >>> headTup _ = [] >>> >>> headNil :: [a] -> [a] >>> headNil (headMay -> Just x) = [x] >>> headNil _ = [] >>> >>> with the same result. What do I need to do? >>> -- >>> ⨽ >>> Lawrence Bottorff >>> Grand Marais, MN, USA >>> borgauf at gmail.com >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > -- > ⨽ > Lawrence Bottorff > Grand Marais, MN, USA > borgauf at gmail.com > -- ⨽ Lawrence Bottorff Grand Marais, MN, USA borgauf at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From travis.cardwell at extrema.is Sun Jun 6 00:32:25 2021 From: travis.cardwell at extrema.is (Travis Cardwell) Date: Sun, 6 Jun 2021 09:32:25 +0900 Subject: [Haskell-beginners] import not working In-Reply-To: References: Message-ID: The `stack ghci` command does not load extra packages such as those installed "globally." This is a good thing, IMHO. You can instruct the command to load specific packages using the `--package` option. Example: stack repl --package safe Example using your file: stack repl --package safe GalaxyBeing.hs Note that your email indicates usage of the `Safe` package (uppercase), but that package is deprecated in favor of the `safe` package (lowercase). I mention it in case it is not intentional. * * You may want to create a project that is just for testing. You can then specify which Stack snapshot to use in `stack.yaml` and which packages to use in `package.yaml`. stack new experiment Travis From michael.eugene.turner at gmail.com Sun Jun 6 01:50:08 2021 From: michael.eugene.turner at gmail.com (Michael Turner) Date: Sun, 6 Jun 2021 10:50:08 +0900 Subject: [Haskell-beginners] Better intro to the All About Monads tutorial? Message-ID: I've done some work on this page: https://wiki.haskell.org/All_About_Monads I could use some help in improving my improvements 1. Beginners -- if you haven't looked at monads yet, does this new intro boost your confidence? 2. Those who help beginners here -- have I committed any technical errors? I was a little frustrated about the text as it stood. For example: "... a monad is a way to structure computations in terms of values and sequences of computations using typed values. Monads allow the programmer to build up computations using sequential building blocks, which can themselves be sequences of computations. The monad determines how combined computations form a new computation and frees the programmer from having to code the combination manually each time it is required." The problem with this was that you could substitute "compiler" or "C++ class" and it would be not much less true and not much more uninformative. The approach I took to rewriting (aside from where I take the reader's hand gently at the beginning) was to try to anchor the treatment more in concepts that the reader might already understand. The two main concepts were were pipelines (as in shell programming) and "cross-cutting concerns" (with links to Wikipedia articles for readers who might not know one or the other or both.) I've left almost all of the original wording intact and just wrote around it. Perhaps it could be trimmed, maybe even a lot. I don't understand monads well enough to write one myself yet. But I think a newbie perspective can help in writing for newbies: unlike the expert, the sources of confusion and incomprehension are fresh in your mind, as are the ways you got past them. Regards, Michael Turner Executive Director Project Persephone 1-25-33 Takadanobaba Shinjuku-ku Tokyo 169-0075 Mobile: +81 (90) 5203-8682 turner at projectpersephone.org Understand - http://www.projectpersephone.org/ Join - http://www.facebook.com/groups/ProjectPersephone/ Donate - http://www.patreon.com/ProjectPersephone Volunteer - https://github.com/ProjectPersephone "Love does not consist in gazing at each other, but in looking outward together in the same direction." -- Antoine de Saint-Exupéry From Leonhard.Applis at protonmail.com Mon Jun 7 05:32:07 2021 From: Leonhard.Applis at protonmail.com (Leonhard Applis) Date: Mon, 07 Jun 2021 05:32:07 +0000 Subject: [Haskell-beginners] Designing TimeOut for Search Algorithm Message-ID: Good Morning,  I currently want to write a search algorithm with 3 end conditions: a) Solution Found  b) N-iterations done  c) x minutes timeout I would like to split the function in two pieces, one which is pure with a seed and no timeout, and one time-outed in a monad (IO?). So  pureSearch :: Seed -> Iterations -> Maybe Result  and  search :: Timeout -> Seed -> Iterations -> IO Maybe Result Is this a known Pattern?  Do you know good examples for this behavior?  Any other recommendations before I start implementing?  Best Leonhard   -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 509 bytes Desc: OpenPGP digital signature URL: From velichko.lefterov at gmail.com Thu Jun 10 11:15:51 2021 From: velichko.lefterov at gmail.com (Velichko Lefterov) Date: Thu, 10 Jun 2021 14:15:51 +0300 Subject: [Haskell-beginners] DataKinds and GADTs question? Message-ID: I tried to understand DataKinds and GADTs... Is there a difference between: data MyType :: Type -> Type where MyTypeConstructor :: Int -> MyType Int data MyType2 a where MyTypeConstructor2 :: Int -> MyType2 Int -------------- next part -------------- An HTML attachment was scrubbed... URL: From coot at coot.me Sat Jun 12 11:13:01 2021 From: coot at coot.me (coot at coot.me) Date: Sat, 12 Jun 2021 11:13:01 +0000 Subject: [Haskell-beginners] DataKinds and GADTs question? In-Reply-To: References: Message-ID: There isn't. GHC will infer kind `Type -> Type` for `MyType2`.  You can check that in `ghci` with `:kind MyType` and `:kind MyType2`.  There's also third way to write it by adding a standalone kind signature: ``` {-# LANGUAGE StandalondKindSignatures, GADTs #-} type MyType3 :: Type -> Type data MyType3 a where   MkT3 :: Int -> MyType3 Int ``` A polykinded version would look like this: ``` {-# LANGUAGE PolyKinds #-} type MyType4 :: forall a -> Type data MyType4 a where   MkT3 :: MyType4 Int ``` in `ghci` the kind of `MyType4` is: ``` :kind MyType4 MyType4 :: forall k. forall (a :: k) -> Type ``` Best regards, Marcin Sent with ProtonMail Secure Email. ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Thursday, June 10th, 2021 at 13:15, Velichko Lefterov wrote: > I tried to understand DataKinds and GADTs...Is there a difference between: > > data MyType :: Type -> Type where > >   MyTypeConstructor :: Int -> MyType Int > > data MyType2 a where > >   MyTypeConstructor2 :: Int -> MyType2 Int -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 509 bytes Desc: OpenPGP digital signature URL: From michael.eugene.turner at gmail.com Thu Jun 24 03:41:58 2021 From: michael.eugene.turner at gmail.com (Michael Turner) Date: Thu, 24 Jun 2021 12:41:58 +0900 Subject: [Haskell-beginners] A one- or two-page diagram of how Haskell works? Message-ID: When I write C, or even C++, I have a mental model of how execution will proceed. When I write Prolog, but get confused, I run a kind of skeletal inference algorithm in my head and the confusion usually clears up. I can imagine how things are stored and what's done with them. I can see /through/ the code to the machine. With Haskell, I still feel blind. Has anyone summarized it all in a chart where I can look at it and think, "Ah, OK, GHC is taking this line and thinking of it THIS way"? If someone wanted to write an interpreter for Haskell, would there be a way for them to see how it would basically need to work, in one chart? Regards, Michael Turner Executive Director Project Persephone 1-25-33 Takadanobaba Shinjuku-ku Tokyo 169-0075 Mobile: +81 (90) 5203-8682 turner at projectpersephone.org Understand - http://www.projectpersephone.org/ Join - http://www.facebook.com/groups/ProjectPersephone/ Donate - http://www.patreon.com/ProjectPersephone Volunteer - https://github.com/ProjectPersephone "Love does not consist in gazing at each other, but in looking outward together in the same direction." -- Antoine de Saint-Exupéry From leiva.steven at gmail.com Thu Jun 24 13:43:10 2021 From: leiva.steven at gmail.com (Steven Leiva) Date: Thu, 24 Jun 2021 09:43:10 -0400 Subject: [Haskell-beginners] A one- or two-page diagram of how Haskell works? In-Reply-To: References: Message-ID: Wonderful question. I would love to see something like this too. What kind of confusion are you running into with Haskell? Are they of the type error variety, or do you have a well-typed program that doesn't do what you want? *If* it is the type error stuff, I would recommend that you give the compiler information about what you think the types are. The reason is that type information can flow from very far away places than where you are getting an error. For example, I was writing this code the other day: *for eIdpData \ $(schoolId, districtId, tenantId) -> pure $ Right 1* The type of for is *for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b)* In my case, I knew the following: *t ~ Either SyncFailure* *a ~ IdpData* *f ~ WriterT Logs m* *b ~ Int* Once I do replace type variables with concrete types / type constructors, it becomes clear that my function argument should return an *Int* in some structure, and instead I am returning an *Either a Int*. This helps me figure out the problem. Writing out takes a lot longer than actually doing it. Anyway, the key is to provide GHC with the information you think you know; this will prevent type inference from allowing type information to flow from far away places, and the error will become clearer or at the very least more localized. On Wed, Jun 23, 2021 at 11:42 PM Michael Turner < michael.eugene.turner at gmail.com> wrote: > When I write C, or even C++, I have a mental model of how execution > will proceed. > > When I write Prolog, but get confused, I run a kind of skeletal > inference algorithm in my head and the confusion usually clears up. I > can imagine how things are stored and what's done with them. I can see > /through/ the code to the machine. > > With Haskell, I still feel blind. > > Has anyone summarized it all in a chart where I can look at it and > think, "Ah, OK, GHC is taking this line and thinking of it THIS way"? > If someone wanted to write an interpreter for Haskell, would there be > a way for them to see how it would basically need to work, in one > chart? > > Regards, > Michael Turner > Executive Director > Project Persephone > 1-25-33 Takadanobaba > Shinjuku-ku Tokyo 169-0075 > Mobile: +81 (90) 5203-8682 > turner at projectpersephone.org > > Understand - http://www.projectpersephone.org/ > Join - http://www.facebook.com/groups/ProjectPersephone/ > Donate - http://www.patreon.com/ProjectPersephone > Volunteer - https://github.com/ProjectPersephone > > "Love does not consist in gazing at each other, but in looking outward > together in the same direction." -- Antoine de Saint-Exupéry > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Steven Leiva 305.528.6038 leiva.steven at gmail.com http://www.linkedin.com/in/stevenleiva -------------- next part -------------- An HTML attachment was scrubbed... URL: From leiva.steven at gmail.com Thu Jun 24 13:45:27 2021 From: leiva.steven at gmail.com (Steven Leiva) Date: Thu, 24 Jun 2021 09:45:27 -0400 Subject: [Haskell-beginners] A one- or two-page diagram of how Haskell works? In-Reply-To: References: Message-ID: A few caveats to the above: 1) The literal *1* is polymorphic, but I hand-waved over that for now 2) *Either e Int* is an *Int* in *some* structure, but it's not the structure we want. In the type signature for *for*, the function argument does not contain the *t* type variable at all, which, again, is in our case *t ~ Either SyncFailure*. On Thu, Jun 24, 2021 at 9:43 AM Steven Leiva wrote: > Wonderful question. I would love to see something like this too. > > What kind of confusion are you running into with Haskell? Are they of the > type error variety, or do you have a well-typed program that doesn't do > what you want? > > *If* it is the type error stuff, I would recommend that you give the > compiler information about what you think the types are. The reason is that > type information can flow from very far away places than where you are > getting an error. For example, I was writing this code the other day: > > *for eIdpData \ $(schoolId, districtId, tenantId) -> pure $ Right 1* > > The type of for is *for :: (Traversable t, Applicative f) => t a -> (a -> > f b) -> f (t b)* > > In my case, I knew the following: > > *t ~ Either SyncFailure* > *a ~ IdpData* > *f ~ WriterT Logs m* > *b ~ Int* > > Once I do replace type variables with concrete types / type constructors, > it becomes clear that my function argument should return an *Int* in some > structure, and instead I am returning an *Either a Int*. This helps me > figure out the problem. > > Writing out takes a lot longer than actually doing it. Anyway, the key is > to provide GHC with the information you think you know; this will prevent > type inference from allowing type information to flow from far away places, > and the error will become clearer or at the very least more localized. > > On Wed, Jun 23, 2021 at 11:42 PM Michael Turner < > michael.eugene.turner at gmail.com> wrote: > >> When I write C, or even C++, I have a mental model of how execution >> will proceed. >> >> When I write Prolog, but get confused, I run a kind of skeletal >> inference algorithm in my head and the confusion usually clears up. I >> can imagine how things are stored and what's done with them. I can see >> /through/ the code to the machine. >> >> With Haskell, I still feel blind. >> >> Has anyone summarized it all in a chart where I can look at it and >> think, "Ah, OK, GHC is taking this line and thinking of it THIS way"? >> If someone wanted to write an interpreter for Haskell, would there be >> a way for them to see how it would basically need to work, in one >> chart? >> >> Regards, >> Michael Turner >> Executive Director >> Project Persephone >> 1-25-33 Takadanobaba >> Shinjuku-ku Tokyo 169-0075 >> Mobile: +81 (90) 5203-8682 >> turner at projectpersephone.org >> >> Understand - http://www.projectpersephone.org/ >> Join - http://www.facebook.com/groups/ProjectPersephone/ >> Donate - http://www.patreon.com/ProjectPersephone >> Volunteer - https://github.com/ProjectPersephone >> >> "Love does not consist in gazing at each other, but in looking outward >> together in the same direction." -- Antoine de Saint-Exupéry >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > -- > Steven Leiva > 305.528.6038 > leiva.steven at gmail.com > http://www.linkedin.com/in/stevenleiva > -- Steven Leiva 305.528.6038 leiva.steven at gmail.com http://www.linkedin.com/in/stevenleiva -------------- next part -------------- An HTML attachment was scrubbed... URL: From tozkanli2023 at gmail.com Thu Jun 24 14:10:48 2021 From: tozkanli2023 at gmail.com (=?UTF-8?Q?Tarik_=C3=96ZKANLI?=) Date: Thu, 24 Jun 2021 17:10:48 +0300 Subject: [Haskell-beginners] A one- or two-page diagram of how Haskell works? In-Reply-To: References: Message-ID: It's better to try to model execution using lambda calculus. The most dominant factor in languages like Haskell is lambda calculus. Think through lambda calculus for a mental model. On Thu, 24 Jun 2021 at 16:45, Steven Leiva wrote: > Wonderful question. I would love to see something like this too. > > What kind of confusion are you running into with Haskell? Are they of the > type error variety, or do you have a well-typed program that doesn't do > what you want? > > *If* it is the type error stuff, I would recommend that you give the > compiler information about what you think the types are. The reason is that > type information can flow from very far away places than where you are > getting an error. For example, I was writing this code the other day: > > *for eIdpData \ $(schoolId, districtId, tenantId) -> pure $ Right 1* > > The type of for is *for :: (Traversable t, Applicative f) => t a -> (a -> > f b) -> f (t b)* > > In my case, I knew the following: > > *t ~ Either SyncFailure* > *a ~ IdpData* > *f ~ WriterT Logs m* > *b ~ Int* > > Once I do replace type variables with concrete types / type constructors, > it becomes clear that my function argument should return an *Int* in some > structure, and instead I am returning an *Either a Int*. This helps me > figure out the problem. > > Writing out takes a lot longer than actually doing it. Anyway, the key is > to provide GHC with the information you think you know; this will prevent > type inference from allowing type information to flow from far away places, > and the error will become clearer or at the very least more localized. > > On Wed, Jun 23, 2021 at 11:42 PM Michael Turner < > michael.eugene.turner at gmail.com> wrote: > >> When I write C, or even C++, I have a mental model of how execution >> will proceed. >> >> When I write Prolog, but get confused, I run a kind of skeletal >> inference algorithm in my head and the confusion usually clears up. I >> can imagine how things are stored and what's done with them. I can see >> /through/ the code to the machine. >> >> With Haskell, I still feel blind. >> >> Has anyone summarized it all in a chart where I can look at it and >> think, "Ah, OK, GHC is taking this line and thinking of it THIS way"? >> If someone wanted to write an interpreter for Haskell, would there be >> a way for them to see how it would basically need to work, in one >> chart? >> >> Regards, >> Michael Turner >> Executive Director >> Project Persephone >> 1-25-33 Takadanobaba >> Shinjuku-ku Tokyo 169-0075 >> Mobile: +81 (90) 5203-8682 >> turner at projectpersephone.org >> >> Understand - http://www.projectpersephone.org/ >> Join - http://www.facebook.com/groups/ProjectPersephone/ >> Donate - http://www.patreon.com/ProjectPersephone >> Volunteer - https://github.com/ProjectPersephone >> >> "Love does not consist in gazing at each other, but in looking outward >> together in the same direction." -- Antoine de Saint-Exupéry >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > -- > Steven Leiva > 305.528.6038 > leiva.steven at gmail.com > http://www.linkedin.com/in/stevenleiva > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sgf.dma at gmail.com Mon Jun 28 15:37:07 2021 From: sgf.dma at gmail.com (Dmitriy Matrosov) Date: Mon, 28 Jun 2021 18:37:07 +0300 Subject: [Haskell-beginners] Partial results with megaparsec Message-ID: <1570a77d-1f0f-86cf-25a6-cda2964883a8@gmail.com> Hi. I've used attoparsec before and it can return 'Partial' result containing continuation, which is able to continue parsing if provided with more input. E.g. > let A.Partial c1 = A.parse (A.string "mac address") "mac "; in c1 "address" Done "" "mac address" Does the same thing possible with megaparsec? After looking through library API, i haven't find a way to do this. 'runParser' (which seems the only way to run megaparsec parser) fails on incomplete (text) input. And if that's not possible, how should i deal with chunked input? E.g. i read from a socket with 'recv' and i don't want to read all data at once. How can i suspend parsing for a time, read next chunk and continue? Thanks. From toad3k at gmail.com Mon Jun 28 16:46:16 2021 From: toad3k at gmail.com (David McBride) Date: Mon, 28 Jun 2021 12:46:16 -0400 Subject: [Haskell-beginners] Partial results with megaparsec In-Reply-To: <1570a77d-1f0f-86cf-25a6-cda2964883a8@gmail.com> References: <1570a77d-1f0f-86cf-25a6-cda2964883a8@gmail.com> Message-ID: Attoparsec was created specifically for streaming, thus its parsing functions take into account that some portion of the pattern may yet to have arrived and its combinators avoid taking input greedily unintentionally. It is not clear to me that megaparsec is capable of that. There is a package attoparsec-parsec package, which reimplements parsec's combinators in a way attoparsec can use, but I do not see a version of that for megaparsec. You would have to write every megaparsec combinator into an equivalent attoparsec to create such a package. On Mon, Jun 28, 2021 at 11:37 AM Dmitriy Matrosov wrote: > Hi. > > I've used attoparsec before and it can return 'Partial' result containing > continuation, which is able to continue parsing if provided with more > input. > E.g. > > > let A.Partial c1 = A.parse (A.string "mac address") "mac "; in c1 > "address" > Done "" "mac address" > > Does the same thing possible with megaparsec? > > After looking through library API, i haven't find a way to do this. > 'runParser' (which seems the only way to run megaparsec parser) fails on > incomplete (text) input. > > And if that's not possible, how should i deal with chunked input? > E.g. i read from a socket with 'recv' and i don't want to read all > data at once. How can i suspend parsing for a time, read next chunk and > continue? > > Thanks. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From borgauf at gmail.com Wed Jun 30 04:57:41 2021 From: borgauf at gmail.com (Galaxy Being) Date: Tue, 29 Jun 2021 23:57:41 -0500 Subject: [Haskell-beginners] Simple data type for dates? Message-ID: I've looked at Data.Time, but I'm not seeing examples. I'd like to figure out how to simply have use of similar to this: type MyMonth = String type MyDay = String type MyYear = String data MyDate = MyDate MyMonth MyDay MyYear deriving Show storeDate :: MyDate storeDate = "June" "29" "2021" which will be in a bigger data structure I'm building. I can't believe this isn't reinventing some long-established wheel. Is there such a type ready to use? ⨽ Lawrence Bottorff Grand Marais, MN, USA borgauf at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From mlow at ualberta.ca Wed Jun 30 05:31:47 2021 From: mlow at ualberta.ca (Matthew Low) Date: Tue, 29 Jun 2021 23:31:47 -0600 Subject: [Haskell-beginners] Simple data type for dates? In-Reply-To: References: Message-ID: The `time` package equivalent of `MyDate` would be `Day`: storeDate :: Day storeDate = fromGregorian 2021 6 29 > storeDate 2021-06-29 > toGregorian storeDate (2021,6,29) > dayOfWeek storeDate Tuesday However, I don't see any easy conversion between the numeric month and its English name. On Tue, Jun 29, 2021 at 10:58 PM Galaxy Being wrote: > I've looked at Data.Time, but I'm not seeing examples. I'd like to figure > out how to simply have use of similar to this: > > type MyMonth = String > type MyDay = String > type MyYear = String > data MyDate = MyDate MyMonth MyDay MyYear deriving Show > > storeDate :: MyDate > storeDate = "June" "29" "2021" > > which will be in a bigger data structure I'm building. I can't believe > this isn't reinventing some long-established wheel. Is there such a type > ready to use? > > ⨽ > Lawrence Bottorff > Grand Marais, MN, USA > borgauf at gmail.com > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: