From trent.shipley at gmail.com Sat Mar 3 06:24:28 2018 From: trent.shipley at gmail.com (trent shipley) Date: Fri, 2 Mar 2018 23:24:28 -0700 Subject: [Haskell-beginners] Overload ^ Message-ID: {- I want to override Prelude.^ (as an academic exercise). Can it be done? How? Trent -} (^) :: Int -> Int -> Int m ^ 0 = 1 m ^ n = m * (m ^ (n-1)) {- Hutton, Graham. Programming in Haskell (p. 263). Cambridge University Press. Kindle Edition. 2016. -} {- Result [1 of 1] Compiling Main ( ex6_3b.hs, interpreted ) ex6_3b.hs:3:16: error: Ambiguous occurrence ‘^’ It could refer to either ‘Prelude.^’, imported from ‘Prelude’ at ex6_3b.hs:1:1 (and originally defined in ‘GHC.Real’) or ‘Main.^’, defined at ex6_3b.hs:2:3 | 3 | m ^ n = m * (m ^ (n-1)) | ^ Failed, no modules loaded. -} -- So I try (^) :: Int -> Int -> Int m Main.^ 0 = 1 m Main.^ n = m * (m Main.^ (n-1)) {- Result Prelude> :reload ex6_3b.hs:2:3: error: Qualified name in binding position: Main.^ | 2 | m Main.^ 0 = 1 | ^^^^^^ [1 of 1] Compiling Main ( ex6_3b.hs, interpreted ) Failed, no modules loaded. -} -------------- next part -------------- An HTML attachment was scrubbed... URL: From aquagnu at gmail.com Sat Mar 3 06:33:11 2018 From: aquagnu at gmail.com (Paul) Date: Sat, 3 Mar 2018 08:33:11 +0200 Subject: [Haskell-beginners] Overload ^ In-Reply-To: References: Message-ID: <5a9a41a5.5198df0a.8d5ff.500b@mx.google.com> import Prelude hiding ((^)) See here: https://wiki.haskell.org/Import Best regards, Paul От: trent shipley Отправлено: 3 марта 2018 г. в 8:25 Кому: beginners at haskell.org Тема: [Haskell-beginners] Overload ^ {- I want to override Prelude.^ (as an academic exercise). Can it be done? How? Trent -} (^) :: Int -> Int -> Int m ^ 0 = 1  m ^ n = m * (m ^ (n-1)) {- Hutton, Graham. Programming in Haskell (p. 263). Cambridge University Press. Kindle Edition. 2016. -} {- Result [1 of 1] Compiling Main             ( ex6_3b.hs, interpreted ) ex6_3b.hs:3:16: error:     Ambiguous occurrence ‘^’     It could refer to either ‘Prelude.^’,                              imported from ‘Prelude’ at ex6_3b.hs:1:1                              (and originally defined in ‘GHC.Real’)                           or ‘Main.^’, defined at ex6_3b.hs:2:3   | 3 | m ^ n = m * (m ^ (n-1))   |                ^ Failed, no modules loaded. -} -- So I try (^) :: Int -> Int -> Int m Main.^ 0 = 1  m Main.^ n = m * (m Main.^ (n-1)) {- Result Prelude> :reload ex6_3b.hs:2:3: error: Qualified name in binding position: Main.^   | 2 | m Main.^ 0 = 1    |   ^^^^^^ [1 of 1] Compiling Main             ( ex6_3b.hs, interpreted ) Failed, no modules loaded. -} -------------- next part -------------- An HTML attachment was scrubbed... URL: From hilco.wijbenga at gmail.com Sat Mar 3 20:32:34 2018 From: hilco.wijbenga at gmail.com (Hilco Wijbenga) Date: Sat, 3 Mar 2018 12:32:34 -0800 Subject: [Haskell-beginners] Functor instance Message-ID: Hi all, I'm trying to implement my own Result type (and yes, I'm aware you can abuse Either for this :-) ) but doing something as (seemingly?) simple as implementing a Functor instance was surprisingly difficult. data Result failure success = Success success | Failure failure instance Functor (Result failure) where fmap f (Success value) = Success (f value) fmap _ (Failure error) = Failure error -- fmap _ result@(Failure error) = result -- fmap _ result = result 1) Is it possible to define "Result" as "Result success failure" (instead of "Result failure success") and _still_ create an instance of Functor? 2) The two alternatives for fmap for the Failure scenario do not compile (the end result is "Result failure a" instead of "Result failure b") and that makes sense. But I would like to be able to express that "result" is not touched. Is there any way to do that? 3) And while wondering about that, is GHC smart enough to realize that "= Failure error" in the failure scenario is actually a NOP? (I'm just curious.) Cheers, Hilco From fa-ml at ariis.it Sat Mar 3 21:40:43 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 3 Mar 2018 22:40:43 +0100 Subject: [Haskell-beginners] Functor instance In-Reply-To: References: Message-ID: <20180303214043.opqhfunzns2o4bks@x60s.casa> Hello Hilco, On Sat, Mar 03, 2018 at 12:32:34PM -0800, Hilco Wijbenga wrote: > data Result failure success > = Success success > | Failure failure > > instance Functor (Result failure) where > fmap f (Success value) = Success (f value) > fmap _ (Failure error) = Failure error > -- fmap _ result@(Failure error) = result > -- fmap _ result = result > > 1) Is it possible to define "Result" as "Result success failure" > (instead of "Result failure success") and _still_ create an instance > of Functor? Yes, as far the compiler is concerned `data Result failure success` is equivalent to `data Result a b`. Same in your instance, you could have written: instance Functor (Result a) where -- etc. no problem. > 2) The two alternatives for fmap for the Failure scenario do not > compile (the end result is "Result failure a" instead of "Result > failure b") and that makes sense. But I would like to be able to > express that "result" is not touched. Is there any way to do that? You can but you have to modify your datatype! Probably you want something like this: data Result r f = Result r (ResState e) data ResState e = Ok | Error e > 3) And while wondering about that, is GHC smart enough to realize that > "= Failure error" in the failure scenario is actually a NOP? (I'm just > curious.) Not sure about this one, but I strongly suspect so! Was the explanation clear? -F From hilco.wijbenga at gmail.com Sun Mar 4 02:31:47 2018 From: hilco.wijbenga at gmail.com (Hilco Wijbenga) Date: Sat, 3 Mar 2018 18:31:47 -0800 Subject: [Haskell-beginners] Functor instance In-Reply-To: <20180303214043.opqhfunzns2o4bks@x60s.casa> References: <20180303214043.opqhfunzns2o4bks@x60s.casa> Message-ID: On Sat, Mar 3, 2018 at 1:40 PM, Francesco Ariis wrote: > On Sat, Mar 03, 2018 at 12:32:34PM -0800, Hilco Wijbenga wrote: >> data Result failure success >> = Success success >> | Failure failure >> >> instance Functor (Result failure) where >> fmap f (Success value) = Success (f value) >> fmap _ (Failure error) = Failure error >> -- fmap _ result@(Failure error) = result >> -- fmap _ result = result >> >> 1) Is it possible to define "Result" as "Result success failure" >> (instead of "Result failure success") and _still_ create an instance >> of Functor? > > Yes, as far the compiler is concerned `data Result failure success` > is equivalent to `data Result a b`. Same in your instance, you could > have written: > > instance Functor (Result a) where > -- etc. > > no problem. But now "a" has a different meaning, doesn't it? I had the impression that the "Result a" was similar to currying or leaving a hole (something like " Result a * " but if I change the meaning of "a" from "failure" to "success" then things don't work anymore, do they? In any case, _when_ I flip "success" and "failure" the Functor instance no longer compiles. Which probably makes sense because I did not tell the compiler to interpret "Result failure" as "Result * failure"? >> 2) The two alternatives for fmap for the Failure scenario do not >> compile (the end result is "Result failure a" instead of "Result >> failure b") and that makes sense. But I would like to be able to >> express that "result" is not touched. Is there any way to do that? > > You can but you have to modify your datatype! Probably you want > something like this: > > data Result r f = Result r (ResState e) > data ResState e = Ok | Error e Ah, I see. Mmm, I'll have to think about that. I prefer the current setup. :-) From fa-ml at ariis.it Sun Mar 4 02:41:39 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 4 Mar 2018 03:41:39 +0100 Subject: [Haskell-beginners] Functor instance In-Reply-To: References: <20180303214043.opqhfunzns2o4bks@x60s.casa> Message-ID: <20180304024139.6jqwvamnak5qn7dm@x60s.casa> On Sat, Mar 03, 2018 at 06:31:47PM -0800, Hilco Wijbenga wrote: > In any case, _when_ I flip "success" and "failure" the Functor > instance no longer compiles. Which probably makes sense because I did > not tell the compiler to interpret "Result failure" as "Result * > failure"? I wonder if you are talking about failure (type parameter) or Failure (data constructor). This instance obviously work instance Functor (Result success) where fmap f (Success value) = Success (f value) fmap _ (Failure error) = Failure error Flipping in `data` of course means you are to flip one of: a) instance or b) data constructor, e.g.: instance Functor (Result success) where fmap f (Failure error) = Failure (f error) fmap _ (Success value) = Success value From hilco.wijbenga at gmail.com Sun Mar 4 03:54:48 2018 From: hilco.wijbenga at gmail.com (Hilco Wijbenga) Date: Sat, 3 Mar 2018 19:54:48 -0800 Subject: [Haskell-beginners] Functor instance In-Reply-To: <20180304024139.6jqwvamnak5qn7dm@x60s.casa> References: <20180303214043.opqhfunzns2o4bks@x60s.casa> <20180304024139.6jqwvamnak5qn7dm@x60s.casa> Message-ID: On Sat, Mar 3, 2018 at 6:41 PM, Francesco Ariis wrote: > On Sat, Mar 03, 2018 at 06:31:47PM -0800, Hilco Wijbenga wrote: >> In any case, _when_ I flip "success" and "failure" the Functor >> instance no longer compiles. Which probably makes sense because I did >> not tell the compiler to interpret "Result failure" as "Result * >> failure"? > > I wonder if you are talking about failure (type parameter) or > Failure (data constructor). I believe I am talking about "failure" the type parameter. > This instance obviously work > > instance Functor (Result success) where > fmap f (Success value) = Success (f value) > fmap _ (Failure error) = Failure error > > Flipping in `data` of course means you are to flip one of: > a) instance or b) data constructor, e.g.: > > instance Functor (Result success) where > fmap f (Failure error) = Failure (f error) > fmap _ (Success value) = Success value Yes, indeed. But that's what I meant with 'now "a" has a different meaning'. I understand that to the compiler there is no practical difference between Result a b and Result b a ... but there is to me. :-) So am I to understand then that to be able to do the kind of "fmap" I want (i.e. one that affects the "success" value), I _have to_ make sure that I use "Result failure success" (and not "Result success failure")? From tanuki at gmail.com Sun Mar 4 04:10:36 2018 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Sat, 3 Mar 2018 20:10:36 -0800 Subject: [Haskell-beginners] Functor instance In-Reply-To: References: <20180303214043.opqhfunzns2o4bks@x60s.casa> <20180304024139.6jqwvamnak5qn7dm@x60s.casa> Message-ID: That is correct. You can think of type parameters as being curried and applied the same way as function parameters. Since application is strictly left to right, and we have no type-level flip function (barring newtype), getting your type down to the single parameter allowed in a Functor instance can only ever mean using the rightmost parameter in the type's definition. This is just a semantic limitation of how Haskell types are expressed. On Mar 3, 2018 7:56 PM, "Hilco Wijbenga" wrote: > On Sat, Mar 3, 2018 at 6:41 PM, Francesco Ariis wrote: > > On Sat, Mar 03, 2018 at 06:31:47PM -0800, Hilco Wijbenga wrote: > >> In any case, _when_ I flip "success" and "failure" the Functor > >> instance no longer compiles. Which probably makes sense because I did > >> not tell the compiler to interpret "Result failure" as "Result * > >> failure"? > > > > I wonder if you are talking about failure (type parameter) or > > Failure (data constructor). > > I believe I am talking about "failure" the type parameter. > > > This instance obviously work > > > > instance Functor (Result success) where > > fmap f (Success value) = Success (f value) > > fmap _ (Failure error) = Failure error > > > > Flipping in `data` of course means you are to flip one of: > > a) instance or b) data constructor, e.g.: > > > > instance Functor (Result success) where > > fmap f (Failure error) = Failure (f error) > > fmap _ (Success value) = Success value > > Yes, indeed. But that's what I meant with 'now "a" has a different > meaning'. I understand that to the compiler there is no practical > difference between Result a b and Result b a ... but there is to me. > :-) > > So am I to understand then that to be able to do the kind of "fmap" I > want (i.e. one that affects the "success" value), I _have to_ make > sure that I use "Result failure success" (and not "Result success > failure")? > _______________________________________________ > 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 sumitraja at gmail.com Sun Mar 4 07:34:27 2018 From: sumitraja at gmail.com (Sumit Raja) Date: Sun, 4 Mar 2018 18:34:27 +1100 Subject: [Haskell-beginners] Functor instance Message-ID: > I'm trying to implement my own Result type (and yes, I'm aware you can > abuse Either for this :-) ) but doing something as (seemingly?) simple > as implementing a Functor instance was surprisingly difficult. > Without knowing your final use case are Bifunctors what you are after (https://hackage.haskell.org/package/base-4.10.1.0/docs/Data-Bifunctor.html)? I used them when I wanted to fmap Left to convert errors to other errors. -Sumit From hilco.wijbenga at gmail.com Sun Mar 4 19:41:38 2018 From: hilco.wijbenga at gmail.com (Hilco Wijbenga) Date: Sun, 4 Mar 2018 11:41:38 -0800 Subject: [Haskell-beginners] Functor instance In-Reply-To: References: Message-ID: On Sat, Mar 3, 2018 at 11:34 PM, Sumit Raja wrote: >> I'm trying to implement my own Result type (and yes, I'm aware you can >> abuse Either for this :-) ) but doing something as (seemingly?) simple >> as implementing a Functor instance was surprisingly difficult. >> > Without knowing your final use case are Bifunctors what you are after > (https://hackage.haskell.org/package/base-4.10.1.0/docs/Data-Bifunctor.html)? > I used them when I wanted to fmap Left to convert errors to other > errors. No, they provide too much power. [I don't want to do anything more than die on the first error although I may add support for multiple errors later.] And I want to do this myself! No doubt, once I'm (far) more familiar with Haskell I'll be able to use things like Either and BiFunctor but right now they are just a step too far. I get lost in a forest of "weird" operators. :-) The purpose really is to work on something I fully understand (a Result type) and then see what I need to do in Haskell to support that. I just felt that the logical/intuitive type (at least to me) is "Result success failure" (it's the success value I really care about, after all) but that does not work with Functor (or Applicative, or Monad), AFAICT. So the order ("failure" first) seems to be forced on me. So be it. P.S. The second line in the Data.Bifunctor documentation made me chuckle: "Intuitively it is a bifunctor where both the first and second arguments are covariant.". Intuitive? Really? :-) ;-) From leiva.steven at gmail.com Mon Mar 5 15:38:22 2018 From: leiva.steven at gmail.com (Steven Leiva) Date: Mon, 5 Mar 2018 09:38:22 -0600 Subject: [Haskell-beginners] Functor instance In-Reply-To: References: Message-ID: Hilco, I am going to use a lot of Haskell concepts here, but I am a strong believer that using the correct terms empowers the learner to go out and continue their education on their own. *Your first question is is it possible to define Result as Result success failure and still create an instance of Functor?* The answer to that is *yes*. We can look up the definition of the *Functor typeclass* (use *:i Functor* in GHCI), and we can see the following: *class Functor (f :: * -> *) where*.... >From that definition, we can see that we can have an instance of Functor for any type that has the *kind * -> **. It seems like you are familiar with treating type constructors as functions at the type level, so what we are saying here is that in order for a type constructor to be a functor, it *has* to be a type constructor that takes *one* type constant to yield another type constant. Your type *Result* has the kind ** -> * -> **. It takes two type constants, so we know that wont "fit" into Functor, and we have to partially apply the *Result* type constructor to get another type constructor with the kind ** -> **, which can have an instance of Functor. What I think is missing from your understanding is this - if you change your data declaration to be *Result success failure*, then your instance of functor will only be able to modify the failure case. Why? Because when you write your instance of functor, it will look like this: *instance Functor (Result success) where...*. If we look at the signature of *fmap :: (a -> b) -> f a -> f b*, and then we specialize so that *f ~ Result success*, we get *fmap :: (a -> b) -> Result success a -> Result success b*. In other words, you have already baked in the first type argument to *Result* when you are writing your instance of Functor for it, and are not allowed to change it anymore. *Your second question I would like to be able to express that "result" is not touched...* I am assuming here that you are talking about this piece of code "fmap _ result@(Failure error) = result" using your original functor instance and data Result failure success... We can't express that result is not touched. Why? Because result *is* touched. It has to be. As you yourself mentioned, on the left-hand side we have a value of one type, and on the right-hand side we have a value of a different type. Even though we don't witness the change at the value level, we do have a change at the type level. So we can't express it because it is not what is happening. Now, I get what you are saying - the result on the left-hand side has the same data as the right-hand side, same data constructor, etc, but it is still not the same value. On your third question, regarding GHC being smart enough to realize a NOP, I don't know. I hope this helps! On Sat, Mar 3, 2018 at 2:32 PM, Hilco Wijbenga wrote: > Hi all, > > I'm trying to implement my own Result type (and yes, I'm aware you can > abuse Either for this :-) ) but doing something as (seemingly?) simple > as implementing a Functor instance was surprisingly difficult. > > data Result failure success > = Success success > | Failure failure > > instance Functor (Result failure) where > fmap f (Success value) = Success (f value) > fmap _ (Failure error) = Failure error > -- fmap _ result@(Failure error) = result > -- fmap _ result = result > > 1) Is it possible to define "Result" as "Result success failure" > (instead of "Result failure success") and _still_ create an instance > of Functor? > 2) The two alternatives for fmap for the Failure scenario do not > compile (the end result is "Result failure a" instead of "Result > failure b") and that makes sense. But I would like to be able to > express that "result" is not touched. Is there any way to do that? > 3) And while wondering about that, is GHC smart enough to realize that > "= Failure error" in the failure scenario is actually a NOP? (I'm just > curious.) > > Cheers, > Hilco > _______________________________________________ > 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 sylvain at haskus.fr Mon Mar 5 21:21:45 2018 From: sylvain at haskus.fr (Sylvain Henry) Date: Mon, 5 Mar 2018 22:21:45 +0100 Subject: [Haskell-beginners] Functor instance In-Reply-To: References: Message-ID: > 3) And while wondering about that, is GHC smart enough to realize that > "= Failure error" in the failure scenario is actually a NOP? (I'm just > curious.) Yes it does. The STG CSE pass handles this. Sylvain From capnoi8 at gmail.com Thu Mar 8 11:22:06 2018 From: capnoi8 at gmail.com (Ashwin Samudre) Date: Thu, 8 Mar 2018 16:52:06 +0530 Subject: [Haskell-beginners] Clarification regarding idea discussion Message-ID: Hello, I am Ashwin Samudre a CSE undergraduate from Pune, India. I started learning haskell some time ago and I am referring the book 'first principles with haskell'. Being a student, I thought of applying for upcoming GSOC with Haskell community after going through the ideas page. Can I ask for the help to discuss the selected project idea on this mailing list.? If not, please let me know which could be the right place to discuss regarding this. Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon.jakobi at googlemail.com Thu Mar 8 13:00:22 2018 From: simon.jakobi at googlemail.com (Simon Jakobi) Date: Thu, 8 Mar 2018 14:00:22 +0100 Subject: [Haskell-beginners] Clarification regarding idea discussion In-Reply-To: References: Message-ID: Hi Ashwin! You may find help on this list, but you should rather directly contact the mentors listed with each idea. You should find their email adresses by looking up their Github profiles. Cheers, Simon 2018-03-08 12:22 GMT+01:00 Ashwin Samudre : > Hello, I am Ashwin Samudre a CSE undergraduate from Pune, India. I started > learning haskell some time ago and I am referring the book 'first > principles with haskell'. Being a student, I thought of applying for > upcoming GSOC with Haskell community after going through the ideas page. > > Can I ask for the help to discuss the selected project idea on this > mailing list.? > If not, please let me know which could be the right place to discuss > regarding this. > > Thank you. > > _______________________________________________ > 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 capnoi8 at gmail.com Thu Mar 8 13:30:27 2018 From: capnoi8 at gmail.com (Ashwin Samudre) Date: Thu, 8 Mar 2018 19:00:27 +0530 Subject: [Haskell-beginners] Clarification regarding idea discussion In-Reply-To: References: Message-ID: Thanks a lot. I would contact the mentor soon. In any case, I would be glad to be a part of Haskell community. On Mar 8, 2018 6:30 PM, "Simon Jakobi" wrote: > Hi Ashwin! > > You may find help on this list, but you should rather directly contact the > mentors listed with each idea. You should find their email adresses by > looking up their Github profiles. > > Cheers, > Simon > > 2018-03-08 12:22 GMT+01:00 Ashwin Samudre : > >> Hello, I am Ashwin Samudre a CSE undergraduate from Pune, India. I >> started learning haskell some time ago and I am referring the book 'first >> principles with haskell'. Being a student, I thought of applying for >> upcoming GSOC with Haskell community after going through the ideas page. >> >> Can I ask for the help to discuss the selected project idea on this >> mailing list.? >> If not, please let me know which could be the right place to discuss >> regarding this. >> >> Thank you. >> >> _______________________________________________ >> 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 hilco.wijbenga at gmail.com Sat Mar 10 07:25:29 2018 From: hilco.wijbenga at gmail.com (Hilco Wijbenga) Date: Fri, 9 Mar 2018 23:25:29 -0800 Subject: [Haskell-beginners] ReadP & Error Reporting Message-ID: Hi all, I recently discovered ReadP (Text.ParserCombinators.ReadP) and I wondered if I could use it to write simple parsers _with decent error reporting_. Let's say I want to parse "[ab] [12]" (i.e. either 'a', or 'b', followed by whitespace, followed by '1', or '2'). I believe something like this does the trick: parse = do name <- ReadP.choice [ReadP.char 'a', ReadP.char 'b'] ReadP.skipMany1 (ReadP.satisfy (\ch -> ch == ' ' || ch == '\t')) value <- ReadP.choice [ReadP.char '1', ReadP.char '2'] return (name, value) How do you add error handling to this? Obviously, I could change the signature to return an Either but I don't see how I "return" anything other than Right. E.g., I would want to give a warning like "Expected 'a', or 'b'" if anything other than 'a', or 'b' is used as first character. Similarly for '1' and '2'. The obvious(?) way would be to add an error result as the last option. The best I can come up with is adding ReadP.pfail to the list of choices but that doesn't allow me to add a useful error. Is ReadP simply not powerful enough for this? Or am I overlooking something obvious? I did some googling and there is plenty about creating parsers with parser combinators but I could not find anything about error handling. Cheers, Hilco From toad3k at gmail.com Sat Mar 10 21:04:01 2018 From: toad3k at gmail.com (David McBride) Date: Sat, 10 Mar 2018 16:04:01 -0500 Subject: [Haskell-beginners] ReadP & Error Reporting In-Reply-To: References: Message-ID: My first instinct is that no, there's not much you can do with this. You could wrap every combinator to return more detailed error messages, which might be *okay*. Or you could use the heavier parsing libraries and get all the error reporting for free. On Sat, Mar 10, 2018 at 2:25 AM, Hilco Wijbenga wrote: > Hi all, > > I recently discovered ReadP (Text.ParserCombinators.ReadP) and I > wondered if I could use it to write simple parsers _with decent error > reporting_. > > Let's say I want to parse "[ab] [12]" (i.e. either 'a', or 'b', > followed by whitespace, followed by '1', or '2'). I believe something > like this does the trick: > > parse = do > name <- ReadP.choice [ReadP.char 'a', ReadP.char 'b'] > ReadP.skipMany1 (ReadP.satisfy (\ch -> ch == ' ' || ch == '\t')) > value <- ReadP.choice [ReadP.char '1', ReadP.char '2'] > return (name, value) > > How do you add error handling to this? Obviously, I could change the > signature to return an Either but I don't see how I "return" anything > other than Right. > > E.g., I would want to give a warning like "Expected 'a', or 'b'" if > anything other than 'a', or 'b' is used as first character. Similarly > for '1' and '2'. The obvious(?) way would be to add an error result as > the last option. The best I can come up with is adding ReadP.pfail to > the list of choices but that doesn't allow me to add a useful error. > Is ReadP simply not powerful enough for this? Or am I overlooking > something obvious? > > I did some googling and there is plenty about creating parsers with > parser combinators but I could not find anything about error handling. > > Cheers, > Hilco > _______________________________________________ > 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 utprimum at gmail.com Sun Mar 18 13:37:31 2018 From: utprimum at gmail.com (Ut Primum) Date: Sun, 18 Mar 2018 14:37:31 +0100 Subject: [Haskell-beginners] how to know if a value has already been evaluated? Message-ID: In Haskell, the value of a variable is not always evaluated. This is fundamental when working with infinite lists. Is there a way of determining whether, at a certain point of the execution of a program, a value has been calculated or not? In particular, I would like to write a function that works on an infinite list that: - if the first value of a list, x, has already been evaluated, returns [x] - Else waits until it is evaluated, but without forcing its evaluation. (eventually, its evaluation will be forced later by other functions). Until then, the result of this function must be considered as [ ]. As soon as x is computed, it can return [x]. Is something like this possible in Haskell? -------------- next part -------------- An HTML attachment was scrubbed... URL: From higuoxing at outlook.com Sun Mar 18 13:53:51 2018 From: higuoxing at outlook.com (GUO Xing) Date: Sun, 18 Mar 2018 13:53:51 +0000 Subject: [Haskell-beginners] =?utf-8?q?Re=EF=BC=9A_how_to_know_if_a_value_?= =?utf-8?q?has_already_been__=09evaluated=3F?= References: Message-ID: Sounds like an *await* expression ... I am curious about it too! Regards Xing -------------- next part -------------- An HTML attachment was scrubbed... URL: From sanyanegi99 at gmail.com Tue Mar 20 02:27:50 2018 From: sanyanegi99 at gmail.com (Sanya Negi) Date: Tue, 20 Mar 2018 07:57:50 +0530 Subject: [Haskell-beginners] GSoC Project In-Reply-To: References: Message-ID: Hello! I am extremely interested in the project " offline mode for stack " for GSoC, for which I have learnt basic stack and have been learning more. Please guide me as to what other specific things I have to delve into and provide me pointers and inputs on how to break this problem into pieces to form my proposal. I can't seem to get in touch with the projects mentor Emanuel Borsboom. And as the deadline is reaching, I really need to start forming my proposal now. Soliciting a prompt and positive response. Sanya Negi -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben at bsima.me Tue Mar 20 16:41:57 2018 From: ben at bsima.me (Ben Sima) Date: Tue, 20 Mar 2018 09:41:57 -0700 Subject: [Haskell-beginners] GSoC Project In-Reply-To: (Sanya Negi's message of "Tue, 20 Mar 2018 07:57:50 +0530") References: Message-ID: <874llaya0a.fsf@bsima.me> Sanya, I would encourage you to follow this guide and put in your proposal as soon as you are able: http://write.flossmanuals.net/gsocstudentguide/writing-a-proposal/ Also note the FAQ here, in case some of your specific questions have already been answered: https://developers.google.com/open-source/gsoc/faq#students As you work on your proposal, if questions come up and you cannot contact Emanuel, you can reach out to me directly. I am a backup mentor for GSoC, and while mentors don't have any power to decide which applications are accepted, I can help work out some of the details of the proposal. I'm also on Freenode IRC as "bsima". Good luck, and thanks for participating in the Haskell GSoC :) Ben From mihai.maruseac at gmail.com Mon Mar 26 14:04:53 2018 From: mihai.maruseac at gmail.com (Mihai Maruseac) Date: Mon, 26 Mar 2018 07:04:53 -0700 Subject: [Haskell-beginners] [Call for Contributions] Haskell Communities and Activities Report, May 2018 edition (34th edition) Message-ID: Dear all, We would like to collect contributions for the 34th edition of the ============================================================ Haskell Communities & Activities Report http://www.haskell.org/haskellwiki/Haskell_Communities_and_Activities_Report Submission deadline: 30 April 2018 (please send your contributions to hcar at haskell.org, in plain text or LaTeX format, both are equally accepted) ============================================================ This is the short story: * If you are working on any project that is in some way related to Haskell, please write a short entry and submit it. Even if the project is very small or unfinished or you think it is not important enough --- please reconsider and submit an entry anyway! * If you are interested in an existing project related to Haskell that has not previously been mentioned in the HCAR, please tell us, so that we can contact the project leaders and ask them to submit an entry. * If you are working on a project that is looking for contributors, please write a short entry and submit it, mentioning that your are looking for contributors. * Feel free to pass on this call for contributions to others that might be interested. More detailed information: The Haskell Communities & Activities Report is a bi-annual overview of the state of Haskell as well as Haskell-related projects over the last, and possibly the upcoming six months. If you have only recently been exposed to Haskell, it might be a good idea to browse the previous edition --- you will find interesting projects described as well as several starting points and links that may provide answers to many questions. Contributions will be collected until the submission deadline. They will then be compiled into a coherent report that is published online as soon as it is ready. As always, this is a great opportunity to update your webpages, make new releases, announce or even start new projects, or to talk about developments you want every Haskeller to know about! Looking forward to your contributions, Mihai Maruseac FAQ: Q: What format should I write in? A: The usual format is a LaTeX source file, adhering to the template that is available at: http://haskell.org/communities/11-2017/template.tex There is also a LaTeX style file at http://haskell.org/communities/11-2017/hcar.sty that you can use to preview your entry. If you do not know LaTeX or don't want to use it or don't have time to translate your entry into it, then please use plain text, it is better to have an entry in plain-text which we will translate than not have it at all. If you modify an old entry that you have written for an earlier edition of the report, you should soon receive your old entry as a template (provided we have your valid email address). Please modify that template, rather than using your own version of the old entry as a template. Q: Can I include Haskell code? A: Yes. Please use lhs2tex syntax (http://www.andres-loeh.de/lhs2tex/). The report is compiled in mode polycode.fmt. Q: Can I include images? A: Yes, you are even encouraged to do so. Please use .jpg or .png format, then. PNG is preferred for simplicity. Q: Should I send files in .zip archives or similar? A: No, plain file attachments are the way. Q: How much should I write? A: Authors are asked to limit entries to about one column of text. A general introduction is helpful. Apart from that, you should focus on recent or upcoming developments. Pointers to online content can be given for more comprehensive or "historic" overviews of a project. Images do not count towards the length limit, so you may want to use this opportunity to pep up entries. There is no minimum length of an entry! The report aims for being as complete as possible, so please consider writing an entry, even if it is only a few lines long. Q: Which topics are relevant? A: All topics which are related to Haskell in some way are relevant. We usually had reports from users of Haskell (private, academic, or commercial), from authors or contributors to projects related to Haskell, from people working on the Haskell language, libraries, on language extensions or variants. We also like reports about distributions of Haskell software, Haskell infrastructure, books and tutorials on Haskell. Reports on past and upcoming events related to Haskell are also relevant. Finally, there might be new topics we do not even think about. As a rule of thumb: if in doubt, then it probably is relevant and has a place in the HCAR. You can also simply ask us. Q: Is unfinished work relevant? Are ideas for projects relevant? A: Yes! You can use the HCAR to talk about projects you are currently working on. You can use it to look for other developers that might help you. You can use HCAR to ask for more contributors to your project, it is a good way to gain visibility and traction. Q: If I do not update my entry, but want to keep it in the report, what should I do? A: Tell us that there are no changes. The old entry will typically be reused in this case, but it might be dropped if it is older than a year, to give more room and more attention to projects that change a lot. Do not resend complete entries if you have not changed them. Q: Will I get confirmation if I send an entry? How do I know whether my email has even reached its destination, and not ended up in a spam folder? A: Prior to publication of the final report, we will send a draft to all contributors, for possible corrections. So if you do not hear from us within two weeks after the deadline, it is safer to send another mail and check whether your first one was received. -- Mihai Maruseac (MM) "If you can't solve a problem, then there's an easier problem you can solve: find it." -- George Polya From frederic-emmanuel.picca at synchrotron-soleil.fr Mon Mar 26 17:52:58 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Mon, 26 Mar 2018 17:52:58 +0000 Subject: [Haskell-beginners] how to split a list Message-ID: Hello, I try to achieve this but I can not find a convenient (elegant solution) let l =[1,2, 3, 4, 6, 7, 9, 10] I want this [[1, 2, 3, 4][6, 7],[9, 10]] In fact I want to split a list with all consecutive series. I imagine that it existe a one-liner for this but I did not find it :)) Cheers and thanks for your help Frederic From fa-ml at ariis.it Mon Mar 26 18:11:44 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Mon, 26 Mar 2018 20:11:44 +0200 Subject: [Haskell-beginners] how to split a list In-Reply-To: References: Message-ID: <20180326181144.kyuiipcf73nzinyy@x60s.casa> On Mon, Mar 26, 2018 at 05:52:58PM +0000, PICCA Frederic-Emmanuel wrote: > Hello, I try to achieve this but I can not find a convenient (elegant solution) > > let l =[1,2, 3, 4, 6, 7, 9, 10] > > I want this > > [[1, 2, 3, 4][6, 7],[9, 10]] There's the usual zip trick λ> l = [1,2, 3, 4, 6, 7, 9, 10] λ> zipWith (-) l [1..] [0,0,0,0,1,1,2,2] λ> zip l it [(1,0),(2,0),(3,0),(4,0),(6,1),(7,1),(9,2),(10,2)] Now you can groupBy on the second element. I am not sure there is a shorter method! From fa-ml at ariis.it Mon Mar 26 18:18:29 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Mon, 26 Mar 2018 20:18:29 +0200 Subject: [Haskell-beginners] how to split a list In-Reply-To: <20180326181144.kyuiipcf73nzinyy@x60s.casa> References: <20180326181144.kyuiipcf73nzinyy@x60s.casa> Message-ID: <20180326181829.4lfasqt7iey7rrbr@x60s.casa> On Mon, Mar 26, 2018 at 08:11:44PM +0200, Francesco Ariis wrote: > There's the usual zip trick > > λ> l = [1,2, 3, 4, 6, 7, 9, 10] > λ> zipWith (-) l [1..] > [0,0,0,0,1,1,2,2] > λ> zip l it > [(1,0),(2,0),(3,0),(4,0),(6,1),(7,1),(9,2),(10,2)] To be more explicit: λ> :m +Data.List (groupBy) λ> :m +Data.Function (on) λ> l = [1,2, 3, 4, 6, 7, 9, 10] λ> map (map snd) $ groupBy ((==) `on` snd) $ zip l (zipWith (-) l [1..]) [[0,0,0,0],[1,1],[2,2]] Maybe with some lens or with a foldr you can end up with something shorter than this (69 characters). From frederic-emmanuel.picca at synchrotron-soleil.fr Mon Mar 26 18:26:19 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Mon, 26 Mar 2018 18:26:19 +0000 Subject: [Haskell-beginners] how to split a list In-Reply-To: <20180326181829.4lfasqt7iey7rrbr@x60s.casa> References: <20180326181144.kyuiipcf73nzinyy@x60s.casa>, <20180326181829.4lfasqt7iey7rrbr@x60s.casa> Message-ID: > To be more explicit: > λ> :m +Data.List (groupBy) > λ> :m +Data.Function (on) > λ> l = [1,2, 3, 4, 6, 7, 9, 10] > λ> map (map snd) $ groupBy ((==) `on` snd) $ zip l (zipWith (-) l [1..]) > [[0,0,0,0],[1,1],[2,2]] I imagine that you mean fst instead of snd in order to produce the right output :) How can I check if this code produce list copies and is efficient with big lists ? thanks Frederic From fa-ml at ariis.it Mon Mar 26 19:01:48 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Mon, 26 Mar 2018 21:01:48 +0200 Subject: [Haskell-beginners] how to split a list In-Reply-To: References: <20180326181144.kyuiipcf73nzinyy@x60s.casa> <20180326181829.4lfasqt7iey7rrbr@x60s.casa> Message-ID: <20180326190148.4upitvbavpfvo6jd@x60s.casa> On Mon, Mar 26, 2018 at 06:26:19PM +0000, PICCA Frederic-Emmanuel wrote: > I imagine that you mean fst instead of snd in order to produce the right output :) Indeed :P > How can I check if this code produce list copies and is efficient with big lists ? `time` and profiling tools provided by GHC [1] If you feel lost, shout and I'll set up and example [1] http://book.realworldhaskell.org/read/profiling-and-optimization.html From frederic-emmanuel.picca at synchrotron-soleil.fr Mon Mar 26 19:21:22 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Mon, 26 Mar 2018 19:21:22 +0000 Subject: [Haskell-beginners] how to split a list In-Reply-To: <20180326190148.4upitvbavpfvo6jd@x60s.casa> References: <20180326181144.kyuiipcf73nzinyy@x60s.casa> <20180326181829.4lfasqt7iey7rrbr@x60s.casa> , <20180326190148.4upitvbavpfvo6jd@x60s.casa> Message-ID: Just one question about this. I do not want to put a print in order to generate the newList object. let l = [] let newList = superChnker l print newList How Can I tell to haskell, produce the result even if I do not use it. From tanuki at gmail.com Mon Mar 26 20:48:09 2018 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Mon, 26 Mar 2018 13:48:09 -0700 Subject: [Haskell-beginners] how to split a list In-Reply-To: References: <20180326181144.kyuiipcf73nzinyy@x60s.casa> <20180326181829.4lfasqt7iey7rrbr@x60s.casa> <20180326190148.4upitvbavpfvo6jd@x60s.casa> Message-ID: Wow... after attempting a simpler solution, I now understand a discussion from a little while back on one of the other lists about how terribly unexpected the default groupBy behavior is. On Mon, Mar 26, 2018 at 12:21 PM, PICCA Frederic-Emmanuel < frederic-emmanuel.picca at synchrotron-soleil.fr> wrote: > Just one question about this. > > I do not want to put a print in order to generate the newList object. > > > let l = [] > let newList = superChnker l > print newList > > > How Can I tell to haskell, produce the result even if I do not use it. > _______________________________________________ > 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 fa-ml at ariis.it Tue Mar 27 07:41:05 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Tue, 27 Mar 2018 09:41:05 +0200 Subject: [Haskell-beginners] how to split a list In-Reply-To: References: <20180326181144.kyuiipcf73nzinyy@x60s.casa> <20180326181829.4lfasqt7iey7rrbr@x60s.casa> <20180326190148.4upitvbavpfvo6jd@x60s.casa> Message-ID: <20180327074105.6sztwji66gs4fxf6@x60s.casa> On Mon, Mar 26, 2018 at 07:21:22PM +0000, PICCA Frederic-Emmanuel wrote: > How Can I tell to haskell, produce the result even if I do not use it. deepseq [1]! [1] https://hackage.haskell.org/package/deepseq-1.4.3.0/docs/Control-DeepSeq.html#v:deepseq From malikraghav at gmail.com Tue Mar 27 16:11:51 2018 From: malikraghav at gmail.com (Raghav Malik) Date: Tue, 27 Mar 2018 16:11:51 +0000 Subject: [Haskell-beginners] Rounding to 2 decimal places Message-ID: Hi, I have a complex double (x :+ y) where 'x' and 'y' are computed using sin and cos functions on an angle expressed in radians. However, the output on the command line (using GHCi) shows up with a lot of decimal places. How can I limit the values of 'x' and 'y' to having only two decimal places? Thanks, Raghav -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Tue Mar 27 16:32:56 2018 From: toad3k at gmail.com (David McBride) Date: Tue, 27 Mar 2018 12:32:56 -0400 Subject: [Haskell-beginners] Rounding to 2 decimal places In-Reply-To: References: Message-ID: Because there is already a Show instance for Complex a, you will have to use your own show function. Something list this. import Text.Printf import Data.Complex showComplex :: Complex Float -> String showComplex (a :+ b) = (printf "%.2f" a) ++ " :+ " ++ (printf "%.2f" b) On Tue, Mar 27, 2018 at 12:11 PM, Raghav Malik wrote: > Hi, > > I have a complex double (x :+ y) where 'x' and 'y' are computed using sin > and cos functions on an angle expressed in radians. > > However, the output on the command line (using GHCi) shows up with a lot > of decimal places. How can I limit the values of 'x' and 'y' to having only > two decimal places? > > Thanks, > Raghav > > _______________________________________________ > 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 imantc at gmail.com Tue Mar 27 16:42:26 2018 From: imantc at gmail.com (Imants Cekusins) Date: Tue, 27 Mar 2018 16:42:26 +0000 Subject: [Haskell-beginners] Rounding to 2 decimal places In-Reply-To: References: Message-ID: Or you could use Centi instead of Float: http://hackage.haskell.org/package/base-4.11.0.0/docs/Data-Fixed.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From justinthong93 at gmail.com Wed Mar 28 18:19:35 2018 From: justinthong93 at gmail.com (Justin Thong) Date: Wed, 28 Mar 2018 14:19:35 -0400 Subject: [Haskell-beginners] Two type declarations Message-ID: What is the difference between these two type declarations? The second one is wrong but I can't convince myself why it should be wrong. Is it because *Int *not a constraint class and it is only an instance of one? My curiousity is why #1 can't be written in the form of #2. I apologise if I am using wrong terminology as type, class and constraint class are used with not much distinction. To add context, this problem is to find a function that will find an element by passing in a list and an index argument. elementAt''' ::[a]-> Int ->a -- #1 elementAt''' [] _= error "list is empty" elementAt''' list index | (index < 1) = error "index has to be positive number" | otherwise= list !! (index-1) elementAt'''' ::(Int b)=>[a]-> b ->a -- #2 elementAt'''' [] _= error "list is empty" elementAt'''' list index | (index < 1) = error "index has to be positive number" | otherwise= list !! (index-1) Thank you. I just began learning Haskell. Yours sincerely, Justin *I check my email at 9AM and 4PM everyday* *If you have an EMERGENCY, contact me at +447938674419(UK) or +60125056192(Malaysia)* -------------- next part -------------- An HTML attachment was scrubbed... URL: From sylvain at haskus.fr Wed Mar 28 18:33:56 2018 From: sylvain at haskus.fr (Sylvain Henry) Date: Wed, 28 Mar 2018 20:33:56 +0200 Subject: [Haskell-beginners] Two type declarations In-Reply-To: References: Message-ID: Indeed "Int b" is not a valid constraint: the kind of "Int" is Type (or "*") as GHC reports: > Expecting one fewer arguments to ‘Int’ > Expected kind ‘* -> Constraint’, but ‘Int’ has kind ‘*’ A valid constraint would be "Int ~ b" as in the following example. But I don't see why you would do this in this case, especially if you are beginning with Haskell. It complicates the code for no gain. {-# LANGUAGE TypeFamilies #-} elementAt'''' ::(Int ~ b)=>[a]-> b ->a -- #2 elementAt'''' [] _= error "list is empty" elementAt'''' list index    | (index < 1) = error "index has to be positive number"    | otherwise= list !! (index-1) Cheers Sylvain On 28/03/2018 20:19, Justin Thong wrote: > What is the difference between these two type declarations? The second > one is wrong but I can't convince myself why it should be wrong. Is it > because /Int /not a constraint class and it is only an instance of > one? My curiousity is why #1 can't be written in the form of #2. I > apologise if I am using wrong terminology as type, class and > constraint class are used with not much distinction. To add context, > this problem is to find a function that will find an element by > passing in a list and an index argument. > > elementAt''' ::[a]-> Int ->a -- #1 > elementAt''' [] _= error "list is empty" > elementAt''' list index > | (index < 1) = error "index has to be positive number" > | otherwise= list !! (index-1) > > elementAt'''' ::(Int b)=>[a]-> b ->a -- #2 > elementAt'''' [] _= error "list is empty" > elementAt'''' list index > | (index < 1) = error "index has to be positive number" > | otherwise= list !! (index-1) > > Thank you. I just began learning Haskell. > > > Yours sincerely, > Justin > > /I check my email at 9AM and 4PM everyday/ > /If you have an *EMERGENCY*, contact me at +447938674419(UK) or > +60125056192(Malaysia)/ > > > > _______________________________________________ > 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 mike_k_houghton at yahoo.co.uk Thu Mar 29 15:33:19 2018 From: mike_k_houghton at yahoo.co.uk (mike h) Date: Thu, 29 Mar 2018 16:33:19 +0100 Subject: [Haskell-beginners] Stack and Cabal Message-ID: <87333E08-541F-450D-AF31-46B8A3316F93@yahoo.co.uk> Hi, I have dependencies on mtl >= 2.2.2 and containers >= 0.5.11.0 should these go into my .cabal file or into my local stack.yaml? Which is best practice? Can anyone recommend a stack/cabal ‘cheat sheet’? Thanks Mike From michael at snoyman.com Thu Mar 29 16:02:11 2018 From: michael at snoyman.com (Michael Snoyman) Date: Thu, 29 Mar 2018 19:02:11 +0300 Subject: [Haskell-beginners] Stack and Cabal In-Reply-To: <87333E08-541F-450D-AF31-46B8A3316F93@yahoo.co.uk> References: <87333E08-541F-450D-AF31-46B8A3316F93@yahoo.co.uk> Message-ID: I wrote up a doc to address this question: https://docs.haskellstack.org/en/stable/stack_yaml_vs_cabal_package_file/ On Thu, Mar 29, 2018 at 6:33 PM, mike h wrote: > Hi, > > I have dependencies on mtl >= 2.2.2 and containers >= 0.5.11.0 > should these go into my .cabal file or into my local stack.yaml? > Which is best practice? > > Can anyone recommend a stack/cabal ‘cheat sheet’? > > Thanks > > Mike > > _______________________________________________ > 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 mike_k_houghton at yahoo.co.uk Thu Mar 29 18:23:01 2018 From: mike_k_houghton at yahoo.co.uk (mike h) Date: Thu, 29 Mar 2018 19:23:01 +0100 Subject: [Haskell-beginners] Stack and Cabal In-Reply-To: References: <87333E08-541F-450D-AF31-46B8A3316F93@yahoo.co.uk> Message-ID: Thanks. > On 29 Mar 2018, at 17:02, Michael Snoyman wrote: > > I wrote up a doc to address this question: > > https://docs.haskellstack.org/en/stable/stack_yaml_vs_cabal_package_file/ > > On Thu, Mar 29, 2018 at 6:33 PM, mike h > wrote: > Hi, > > I have dependencies on mtl >= 2.2.2 and containers >= 0.5.11.0 > should these go into my .cabal file or into my local stack.yaml? > Which is best practice? > > Can anyone recommend a stack/cabal ‘cheat sheet’? > > Thanks > > Mike > > _______________________________________________ > 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From frederic-emmanuel.picca at synchrotron-soleil.fr Sat Mar 31 07:54:50 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Sat, 31 Mar 2018 07:54:50 +0000 Subject: [Haskell-beginners] phantom type Message-ID: Hello, Here my problem. I extract some information from a database and put them into a type with 50 parameters Type MyData = MyData Int String ... But I need to be able to differenciate two different case. depending on the String content. something like if the String start with "ref-" it is a Caracterization and if not it is a Collect So I end up with this solution data Unchecked data Caracterization data Collect data MyData t = MyData Int String ... now I defined a function getMyDataFromDatabase :: ... -> Mydata Unchecked and isCollect in order to verify that I have a Collect and not something Else isACollect :: MyData Unchecked -> Either Text (MyData Collect). which use coerc in order to avoid copying all the members. It is great. now Here is my problem. I create a method myMethod :: MyData Collect -> IO () but I want my method to work for MyData Collect and Mydata Caracterization but not Unchecked. So It seems to me that I can not just do myMethod :: MyData t -> IO () what is the right way to solve this problem ? thanks for your help. Frederic From fa-ml at ariis.it Sat Mar 31 08:40:11 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 31 Mar 2018 10:40:11 +0200 Subject: [Haskell-beginners] phantom type In-Reply-To: References: Message-ID: <20180331084011.5ixszt3pboaovr4i@x60s.casa> On Sat, Mar 31, 2018 at 07:54:50AM +0000, PICCA Frederic-Emmanuel wrote: > I create a method > > myMethod :: MyData Collect -> IO () > > but I want my method to work for MyData Collect and Mydata Caracterization but not Unchecked. > > So It seems to me that I can not just do > > myMethod :: MyData t -> IO () > > > what is the right way to solve this problem ? Hello Frederic, I am in a rush so I cant write a minimal example, but wouldn't a typeclass + make Collect and Cara instances of that typeclass do? -F From tanuki at gmail.com Sat Mar 31 20:31:46 2018 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Sat, 31 Mar 2018 20:31:46 +0000 Subject: [Haskell-beginners] phantom type In-Reply-To: <20180331084011.5ixszt3pboaovr4i@x60s.casa> References: <20180331084011.5ixszt3pboaovr4i@x60s.casa> Message-ID: Directly relevant blog: https://www.benjamin.pizza/posts/2017-12-15-functor-functors.html On Sat, Mar 31, 2018, 1:41 AM Francesco Ariis wrote: > On Sat, Mar 31, 2018 at 07:54:50AM +0000, PICCA Frederic-Emmanuel wrote: > > I create a method > > > > myMethod :: MyData Collect -> IO () > > > > but I want my method to work for MyData Collect and Mydata > Caracterization but not Unchecked. > > > > So It seems to me that I can not just do > > > > myMethod :: MyData t -> IO () > > > > > > what is the right way to solve this problem ? > > Hello Frederic, > I am in a rush so I cant write a minimal example, but wouldn't > a typeclass + make Collect and Cara instances of that typeclass do? > -F > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: