From frederic-emmanuel.picca at synchrotron-soleil.fr Thu Jun 1 17:33:00 2017 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Thu, 1 Jun 2017 17:33:00 +0000 Subject: [Haskell-beginners] Attoparsec parser question In-Reply-To: <20170524162023.GB20506@casa.casa> References: , <20170524162023.GB20506@casa.casa> Message-ID: Hello Francesco > maybe next time attach a simple .hs file which replicates the issue > (with import modules, etc.), this way it is simpler to diagnose. I will considere this next time. > Just by scanning the code, this raises a red flag: > > detectorP ∷ ToPyFAI a ⇒ a → Parser a > > detectorP a = do > > _ ← "Detector: " *> string (toPyFAI a) <* endOfLine > > pure a > "Detector: " is a plain String, so i guess putting a `string` before it > (or whatever is needed) should solve the issue. > Does that solve the problem? I solved my problem doing something else, but thanks for your help. thanks a lot Fred From frederic-emmanuel.picca at synchrotron-soleil.fr Fri Jun 2 06:04:44 2017 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Fri, 2 Jun 2017 06:04:44 +0000 Subject: [Haskell-beginners] help designing types for a gsl fit Message-ID: Hello I imagine that I have two types A and B I want to create a ADT data C = C A B 1) the toGsl class class ToGsl a where toGsl :: a -> [Double] this class allow to convert a type to a Vector of double in order to use gsl for a fit so I can create instance for A and B (I do not write the instance but the result of the toGsl function) A -> [a1, ... an] B -> [b1, ... bm] Now I want this to work also with C C -> [a1..., an] ++ [b1, .... bm] So the C instance is juste the (toGsl a) ++ (toGsl b) Is there a way to write this generically for other type construct like (data D = D C A) etc.... Functor, Applicative, Monoid ? 2) the fromGsl case now the inverse method is cladd FromGsl a where fromGsl :: a -> [Double] -> a so now the question is if I have a [Double], I need t osplit this list for each composant of the ADT. in the case of C fromGSL (C a b) v = ...split the vector... and apply fromGsl to a and b So my question is the symetic of the previous one. Is it possible to create a generic function inorder to do this. thanks for your help. Frederic From fa-ml at ariis.it Fri Jun 2 17:30:39 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Fri, 2 Jun 2017 19:30:39 +0200 Subject: [Haskell-beginners] help designing types for a gsl fit In-Reply-To: References: Message-ID: <20170602173039.GB2274@casa.casa> On Fri, Jun 02, 2017 at 06:04:44AM +0000, PICCA Frederic-Emmanuel wrote: > Now I want this to work also with C > > C -> [a1..., an] ++ [b1, .... bm] > > So the C instance is juste the (toGsl a) ++ (toGsl b) > > Is there a way to write this generically for other type construct like > (data D = D C A) etc.... Hello Frederic, maye Generic programming [1] is what you need? [1] https://wiki.haskell.org/Generics > 2) the fromGsl case 2) is more tricky to me. How do I decide where to split? Feels like parsing data. From aquagnu at gmail.com Wed Jun 7 12:26:44 2017 From: aquagnu at gmail.com (Baa) Date: Wed, 7 Jun 2017 15:26:44 +0300 Subject: [Haskell-beginners] Alternative instance w/ additional restriction In-Reply-To: References: <04C0433B-3D6A-4DE9-ABEC-488EF59859AE@me.com> <20170525181027.1a74deff@Pavel> <20170525191150.51d8e3ac@Pavel> <20170525213703.54e8296a@gmail.com> Message-ID: <20170607152644.1bc47bc8@Pavel> Hello all! If I try to write, for example: instance Alternative MyData where empty = NoMyData a <|> b = if a == b then ... I get error (see on bottom of the mail) sure, bcz I suppose something like: Eq a => (MyData a) All my attempts to add something to instance's `pure` signature have failed. How can I instantiate something with additional restrictions, like in this case? Or are there another solutions for such problem? Interesting is that MyData derives Eq itself! Which, I suppose, must means that "Eq (MyData a)", and if it's true than "Eq a" is true, because how "MyData a" can be Eq without to be "Eq a" (with *automatically deriving* of Eq instance) ?! By the way, for Monoid (which is "* -> Constraint") I can add "Eq a" constraint without problems: instance Eq a => Monoid (Origin a) where mempty = NoMyData mappend NoMyData a = a mappend a NoMyData = a mappend (MyData a) (MyData b)|a == b = MyData a |otherwise = NoMyData but not for Alternative, which is "(* -> *) -> Constraint". *ORIGINAL ERROR DUMP*: ====================== 42 16 error error: • No instance for (Eq a) arising from a use of ‘==’ Possible fix: add (Eq a) to the context of the type signature for: (<|>) :: Origin a -> Origin a -> Origin a • In the expression: a == b In the expression: if a == b then NoOrigin else NoOrigin In an equation for ‘<|>’: a <|> b = if a == b then NoOrigin else NoOrigin (intero) /Best regards Paul From toad3k at gmail.com Wed Jun 7 15:25:26 2017 From: toad3k at gmail.com (David McBride) Date: Wed, 7 Jun 2017 11:25:26 -0400 Subject: [Haskell-beginners] Alternative instance w/ additional restriction In-Reply-To: <20170607152644.1bc47bc8@Pavel> References: <04C0433B-3D6A-4DE9-ABEC-488EF59859AE@me.com> <20170525181027.1a74deff@Pavel> <20170525191150.51d8e3ac@Pavel> <20170525213703.54e8296a@gmail.com> <20170607152644.1bc47bc8@Pavel> Message-ID: The Alternative class says nothing about the a in MyData a. It only represents code relevant to MyData. When you see class Applicative f => Alternative (f :: * -> *), that means all of its functions had to work on any f, where f takes any type and becomes some other type which could be anything. The reason it works for Monoid is that class Monoid a where implies that a is completely known by the time the instance is fulfilled, therefore the instance can look at what a ended up being and ensure whatever a is, it must have this constraint on it. You can tell the difference because mempty returns a type that mentions the a mentioned in the class, whereas empty returns an a that is not mentioned in the class, therefore it has to work for any a. On Wed, Jun 7, 2017 at 8:26 AM, Baa wrote: > Hello all! > > If I try to write, for example: > > instance Alternative MyData where > empty = NoMyData > a <|> b = if a == b then ... > > I get error (see on bottom of the mail) sure, bcz I suppose something > like: > > Eq a => (MyData a) > > All my attempts to add something to instance's `pure` signature have > failed. How can I instantiate something with additional restrictions, > like in this case? Or are there another solutions for such problem? > > Interesting is that MyData derives Eq itself! Which, I suppose, must > means that "Eq (MyData a)", and if it's true than "Eq a" is true, > because how "MyData a" can be Eq without to be "Eq a" (with > *automatically deriving* of Eq instance) ?! > > By the way, for Monoid (which is "* -> Constraint") I can add "Eq a" > constraint without problems: > > instance Eq a => Monoid (Origin a) where > mempty = NoMyData > mappend NoMyData a = a > mappend a NoMyData = a > mappend (MyData a) (MyData b)|a == b = MyData a > |otherwise = NoMyData > > but not for Alternative, which is "(* -> *) -> Constraint". > > *ORIGINAL ERROR DUMP*: > ====================== > 42 16 error error: > • No instance for (Eq a) arising from a use of ‘==’ > Possible fix: > add (Eq a) to the context of > the type signature for: > (<|>) :: Origin a -> Origin a -> Origin a > • In the expression: a == b > In the expression: if a == b then NoOrigin else NoOrigin > In an equation for ‘<|>’: > a <|> b = if a == b then NoOrigin > else NoOrigin (intero) > > > /Best regards > Paul > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From aquagnu at gmail.com Wed Jun 7 16:06:25 2017 From: aquagnu at gmail.com (Baa) Date: Wed, 7 Jun 2017 19:06:25 +0300 Subject: [Haskell-beginners] Alternative instance w/ additional restriction In-Reply-To: References: <04C0433B-3D6A-4DE9-ABEC-488EF59859AE@me.com> <20170525181027.1a74deff@Pavel> <20170525191150.51d8e3ac@Pavel> <20170525213703.54e8296a@gmail.com> <20170607152644.1bc47bc8@Pavel> Message-ID: <20170607190625.29dfb935@Pavel> So, if I understood right, I'm trying to restrict instance more than class allows. And only way to accomplish it - is to create own class instead of Alternative which will not be based on Functor :: (* -> *) -> *, like Alternative. No other workarounds? В Wed, 7 Jun 2017 11:25:26 -0400 David McBride пишет: > The Alternative class says nothing about the a in MyData a. It only > represents code relevant to MyData. > > When you see class Applicative f => Alternative (f :: * -> *), that > means all of its functions had to work on any f, where f takes any > type and becomes some other type which could be anything. > > The reason it works for Monoid is that class Monoid a where implies > that a is completely known by the time the instance is fulfilled, > therefore the instance can look at what a ended up being and ensure > whatever a is, it must have this constraint on it. > > You can tell the difference because mempty returns a type that > mentions the a mentioned in the class, whereas empty returns an a that > is not mentioned in the class, therefore it has to work for any a. > > On Wed, Jun 7, 2017 at 8:26 AM, Baa wrote: > > Hello all! > > > > If I try to write, for example: > > > > instance Alternative MyData where > > empty = NoMyData > > a <|> b = if a == b then ... > > > > I get error (see on bottom of the mail) sure, bcz I suppose > > something like: > > > > Eq a => (MyData a) > > > > All my attempts to add something to instance's `pure` signature have > > failed. How can I instantiate something with additional > > restrictions, like in this case? Or are there another solutions for > > such problem? > > > > Interesting is that MyData derives Eq itself! Which, I suppose, must > > means that "Eq (MyData a)", and if it's true than "Eq a" is true, > > because how "MyData a" can be Eq without to be "Eq a" (with > > *automatically deriving* of Eq instance) ?! > > > > By the way, for Monoid (which is "* -> Constraint") I can add "Eq a" > > constraint without problems: > > > > instance Eq a => Monoid (Origin a) where > > mempty = NoMyData > > mappend NoMyData a = a > > mappend a NoMyData = a > > mappend (MyData a) (MyData b)|a == b = MyData a > > |otherwise = NoMyData > > > > but not for Alternative, which is "(* -> *) -> Constraint". > > > > *ORIGINAL ERROR DUMP*: > > ====================== > > 42 16 error error: > > • No instance for (Eq a) arising > > from a use of ‘==’ Possible fix: > > add (Eq a) to the context of > > the type signature for: > > (<|>) :: Origin a -> Origin > > a -> Origin a • In the expression: a == b > > In the expression: if a == b then > > NoOrigin else NoOrigin In an equation for ‘<|>’: > > a <|> b = if a == b then > > NoOrigin else NoOrigin (intero) > > > > > > /Best regards > > Paul > > _______________________________________________ > > 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 From aquagnu at gmail.com Wed Jun 7 16:33:52 2017 From: aquagnu at gmail.com (Baa) Date: Wed, 7 Jun 2017 19:33:52 +0300 Subject: [Haskell-beginners] mempty and "No instance for (Monoid Int)" Message-ID: <20170607193352.0085b85a@Pavel> Maybe a is the Monoid: instance Monoid a => Monoid (Maybe a) -- Defined in ‘GHC.Base’ so I can compare its values with empty value: mempty == Nothing => True But if I try: mempty == Just 4 I get: :1:1: error: • Ambiguous type variable ‘a0’ arising from a use of ‘mempty’ prevents the constraint ‘(Monoid a0)’ from being solved. Probable fix: use a type annotation to specify what ‘a0’ should be. These potential instances exist: instance Monoid a => Monoid (IO a) -- Defined in ‘GHC.Base’ instance Monoid Ordering -- Defined in ‘GHC.Base’ instance Monoid a => Monoid (Maybe a) -- Defined in ‘GHC.Base’ ...plus 7 others (use -fprint-potential-instances to see them all) • In the first argument of ‘(==)’, namely ‘mempty’ In the expression: mempty == Just 4 In an equation for ‘it’: it = mempty == Just 4 OK, I try: mempty::Maybe Int and get: :1:1: error: • No instance for (Monoid Int) arising from a use of ‘mempty’ • In the expression: mempty :: Maybe Int In an equation for ‘it’: it = mempty :: Maybe Int so, how is related Int to Monoid, why does ghc expect from mempty::Maybe Int, Int to be Monoid?! As I understand, this means only that I mean "mempty" from (Maybe Int) type, which is Monoid and exists sure. Interesting is, that: mempty::Maybe [Int] => Nothing but how is related "monoidality" of "Maybe a" with "monoidality of "a" ??? Initial idea was to make comparison: mempty :: Maybe Int == Just 4 => False /Best regards, Paul From toad3k at gmail.com Wed Jun 7 16:40:52 2017 From: toad3k at gmail.com (David McBride) Date: Wed, 7 Jun 2017 12:40:52 -0400 Subject: [Haskell-beginners] Alternative instance w/ additional restriction In-Reply-To: <20170607190625.29dfb935@Pavel> References: <04C0433B-3D6A-4DE9-ABEC-488EF59859AE@me.com> <20170525181027.1a74deff@Pavel> <20170525191150.51d8e3ac@Pavel> <20170525213703.54e8296a@gmail.com> <20170607152644.1bc47bc8@Pavel> <20170607190625.29dfb935@Pavel> Message-ID: I honestly don't think so. But you can ask on haskell-cafe or on stackoverflow if you like. There is a reasonable chance that a class or library exists that already will do what you are looking for, just that I haven't heard of it. On Wed, Jun 7, 2017 at 12:06 PM, Baa wrote: > So, if I understood right, I'm trying to restrict instance more than > class allows. And only way to accomplish it - is to create own class > instead of Alternative which will not be based on > Functor :: (* -> *) -> *, like Alternative. No other workarounds? > > > > В Wed, 7 Jun 2017 11:25:26 -0400 > David McBride пишет: > >> The Alternative class says nothing about the a in MyData a. It only >> represents code relevant to MyData. >> >> When you see class Applicative f => Alternative (f :: * -> *), that >> means all of its functions had to work on any f, where f takes any >> type and becomes some other type which could be anything. >> >> The reason it works for Monoid is that class Monoid a where implies >> that a is completely known by the time the instance is fulfilled, >> therefore the instance can look at what a ended up being and ensure >> whatever a is, it must have this constraint on it. >> >> You can tell the difference because mempty returns a type that >> mentions the a mentioned in the class, whereas empty returns an a that >> is not mentioned in the class, therefore it has to work for any a. >> >> On Wed, Jun 7, 2017 at 8:26 AM, Baa wrote: >> > Hello all! >> > >> > If I try to write, for example: >> > >> > instance Alternative MyData where >> > empty = NoMyData >> > a <|> b = if a == b then ... >> > >> > I get error (see on bottom of the mail) sure, bcz I suppose >> > something like: >> > >> > Eq a => (MyData a) >> > >> > All my attempts to add something to instance's `pure` signature have >> > failed. How can I instantiate something with additional >> > restrictions, like in this case? Or are there another solutions for >> > such problem? >> > >> > Interesting is that MyData derives Eq itself! Which, I suppose, must >> > means that "Eq (MyData a)", and if it's true than "Eq a" is true, >> > because how "MyData a" can be Eq without to be "Eq a" (with >> > *automatically deriving* of Eq instance) ?! >> > >> > By the way, for Monoid (which is "* -> Constraint") I can add "Eq a" >> > constraint without problems: >> > >> > instance Eq a => Monoid (Origin a) where >> > mempty = NoMyData >> > mappend NoMyData a = a >> > mappend a NoMyData = a >> > mappend (MyData a) (MyData b)|a == b = MyData a >> > |otherwise = NoMyData >> > >> > but not for Alternative, which is "(* -> *) -> Constraint". >> > >> > *ORIGINAL ERROR DUMP*: >> > ====================== >> > 42 16 error error: >> > • No instance for (Eq a) arising >> > from a use of ‘==’ Possible fix: >> > add (Eq a) to the context of >> > the type signature for: >> > (<|>) :: Origin a -> Origin >> > a -> Origin a • In the expression: a == b >> > In the expression: if a == b then >> > NoOrigin else NoOrigin In an equation for ‘<|>’: >> > a <|> b = if a == b then >> > NoOrigin else NoOrigin (intero) >> > >> > >> > /Best regards >> > Paul >> > _______________________________________________ >> > 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 > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From toad3k at gmail.com Wed Jun 7 16:53:19 2017 From: toad3k at gmail.com (David McBride) Date: Wed, 7 Jun 2017 12:53:19 -0400 Subject: [Haskell-beginners] mempty and "No instance for (Monoid Int)" In-Reply-To: <20170607193352.0085b85a@Pavel> References: <20170607193352.0085b85a@Pavel> Message-ID: In ghci there are type defaulting rules. When you go mempty == Nothing, it type defaults it to "Maybe ()". But when you type Just 4, 4 is definitely not (), and so it looks at the Monoid instance for the a default type to use in cases of numeric literals, the first of which is Int. Which brings you to the next problem. Maybe Int is only a Monoid if Int is an instance of Monoid, and Int is definitely not. That's because is 3 `mappend` 3 == 6 via addition? Or should it be 9 via multiplication? Or something else? What should mempty be, 0? Or maybe 1? Who is to decide what the only way of combining Ints together is. It turns out there are instances for both of those cases, but you have to wrap the int into a type so that it knows which way you want it to be interpreted. import Data.Monoid mempty == Just (Product 1) > false mempty == Just (Sum 1) > false There are similar monoidal instances for Bool, such as Any and All. On Wed, Jun 7, 2017 at 12:33 PM, Baa wrote: > Maybe a is the Monoid: > > instance Monoid a => Monoid (Maybe a) -- Defined in ‘GHC.Base’ > > so I can compare its values with empty value: > > mempty == Nothing > => True > > But if I try: > > mempty == Just 4 > > I get: > > :1:1: error: > • Ambiguous type variable ‘a0’ arising from a use of ‘mempty’ > prevents the constraint ‘(Monoid a0)’ from being solved. > Probable fix: use a type annotation to specify what ‘a0’ should > be. These potential instances exist: > instance Monoid a => Monoid (IO a) -- Defined in ‘GHC.Base’ > instance Monoid Ordering -- Defined in ‘GHC.Base’ > instance Monoid a => Monoid (Maybe a) -- Defined in ‘GHC.Base’ > ...plus 7 others > (use -fprint-potential-instances to see them all) > • In the first argument of ‘(==)’, namely ‘mempty’ > In the expression: mempty == Just 4 > In an equation for ‘it’: it = mempty == Just 4 > > OK, I try: > > mempty::Maybe Int > > and get: > > :1:1: error: > • No instance for (Monoid Int) arising from a use of ‘mempty’ > • In the expression: mempty :: Maybe Int > In an equation for ‘it’: it = mempty :: Maybe Int > > so, how is related Int to Monoid, why does ghc expect from mempty::Maybe > Int, Int to be Monoid?! As I understand, this means only that I > mean "mempty" from (Maybe Int) type, which is Monoid and exists sure. > > Interesting is, that: > > mempty::Maybe [Int] > => Nothing > > but how is related "monoidality" of "Maybe a" with "monoidality of > "a" ??? > > Initial idea was to make comparison: > > mempty :: Maybe Int == Just 4 > => False > > > /Best regards, > Paul > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From aquagnu at gmail.com Wed Jun 7 18:53:36 2017 From: aquagnu at gmail.com (aquagnu) Date: Wed, 7 Jun 2017 21:53:36 +0300 Subject: [Haskell-beginners] mempty and "No instance for (Monoid Int)" In-Reply-To: References: <20170607193352.0085b85a@Pavel> Message-ID: <20170607215336.288715ce@gmail.com> > In ghci there are type defaulting rules. When you go mempty == > Nothing, it type defaults it to "Maybe ()". Aha, OK. These defaults are preset also in non-interactive: I tried the same and get the same result. > But when you type Just 4, > 4 is definitely not (), and so it looks at the Monoid instance for the > a default type to use in cases of numeric literals, the first of which > is Int. This I can not understand. Literal "4" is under "Just", so why are we talking about "Int" as Monoid but not about "Maybe Int" as Monoid? And "Maybe Int" as Monoid does not depend on Int and is the same for "Maybe Int", "Maybe Bool", "Maybe String"... When I added type annotation, like "::Maybe Int", I suppose, usual "Maybe a"'s implementations of "mempty", "mappend" will be used, - no more defaults. Seems it is not true, but why? > > Which brings you to the next problem. Maybe Int is only a Monoid if > Int is an instance of Monoid, and Int is definitely not. > I don't understand it. Monoid is "Maybe a" for any "a". And I can understand your point if we are talking only for interactive GHCI and its defaults, but when I tried in source code to write: m :: Maybe Int m = mempty ... ... print $ Nothing == m i get the same, about no instance for (Monoid Int). But Maybe's "mempty" is "Nothing", nothing else. And its "mappend" processes any (Just _) and Nothing's, right? May be all magic is from defaults? > That's because is 3 `mappend` 3 == 6 via addition? Or should it be 9 > via multiplication? Or something else? What should mempty be, 0? Or > maybe 1? Who is to decide what the only way of combining Ints > together is. > > It turns out there are instances for both of those cases, but you have > to wrap the int into a type so that it knows which way you want it to > be interpreted. > > import Data.Monoid > mempty == Just (Product 1) > > false > mempty == Just (Sum 1) > > false Yes, this is absolutely understandable. Except one detail: Prelude Data.Monoid Data.Maybe> mempty == Product 1 True Prelude Data.Monoid Data.Maybe> mempty == Just (Product 1) False so, "Product Int" as Monoid and "Maybe (Product Int)" as Monoid are totally different, - I understand what is Abel's groups on + and *, but I don't understand why GHC looks for Monoid instance for Int while Int is under Maybe... It will be right if: instance (Monoid a) => Monoid (Maybe a) where ... but is it true?! I suppose no such constraint on "a". Is it all due to defaults? Or I lost my brain at this night :) /Best regards, Paul > > There are similar monoidal instances for Bool, such as Any and All. > > On Wed, Jun 7, 2017 at 12:33 PM, Baa wrote: > > Maybe a is the Monoid: > > > > instance Monoid a => Monoid (Maybe a) -- Defined in ‘GHC.Base’ > > > > so I can compare its values with empty value: > > > > mempty == Nothing > > => True > > > > But if I try: > > > > mempty == Just 4 > > > > I get: > > > > :1:1: error: > > • Ambiguous type variable ‘a0’ arising from a use of ‘mempty’ > > prevents the constraint ‘(Monoid a0)’ from being solved. > > Probable fix: use a type annotation to specify what ‘a0’ > > should be. These potential instances exist: > > instance Monoid a => Monoid (IO a) -- Defined in > > ‘GHC.Base’ instance Monoid Ordering -- Defined in ‘GHC.Base’ > > instance Monoid a => Monoid (Maybe a) -- Defined in > > ‘GHC.Base’ ...plus 7 others > > (use -fprint-potential-instances to see them all) > > • In the first argument of ‘(==)’, namely ‘mempty’ > > In the expression: mempty == Just 4 > > In an equation for ‘it’: it = mempty == Just 4 > > > > OK, I try: > > > > mempty::Maybe Int > > > > and get: > > > > :1:1: error: > > • No instance for (Monoid Int) arising from a use of ‘mempty’ > > • In the expression: mempty :: Maybe Int > > In an equation for ‘it’: it = mempty :: Maybe Int > > > > so, how is related Int to Monoid, why does ghc expect from > > mempty::Maybe Int, Int to be Monoid?! As I understand, this means > > only that I mean "mempty" from (Maybe Int) type, which is Monoid > > and exists sure. > > > > Interesting is, that: > > > > mempty::Maybe [Int] > > => Nothing > > > > but how is related "monoidality" of "Maybe a" with "monoidality of > > "a" ??? > > > > Initial idea was to make comparison: > > > > mempty :: Maybe Int == Just 4 > > => False > > > > > > /Best regards, > > Paul > > _______________________________________________ > > 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 -- Best regards, Paul a.k.a. 6apcyk From toad3k at gmail.com Wed Jun 7 19:00:55 2017 From: toad3k at gmail.com (David McBride) Date: Wed, 7 Jun 2017 15:00:55 -0400 Subject: [Haskell-beginners] mempty and "No instance for (Monoid Int)" In-Reply-To: <20170607215336.288715ce@gmail.com> References: <20170607193352.0085b85a@Pavel> <20170607215336.288715ce@gmail.com> Message-ID: I glossed over the key fact > Maybe Int is only a Monoid if Int is an instance of Monoid This is derived from the Monoid instance of Maybe. instance Monoid a => Monoid (Maybe a) -- Defined in ‘GHC.Base’ Maybe is only an instance if a is an instance. If a isn't then Maybe isn't either, and it will be rejected. That is why Maybe Int is not a Monoid, but Maybe (Product Int) and Maybe () are. On Wed, Jun 7, 2017 at 2:53 PM, aquagnu wrote: >> In ghci there are type defaulting rules. When you go mempty == >> Nothing, it type defaults it to "Maybe ()". > > Aha, OK. These defaults are preset also in non-interactive: I tried the > same and get the same result. > >> But when you type Just 4, >> 4 is definitely not (), and so it looks at the Monoid instance for the >> a default type to use in cases of numeric literals, the first of which >> is Int. > > This I can not understand. Literal "4" is under "Just", so why are we > talking about "Int" as Monoid but not about "Maybe Int" as Monoid? And > "Maybe Int" as Monoid does not depend on Int and is the same for "Maybe > Int", "Maybe Bool", "Maybe String"... When I added type annotation, like > "::Maybe Int", I suppose, usual "Maybe a"'s implementations of > "mempty", "mappend" will be used, - no more defaults. Seems it is not > true, but why? > > >> >> Which brings you to the next problem. Maybe Int is only a Monoid if >> Int is an instance of Monoid, and Int is definitely not. >> > > I don't understand it. Monoid is "Maybe a" for any "a". And I can > understand your point if we are talking only for interactive GHCI and > its defaults, but when I tried in source code to write: > > m :: Maybe Int > m = mempty > ... > ... print $ Nothing == m > > i get the same, about no instance for (Monoid Int). But Maybe's "mempty" > is "Nothing", nothing else. And its "mappend" processes any (Just _) and > Nothing's, right? May be all magic is from defaults? > > >> That's because is 3 `mappend` 3 == 6 via addition? Or should it be 9 >> via multiplication? Or something else? What should mempty be, 0? Or >> maybe 1? Who is to decide what the only way of combining Ints >> together is. >> >> It turns out there are instances for both of those cases, but you have >> to wrap the int into a type so that it knows which way you want it to >> be interpreted. >> >> import Data.Monoid >> mempty == Just (Product 1) >> > false >> mempty == Just (Sum 1) >> > false > > Yes, this is absolutely understandable. Except one detail: > > Prelude Data.Monoid Data.Maybe> mempty == Product 1 > True > Prelude Data.Monoid Data.Maybe> mempty == Just (Product 1) > False > > so, "Product Int" as Monoid and "Maybe (Product Int)" as Monoid are totally > different, - I understand what is Abel's groups on + and *, but I don't > understand why GHC looks for Monoid instance for Int while Int is under > Maybe... It will be right if: > > instance (Monoid a) => Monoid (Maybe a) where > ... > > but is it true?! I suppose no such constraint on "a". Is it all due to > defaults? Or I lost my brain at this night :) > > > /Best regards, Paul > > >> >> There are similar monoidal instances for Bool, such as Any and All. >> >> On Wed, Jun 7, 2017 at 12:33 PM, Baa wrote: >> > Maybe a is the Monoid: >> > >> > instance Monoid a => Monoid (Maybe a) -- Defined in ‘GHC.Base’ >> > >> > so I can compare its values with empty value: >> > >> > mempty == Nothing >> > => True >> > >> > But if I try: >> > >> > mempty == Just 4 >> > >> > I get: >> > >> > :1:1: error: >> > • Ambiguous type variable ‘a0’ arising from a use of ‘mempty’ >> > prevents the constraint ‘(Monoid a0)’ from being solved. >> > Probable fix: use a type annotation to specify what ‘a0’ >> > should be. These potential instances exist: >> > instance Monoid a => Monoid (IO a) -- Defined in >> > ‘GHC.Base’ instance Monoid Ordering -- Defined in ‘GHC.Base’ >> > instance Monoid a => Monoid (Maybe a) -- Defined in >> > ‘GHC.Base’ ...plus 7 others >> > (use -fprint-potential-instances to see them all) >> > • In the first argument of ‘(==)’, namely ‘mempty’ >> > In the expression: mempty == Just 4 >> > In an equation for ‘it’: it = mempty == Just 4 >> > >> > OK, I try: >> > >> > mempty::Maybe Int >> > >> > and get: >> > >> > :1:1: error: >> > • No instance for (Monoid Int) arising from a use of ‘mempty’ >> > • In the expression: mempty :: Maybe Int >> > In an equation for ‘it’: it = mempty :: Maybe Int >> > >> > so, how is related Int to Monoid, why does ghc expect from >> > mempty::Maybe Int, Int to be Monoid?! As I understand, this means >> > only that I mean "mempty" from (Maybe Int) type, which is Monoid >> > and exists sure. >> > >> > Interesting is, that: >> > >> > mempty::Maybe [Int] >> > => Nothing >> > >> > but how is related "monoidality" of "Maybe a" with "monoidality of >> > "a" ??? >> > >> > Initial idea was to make comparison: >> > >> > mempty :: Maybe Int == Just 4 >> > => False >> > >> > >> > /Best regards, >> > Paul >> > _______________________________________________ >> > 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 > > > > -- > Best regards, > Paul a.k.a. 6apcyk > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From aquagnu at gmail.com Wed Jun 7 19:03:34 2017 From: aquagnu at gmail.com (aquagnu) Date: Wed, 7 Jun 2017 22:03:34 +0300 Subject: [Haskell-beginners] Alternative instance w/ additional restriction In-Reply-To: References: <04C0433B-3D6A-4DE9-ABEC-488EF59859AE@me.com> <20170525181027.1a74deff@Pavel> <20170525191150.51d8e3ac@Pavel> <20170525213703.54e8296a@gmail.com> <20170607152644.1bc47bc8@Pavel> <20170607190625.29dfb935@Pavel> Message-ID: <20170607220334.20747438@gmail.com> Thank you, David! > I honestly don't think so. But you can ask on haskell-cafe or on > stackoverflow if you like. There is a reasonable chance that a class > or library exists that already will do what you are looking for, just > that I haven't heard of it. > > On Wed, Jun 7, 2017 at 12:06 PM, Baa wrote: > > So, if I understood right, I'm trying to restrict instance more than > > class allows. And only way to accomplish it - is to create own class > > instead of Alternative which will not be based on > > Functor :: (* -> *) -> *, like Alternative. No other workarounds? > > > > > > > > В Wed, 7 Jun 2017 11:25:26 -0400 > > David McBride пишет: > > > >> The Alternative class says nothing about the a in MyData a. It > >> only represents code relevant to MyData. > >> > >> When you see class Applicative f => Alternative (f :: * -> *), that > >> means all of its functions had to work on any f, where f takes any > >> type and becomes some other type which could be anything. > >> > >> The reason it works for Monoid is that class Monoid a where implies > >> that a is completely known by the time the instance is fulfilled, > >> therefore the instance can look at what a ended up being and ensure > >> whatever a is, it must have this constraint on it. > >> > >> You can tell the difference because mempty returns a type that > >> mentions the a mentioned in the class, whereas empty returns an a > >> that is not mentioned in the class, therefore it has to work for > >> any a. > >> > >> On Wed, Jun 7, 2017 at 8:26 AM, Baa wrote: > >> > Hello all! > >> > > >> > If I try to write, for example: > >> > > >> > instance Alternative MyData where > >> > empty = NoMyData > >> > a <|> b = if a == b then ... > >> > > >> > I get error (see on bottom of the mail) sure, bcz I suppose > >> > something like: > >> > > >> > Eq a => (MyData a) > >> > > >> > All my attempts to add something to instance's `pure` signature > >> > have failed. How can I instantiate something with additional > >> > restrictions, like in this case? Or are there another solutions > >> > for such problem? > >> > > >> > Interesting is that MyData derives Eq itself! Which, I suppose, > >> > must means that "Eq (MyData a)", and if it's true than "Eq a" is > >> > true, because how "MyData a" can be Eq without to be "Eq a" (with > >> > *automatically deriving* of Eq instance) ?! > >> > > >> > By the way, for Monoid (which is "* -> Constraint") I can add > >> > "Eq a" constraint without problems: > >> > > >> > instance Eq a => Monoid (Origin a) where > >> > mempty = NoMyData > >> > mappend NoMyData a = a > >> > mappend a NoMyData = a > >> > mappend (MyData a) (MyData b)|a == b = MyData a > >> > |otherwise = NoMyData > >> > > >> > but not for Alternative, which is "(* -> *) -> Constraint". > >> > > >> > *ORIGINAL ERROR DUMP*: > >> > ====================== > >> > 42 16 error error: > >> > • No instance for (Eq a) arising > >> > from a use of ‘==’ Possible fix: > >> > add (Eq a) to the context of > >> > the type signature for: > >> > (<|>) :: Origin a -> > >> > Origin a -> Origin a • In the expression: a == b > >> > In the expression: if a == b > >> > then NoOrigin else NoOrigin In an equation for ‘<|>’: > >> > a <|> b = if a == b then > >> > NoOrigin else NoOrigin (intero) > >> > > >> > > >> > /Best regards > >> > Paul > >> > _______________________________________________ > >> > 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 > > > > _______________________________________________ > > 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 -- Best regards, Paul a.k.a. 6apcyk From aquagnu at gmail.com Wed Jun 7 20:05:06 2017 From: aquagnu at gmail.com (aquagnu) Date: Wed, 7 Jun 2017 23:05:06 +0300 Subject: [Haskell-beginners] mempty and "No instance for (Monoid Int)" In-Reply-To: References: <20170607193352.0085b85a@Pavel> <20170607215336.288715ce@gmail.com> Message-ID: <20170607230506.138de9cf@gmail.com> > I glossed over the key fact > > > Maybe Int is only a Monoid if Int is an instance of Monoid > > This is derived from the Monoid instance of Maybe. > > instance Monoid a => Monoid (Maybe a) -- Defined in ‘GHC.Base’ Ooohh... I see. Thank you a lot! No magic again :) /Best regards, Paul > > Maybe is only an instance if a is an instance. If a isn't then Maybe > isn't either, and it will be rejected. That is why Maybe Int is not a > Monoid, but Maybe (Product Int) and Maybe () are. > > > On Wed, Jun 7, 2017 at 2:53 PM, aquagnu wrote: > >> In ghci there are type defaulting rules. When you go mempty == > >> Nothing, it type defaults it to "Maybe ()". > > > > Aha, OK. These defaults are preset also in non-interactive: I tried > > the same and get the same result. > > > >> But when you type Just 4, > >> 4 is definitely not (), and so it looks at the Monoid instance for > >> the a default type to use in cases of numeric literals, the first > >> of which is Int. > > > > This I can not understand. Literal "4" is under "Just", so why are > > we talking about "Int" as Monoid but not about "Maybe Int" as > > Monoid? And "Maybe Int" as Monoid does not depend on Int and is the > > same for "Maybe Int", "Maybe Bool", "Maybe String"... When I added > > type annotation, like "::Maybe Int", I suppose, usual "Maybe a"'s > > implementations of "mempty", "mappend" will be used, - no more > > defaults. Seems it is not true, but why? > > > > > >> > >> Which brings you to the next problem. Maybe Int is only a Monoid > >> if Int is an instance of Monoid, and Int is definitely not. > >> > > > > I don't understand it. Monoid is "Maybe a" for any "a". And I can > > understand your point if we are talking only for interactive GHCI > > and its defaults, but when I tried in source code to write: > > > > m :: Maybe Int > > m = mempty > > ... > > ... print $ Nothing == m > > > > i get the same, about no instance for (Monoid Int). But Maybe's > > "mempty" is "Nothing", nothing else. And its "mappend" processes > > any (Just _) and Nothing's, right? May be all magic is from > > defaults? > > > > > >> That's because is 3 `mappend` 3 == 6 via addition? Or should it > >> be 9 via multiplication? Or something else? What should mempty > >> be, 0? Or maybe 1? Who is to decide what the only way of > >> combining Ints together is. > >> > >> It turns out there are instances for both of those cases, but you > >> have to wrap the int into a type so that it knows which way you > >> want it to be interpreted. > >> > >> import Data.Monoid > >> mempty == Just (Product 1) > >> > false > >> mempty == Just (Sum 1) > >> > false > > > > Yes, this is absolutely understandable. Except one detail: > > > > Prelude Data.Monoid Data.Maybe> mempty == Product 1 > > True > > Prelude Data.Monoid Data.Maybe> mempty == Just (Product 1) > > False > > > > so, "Product Int" as Monoid and "Maybe (Product Int)" as Monoid are > > totally different, - I understand what is Abel's groups on + and *, > > but I don't understand why GHC looks for Monoid instance for Int > > while Int is under Maybe... It will be right if: > > > > instance (Monoid a) => Monoid (Maybe a) where > > ... > > > > but is it true?! I suppose no such constraint on "a". Is it all due > > to defaults? Or I lost my brain at this night :) > > > > > > /Best regards, Paul > > > > > >> > >> There are similar monoidal instances for Bool, such as Any and All. > >> > >> On Wed, Jun 7, 2017 at 12:33 PM, Baa wrote: > >> > Maybe a is the Monoid: > >> > > >> > instance Monoid a => Monoid (Maybe a) -- Defined in ‘GHC.Base’ > >> > > >> > so I can compare its values with empty value: > >> > > >> > mempty == Nothing > >> > => True > >> > > >> > But if I try: > >> > > >> > mempty == Just 4 > >> > > >> > I get: > >> > > >> > :1:1: error: > >> > • Ambiguous type variable ‘a0’ arising from a use of > >> > ‘mempty’ prevents the constraint ‘(Monoid a0)’ from being solved. > >> > Probable fix: use a type annotation to specify what ‘a0’ > >> > should be. These potential instances exist: > >> > instance Monoid a => Monoid (IO a) -- Defined in > >> > ‘GHC.Base’ instance Monoid Ordering -- Defined in ‘GHC.Base’ > >> > instance Monoid a => Monoid (Maybe a) -- Defined in > >> > ‘GHC.Base’ ...plus 7 others > >> > (use -fprint-potential-instances to see them all) > >> > • In the first argument of ‘(==)’, namely ‘mempty’ > >> > In the expression: mempty == Just 4 > >> > In an equation for ‘it’: it = mempty == Just 4 > >> > > >> > OK, I try: > >> > > >> > mempty::Maybe Int > >> > > >> > and get: > >> > > >> > :1:1: error: > >> > • No instance for (Monoid Int) arising from a use of > >> > ‘mempty’ • In the expression: mempty :: Maybe Int > >> > In an equation for ‘it’: it = mempty :: Maybe Int > >> > > >> > so, how is related Int to Monoid, why does ghc expect from > >> > mempty::Maybe Int, Int to be Monoid?! As I understand, this means > >> > only that I mean "mempty" from (Maybe Int) type, which is Monoid > >> > and exists sure. > >> > > >> > Interesting is, that: > >> > > >> > mempty::Maybe [Int] > >> > => Nothing > >> > > >> > but how is related "monoidality" of "Maybe a" with "monoidality > >> > of "a" ??? > >> > > >> > Initial idea was to make comparison: > >> > > >> > mempty :: Maybe Int == Just 4 > >> > => False > >> > > >> > > >> > /Best regards, > >> > Paul > >> > _______________________________________________ > >> > 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 > > > > > > > > -- > > Best regards, > > Paul a.k.a. 6apcyk > > _______________________________________________ > > 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 -- Best regards, Paul a.k.a. 6apcyk From mlang at delysid.org Mon Jun 12 12:48:56 2017 From: mlang at delysid.org (Mario Lang) Date: Mon, 12 Jun 2017 14:48:56 +0200 Subject: [Haskell-beginners] 2d layout description? Message-ID: <87bmptgymf.fsf@fx.delysid.org> Hi. I am looking for a good method to describe 2-dimensional panels of various technical, mostly music-production related, devices. Motivation: I am blind and am looking for a future-proof solution to write down labels of jacks/knobs/switches on front/back panels of all the devices I use on a daily basis. Complex devices have so many options that you tend to forget the not-so-often used ones, hence, the need to have a reference "card" somewhere. This need has recently surfaced for me rather clearly as I have entered the realm of eurorack modular synthesizers as a hobby. One module is typicall 3U in either and between 2HP and 50HP in vertical size. And there are literally hundreds of these available these days. So while it becomes surprisingly easy to remember the jacks/knobs of regularily used modules after a rather short while, the need for some reference to go back to is unavoidable. Why is this on haskell-beginners? I am a haskell fan, and think this is a perfect job for a functional programming language. What I *want* is some sort of data format/DSL that makes it easy for me to describe the positions, functions and labels of physical interface elements. From that, I'd like to generate easily readable 2d ascii-diagram alike descriptions which would be particularily well fit to be read with a Braille display. Also, knowing the position/function of interface elements (jacks, knobs, switches) it would be neat if I could implement convenience functions on top of the known data, like the ability to calculate cable lengths for a particular patch, or even figuring out a module layout to minimize patch cable lengths given a list of possible patches. While browsing hackage, I found asciidiagrams, which is * pretty cool! * and might be useful to specify the layout However, I would have to fork and rewrite it to fit my actual needs, and it isn't clear if specifying the machine readable description like that wouldn't be a little bit too verbose. As an example, I have written down the layout of http://www.doepfer.de/A114.html (which admittably, is a rather simple module): +-------------+ | | | /-------\ | | | A-114 | | | |RingMod| | | \-------/ | | | | +--------+ | | | /----\ | | | | | X | | | | | |{i} | | | | | \----/ | | | | /----\ | | | | | Y | | | | | |{i} | | | | | \----/ | | | | /----\ | | | | |X*Y | | | | | |{o} | | | | | \----/ | | | +========+ | | | /----\ | | | | | X | | | | | |{i} | | | | | \----/ | | | | /----\ | | | | | Y | | | | | |{i} | | | | | \----/ | | | | /----\ | | | | |X*Y | | | | | |{o} | | | | | \----/ | | | +--------+ | | | +-------------+ This looks cool, but once I add all the tags I probably need (jack(in/out/in|out), rotary knob, n-way rotary, n-way switch, ...) this will probably grow into something quite cumbersome. A DSL might be better there, and somehow recunstruct a simple ascii diagram from that? In essence, I think I am trying to solve a rather general problem here, even though my actual use-case is specific to eurorack modules. Once I have an easily useable DSL, I will likely want to describe everything I own in this format, to be able to remember individual functions at a later day. And once I start to see this as a database (which is the main reason for wanting to move it from text files to a programming language) I can see the need to search for exact descriptions. For instance, I might find something with 7 RJ45 jacks in groups of 4 and 3, and would like to find the description for it without knowing the product name... Or search for a label of a key, without knowing on which remote it was... There are quite some possibilities here. I am basically asking for everything that comes to your mind, if you have read so far without having been bored to hell. Is there any library on hackage that might help? Do you know of similar projects with different goals? Anything else? TL;DR: I am looking for a DSL to describe physical interfaces in a form that makes it easy to make this information available to the blind in a very accessible way. Description files should be easy enough to maintain, to maybe even start a trend of a central repository to avoid people having to re-create them over and over again. The metadata should be detailed enough to allow for search/query operations on the universe of described hardware. -- CYa, ⡍⠁⠗⠊⠕ | Blog: GitHub: .''`. | Twitter: @blindbird23 FaceBook: disyled : :' : | SoundCloud: `. `' | YouTube: `- From nkurtov at gmail.com Wed Jun 14 18:52:32 2017 From: nkurtov at gmail.com (Nikolay Kurtov) Date: Wed, 14 Jun 2017 20:52:32 +0200 Subject: [Haskell-beginners] Non type-variable argument Message-ID: Hello everyone, Please help me compile the program without the -XFlexibleContexts extension. I don't understand the "Non type-variable argument" error message and googling does not shed any light on the problem. Any help is appreciated. % ghc --version The Glorious Glasgow Haskell Compilation System, version 7.10.3 % ghc orfest.hs orfest.hs:6:1: Non type-variable argument in the constraint: AM.MArray a (t, t, t, [i]) m (Use FlexibleContexts to permit this) When checking that ‘go’ has the inferred type go :: forall (m :: * -> *) t t1 t2 t3 (a :: * -> * -> *) i. (Read t, AM.Ix i, AM.MArray a (t, t1, t2, [i]) m) => a i (t, t1, t2, [i]) -> [[Char]] -> t3 -> i -> m (t3, i) This works: % ghc orfest.hs -XFlexibleContexts Regards, Orfest -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: orfest.hs Type: text/x-haskell Size: 1087 bytes Desc: not available URL: From vagercai at gmail.com Sun Jun 18 09:02:13 2017 From: vagercai at gmail.com (Choi Waikit) Date: Sun, 18 Jun 2017 17:02:13 +0800 Subject: [Haskell-beginners] Question regarding error messages Message-ID: Hi guys, I have difficulty understanding how GHC determines what kind of error message to return. Could you help explain a bit ? Thanks ! The code can be accessed here My question is Why does calling `settleDown 9` return different error message from `settleDown "sting"` ? Thanks, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Sun Jun 18 16:49:09 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 18 Jun 2017 18:49:09 +0200 Subject: [Haskell-beginners] Question regarding error messages In-Reply-To: References: Message-ID: <20170618164653.ubc5ufueswdutexd@x60s.casa> On Sun, Jun 18, 2017 at 05:02:13PM +0800, Choi Waikit wrote: > Hi guys, > > I have difficulty understanding how GHC determines what kind of error > message to return. Could you help explain a bit ? Thanks ! > > The code can be accessed here > > My question is > Why does calling `settleDown 9` return different error message from > `settleDown "sting"` ? Hello David, every time you write a number in a haskell source, it gets automagically wrapped in `fromInteger` (actually, `fromInteger` if there isn't a dot, `fromRational` otherwise). This is made to provide some kind of overloading. `fromInteger` has signature: λ> :t fromInteger fromInteger :: Num a => Integer -> a hence the different error with 9 and "string"! Is it clear now? From david.weijiecai at gmail.com Mon Jun 19 02:56:59 2017 From: david.weijiecai at gmail.com (David CAI) Date: Mon, 19 Jun 2017 10:56:59 +0800 Subject: [Haskell-beginners] Question regarding error messages In-Reply-To: <20170618164653.ubc5ufueswdutexd@x60s.casa> References: <20170618164653.ubc5ufueswdutexd@x60s.casa> Message-ID: Hi Francesco, Thanks for your reply! Just to make sure I understood, can I paraphrase your words as the following ? In the case of `settleDown 9` `settleDown 9` is first translated to `settleDown $ fromInteger 9`. Since fromInteger lies in Num type class and settleDown's signature is: settleDown :: Mood -> Mood, the compiler tries to look for an instance for Num typeclass so that it can resolve which `fromInteger` method to call. Therefore it doesn't show a type mismatch error but hint for implementing a typeclass. In the case of `settleDown "hello"` There's no preprocessing for "hello" so its type remains [Char]. Since settleDown has type Mood -> Mood, Mood and [Char] are not compatible, therefore the compiler shows a type mismatch error. Thanks, David On 19 June 2017 at 00:49, Francesco Ariis wrote: > On Sun, Jun 18, 2017 at 05:02:13PM +0800, Choi Waikit wrote: > > Hi guys, > > > > I have difficulty understanding how GHC determines what kind of error > > message to return. Could you help explain a bit ? Thanks ! > > > > The code can be accessed here > > > > My question is > > Why does calling `settleDown 9` return different error message from > > `settleDown "sting"` ? > > Hello David, > every time you write a number in a haskell source, it gets > automagically > wrapped in `fromInteger` (actually, `fromInteger` if there isn't a dot, > `fromRational` otherwise). This is made to provide some kind of > overloading. > > `fromInteger` has signature: > > λ> :t fromInteger > fromInteger :: Num a => Integer -> a > > hence the different error with 9 and "string"! > > Is it clear now? > _______________________________________________ > 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 Mon Jun 19 05:54:07 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Mon, 19 Jun 2017 07:54:07 +0200 Subject: [Haskell-beginners] Question regarding error messages In-Reply-To: References: <20170618164653.ubc5ufueswdutexd@x60s.casa> Message-ID: <20170619055407.2g5x3r2a2nukzhhx@x60s.casa> On Mon, Jun 19, 2017 at 10:56:59AM +0800, David CAI wrote: > Hi Francesco, > > Thanks for your reply! Just to make sure I understood, can I paraphrase > your words as the following ? > > In the case of `settleDown 9` > `settleDown 9` is first translated to `settleDown $ fromInteger 9`. Since > fromInteger lies in Num type class and settleDown's signature is: > settleDown :: Mood -> Mood, the compiler tries to look for > an instance for Num typeclass so that it can resolve which `fromInteger` > method to call. Therefore it doesn't show a type mismatch error but hint > for implementing a typeclass. > > In the case of `settleDown "hello"` > There's no preprocessing for "hello" so its type remains [Char]. Since > settleDown has type Mood -> Mood, Mood and [Char] are not compatible, > therefore the compiler shows a type mismatch error. Excellent explanation, that's exactly it! From silent.leaf0 at gmail.com Thu Jun 22 20:21:00 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Thu, 22 Jun 2017 22:21:00 +0200 Subject: [Haskell-beginners] Can i post code here for review and getting better? Message-ID: Hi, I'd like to know if this mailing list would be an appropriate place to post code and ask for review. The purpose would not be to help me do it, but to tell me how to do it better, more idiomatically, using more appropriate or powerful tools. If not, and even if yes, are there any other places where this might be appropriate? Are there haskell forums somewhere? mind you i just got the idea, so i'm gonna check, but maybe you all know which ones are better than others, or more active. Also, i've searched in vain for places where one could maybe get together into projects that would not require being fully fluent yet in haskell (with the will to learn and still some solid, yet relatively untested, bases), nor that would require getting updated on a projects of perhaps several thousands of more or less obscure code (for those that come from the outside *cough* operator maniacs *cough*). Otherwise, i'd also welcome ideas of very simple ideas of projects just to learn by doing. The idea would be to know how to do projects that actually do something, so usually there's some sort of contact with the exterior. Thanks verymuch in advance! -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael at schmong.org Thu Jun 22 22:38:44 2017 From: michael at schmong.org (Michael Litchard) Date: Thu, 22 Jun 2017 15:38:44 -0700 Subject: [Haskell-beginners] Can i post code here for review and getting better? In-Reply-To: References: Message-ID: I have received much help over the years from the haskell community. This is a good resource for your skill building. That said, consider also using the code review section of stack exchange. They give internet points as well. :) On Thu, Jun 22, 2017 at 1:21 PM, Silent Leaf wrote: > Hi, > I'd like to know if this mailing list would be an appropriate place to > post code and ask for review. The purpose would not be to help me do it, > but to tell me how to do it better, more idiomatically, using more > appropriate or powerful tools. > > If not, and even if yes, are there any other places where this might be > appropriate? Are there haskell forums somewhere? mind you i just got the > idea, so i'm gonna check, but maybe you all know which ones are better than > others, or more active. > > Also, i've searched in vain for places where one could maybe get together > into projects that would not require being fully fluent yet in haskell > (with the will to learn and still some solid, yet relatively untested, > bases), nor that would require getting updated on a projects of perhaps > several thousands of more or less obscure code (for those that come from > the outside *cough* operator maniacs *cough*). > > Otherwise, i'd also welcome ideas of very simple ideas of projects just to > learn by doing. The idea would be to know how to do projects that actually > do something, so usually there's some sort of contact with the exterior. > > Thanks verymuch in advance! > > _______________________________________________ > 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 michael at schmong.org Thu Jun 22 22:40:23 2017 From: michael at schmong.org (Michael Litchard) Date: Thu, 22 Jun 2017 15:40:23 -0700 Subject: [Haskell-beginners] Can i post code here for review and getting better? In-Reply-To: References: Message-ID: I strongly suggest you acquire the book "Haskell from First Principles" and do each and every exercise, and not move forward until you understand the subject matter you are faced with. Do that and you will be well on the way to expertise. On Thu, Jun 22, 2017 at 3:38 PM, Michael Litchard wrote: > I have received much help over the years from the haskell community. This > is a good resource for your skill building. That said, consider also using > the code review section of stack exchange. They give internet points as > well. :) > > On Thu, Jun 22, 2017 at 1:21 PM, Silent Leaf > wrote: > >> Hi, >> I'd like to know if this mailing list would be an appropriate place to >> post code and ask for review. The purpose would not be to help me do it, >> but to tell me how to do it better, more idiomatically, using more >> appropriate or powerful tools. >> >> If not, and even if yes, are there any other places where this might be >> appropriate? Are there haskell forums somewhere? mind you i just got the >> idea, so i'm gonna check, but maybe you all know which ones are better than >> others, or more active. >> >> Also, i've searched in vain for places where one could maybe get together >> into projects that would not require being fully fluent yet in haskell >> (with the will to learn and still some solid, yet relatively untested, >> bases), nor that would require getting updated on a projects of perhaps >> several thousands of more or less obscure code (for those that come from >> the outside *cough* operator maniacs *cough*). >> >> Otherwise, i'd also welcome ideas of very simple ideas of projects just >> to learn by doing. The idea would be to know how to do projects that >> actually do something, so usually there's some sort of contact with the >> exterior. >> >> Thanks verymuch in advance! >> >> _______________________________________________ >> 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 silent.leaf0 at gmail.com Thu Jun 22 23:58:52 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Fri, 23 Jun 2017 01:58:52 +0200 Subject: [Haskell-beginners] Can i post code here for review and getting better? In-Reply-To: References: Message-ID: That book seems very interesting, tho all is dependent on how useful the exercises are (otherwise i think i understand most of the *theory* of the concepts in the book, but applying them to real tasks is the problem). I'll look into it, thanks! Stack exchange code review seems great too! so, that's a yes for asking reviews of code around here too? 2017-06-23 0:40 GMT+02:00 Michael Litchard : > I strongly suggest you acquire the book "Haskell from First Principles" > and do each and every exercise, and not move forward until you understand > the subject matter you are faced with. Do that and you will be well on the > way to expertise. > > On Thu, Jun 22, 2017 at 3:38 PM, Michael Litchard > wrote: > >> I have received much help over the years from the haskell community. This >> is a good resource for your skill building. That said, consider also using >> the code review section of stack exchange. They give internet points as >> well. :) >> >> On Thu, Jun 22, 2017 at 1:21 PM, Silent Leaf >> wrote: >> >>> Hi, >>> I'd like to know if this mailing list would be an appropriate place to >>> post code and ask for review. The purpose would not be to help me do it, >>> but to tell me how to do it better, more idiomatically, using more >>> appropriate or powerful tools. >>> >>> If not, and even if yes, are there any other places where this might be >>> appropriate? Are there haskell forums somewhere? mind you i just got the >>> idea, so i'm gonna check, but maybe you all know which ones are better than >>> others, or more active. >>> >>> Also, i've searched in vain for places where one could maybe get >>> together into projects that would not require being fully fluent yet in >>> haskell (with the will to learn and still some solid, yet relatively >>> untested, bases), nor that would require getting updated on a projects of >>> perhaps several thousands of more or less obscure code (for those that come >>> from the outside *cough* operator maniacs *cough*). >>> >>> Otherwise, i'd also welcome ideas of very simple ideas of projects just >>> to learn by doing. The idea would be to know how to do projects that >>> actually do something, so usually there's some sort of contact with the >>> exterior. >>> >>> Thanks verymuch in advance! >>> >>> _______________________________________________ >>> 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 michael at schmong.org Fri Jun 23 00:35:30 2017 From: michael at schmong.org (Michael Litchard) Date: Thu, 22 Jun 2017 17:35:30 -0700 Subject: [Haskell-beginners] Can i post code here for review and getting better? In-Reply-To: References: Message-ID: That's a yes. :) On Thu, Jun 22, 2017 at 4:58 PM, Silent Leaf wrote: > That book seems very interesting, tho all is dependent on how useful the > exercises are (otherwise i think i understand most of the *theory* of the > concepts in the book, but applying them to real tasks is the problem). I'll > look into it, thanks! > > Stack exchange code review seems great too! > > so, that's a yes for asking reviews of code around here too? > > 2017-06-23 0:40 GMT+02:00 Michael Litchard : > >> I strongly suggest you acquire the book "Haskell from First Principles" >> and do each and every exercise, and not move forward until you understand >> the subject matter you are faced with. Do that and you will be well on the >> way to expertise. >> >> On Thu, Jun 22, 2017 at 3:38 PM, Michael Litchard >> wrote: >> >>> I have received much help over the years from the haskell community. >>> This is a good resource for your skill building. That said, consider also >>> using the code review section of stack exchange. They give internet points >>> as well. :) >>> >>> On Thu, Jun 22, 2017 at 1:21 PM, Silent Leaf >>> wrote: >>> >>>> Hi, >>>> I'd like to know if this mailing list would be an appropriate place to >>>> post code and ask for review. The purpose would not be to help me do it, >>>> but to tell me how to do it better, more idiomatically, using more >>>> appropriate or powerful tools. >>>> >>>> If not, and even if yes, are there any other places where this might be >>>> appropriate? Are there haskell forums somewhere? mind you i just got the >>>> idea, so i'm gonna check, but maybe you all know which ones are better than >>>> others, or more active. >>>> >>>> Also, i've searched in vain for places where one could maybe get >>>> together into projects that would not require being fully fluent yet in >>>> haskell (with the will to learn and still some solid, yet relatively >>>> untested, bases), nor that would require getting updated on a projects of >>>> perhaps several thousands of more or less obscure code (for those that come >>>> from the outside *cough* operator maniacs *cough*). >>>> >>>> Otherwise, i'd also welcome ideas of very simple ideas of projects just >>>> to learn by doing. The idea would be to know how to do projects that >>>> actually do something, so usually there's some sort of contact with the >>>> exterior. >>>> >>>> Thanks verymuch in advance! >>>> >>>> _______________________________________________ >>>> 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 >> >> > > _______________________________________________ > 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 tanuki at gmail.com Fri Jun 23 04:16:34 2017 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Thu, 22 Jun 2017 21:16:34 -0700 Subject: [Haskell-beginners] Can i post code here for review and getting better? In-Reply-To: References: Message-ID: /r/haskell on reddit, and its sister subs, are also a great resource. /r/haskellquestions might be best for review requests. On Jun 22, 2017 5:37 PM, "Michael Litchard" wrote: > That's a yes. :) > > On Thu, Jun 22, 2017 at 4:58 PM, Silent Leaf > wrote: > >> That book seems very interesting, tho all is dependent on how useful the >> exercises are (otherwise i think i understand most of the *theory* of the >> concepts in the book, but applying them to real tasks is the problem). I'll >> look into it, thanks! >> >> Stack exchange code review seems great too! >> >> so, that's a yes for asking reviews of code around here too? >> >> 2017-06-23 0:40 GMT+02:00 Michael Litchard : >> >>> I strongly suggest you acquire the book "Haskell from First Principles" >>> and do each and every exercise, and not move forward until you understand >>> the subject matter you are faced with. Do that and you will be well on the >>> way to expertise. >>> >>> On Thu, Jun 22, 2017 at 3:38 PM, Michael Litchard >>> wrote: >>> >>>> I have received much help over the years from the haskell community. >>>> This is a good resource for your skill building. That said, consider also >>>> using the code review section of stack exchange. They give internet points >>>> as well. :) >>>> >>>> On Thu, Jun 22, 2017 at 1:21 PM, Silent Leaf >>>> wrote: >>>> >>>>> Hi, >>>>> I'd like to know if this mailing list would be an appropriate place to >>>>> post code and ask for review. The purpose would not be to help me do it, >>>>> but to tell me how to do it better, more idiomatically, using more >>>>> appropriate or powerful tools. >>>>> >>>>> If not, and even if yes, are there any other places where this might >>>>> be appropriate? Are there haskell forums somewhere? mind you i just got the >>>>> idea, so i'm gonna check, but maybe you all know which ones are better than >>>>> others, or more active. >>>>> >>>>> Also, i've searched in vain for places where one could maybe get >>>>> together into projects that would not require being fully fluent yet in >>>>> haskell (with the will to learn and still some solid, yet relatively >>>>> untested, bases), nor that would require getting updated on a projects of >>>>> perhaps several thousands of more or less obscure code (for those that come >>>>> from the outside *cough* operator maniacs *cough*). >>>>> >>>>> Otherwise, i'd also welcome ideas of very simple ideas of projects >>>>> just to learn by doing. The idea would be to know how to do projects that >>>>> actually do something, so usually there's some sort of contact with the >>>>> exterior. >>>>> >>>>> Thanks verymuch in advance! >>>>> >>>>> _______________________________________________ >>>>> 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 >>> >>> >> >> _______________________________________________ >> 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 alarreine at gmail.com Fri Jun 23 07:22:11 2017 From: alarreine at gmail.com (Agustin Larreinegabe) Date: Fri, 23 Jun 2017 09:22:11 +0200 Subject: [Haskell-beginners] help designing types for a gsl fit Message-ID: Hello, I'm trying to install an application Termite - Debug but I get this error in line 929:14 when it try to do this lprog <- G.labelNew Nothing The error says: Could not deduce (glib-0.13.4.1:System.Glib.UTFString.GlibString string0) arising from a use of ‘G.labelNew’ from the context (D.Rel c v a s) bound by the type signature for sourceWindowCreate :: D.Rel c v a s => RSourceView c a u -> IO G.Widget at Debug/SourceView.hs:913:23-73 instance glib-0.13.4.1:System.Glib.UTFString.GlibString [Char] -- Defined in ‘glib-0.13.4.1:System.Glib.UTFString’ In a stmt of a 'do' block: lprog <- G.labelNew Nothing In the expression: do { vbox <- G.vBoxNew False 0; G.widgetShow vbox; spec <- getIORef svInputSpec ref; code <- codeWinNew spec; .... } In an equation for ‘sourceWindowCreate’: sourceWindowCreate ref = do { vbox <- G.vBoxNew False 0; G.widgetShow vbox; spec <- getIORef svInputSpec ref; cabal: Error: some packages failed to install: I really don't know how to proceed, I'm new with Haskell Thanks in advance. ----------------- Agustin Larreinegabe -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Fri Jun 23 13:58:35 2017 From: toad3k at gmail.com (David McBride) Date: Fri, 23 Jun 2017 09:58:35 -0400 Subject: [Haskell-beginners] help designing types for a gsl fit In-Reply-To: References: Message-ID: If you look at the type of labelNew GlibString string => Maybe string -> IO Label If you look at the instances for GlibString, they could be Text or [Char]. You have to decide which. The fact that you are using Nothing does not tell you the entire final type. It could be Maybe [Char], or Maybe Text. Even though the choice seems arbitrary in this instance, you have to decide which it is. So try this. lprog <- G.labelNew (Nothing :: Maybe [Char]) On Fri, Jun 23, 2017 at 3:22 AM, Agustin Larreinegabe wrote: > Hello, > I'm trying to install an application Termite - Debug but I get this error in > line 929:14 > > when it try to do this > > > > lprog <- G.labelNew Nothing > > > The error says: > > Could not deduce (glib-0.13.4.1:System.Glib.UTFString.GlibString string0) > arising from a use of ‘G.labelNew’ from the context (D.Rel c v a s) bound by > the type signature for sourceWindowCreate :: D.Rel c v a s => RSourceView c > a u -> IO G.Widget at Debug/SourceView.hs:913:23-73 instance > glib-0.13.4.1:System.Glib.UTFString.GlibString [Char] -- Defined in > ‘glib-0.13.4.1:System.Glib.UTFString’ In a stmt of a 'do' block: lprog <- > G.labelNew Nothing In the expression: do { vbox <- G.vBoxNew False 0; > G.widgetShow vbox; spec <- getIORef svInputSpec ref; code <- codeWinNew > spec; .... } In an equation for ‘sourceWindowCreate’: sourceWindowCreate ref > = do { vbox <- G.vBoxNew False 0; G.widgetShow vbox; spec <- getIORef > svInputSpec ref; cabal: Error: some packages failed to install: > > I really don't know how to proceed, I'm new with Haskell > > > Thanks in advance. > > > ----------------- > Agustin Larreinegabe > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From silent.leaf0 at gmail.com Fri Jun 23 14:24:07 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Fri, 23 Jun 2017 16:24:07 +0200 Subject: [Haskell-beginners] What to use when you need random values? Message-ID: Hi, I've had trouble finding the best way(s) to use random values in haskell, as it seems like there are several modules that either do the same thing or reuse one another i'm not sure. There is System.Random - is it better to use the streams random(R)s or a more imperative randomRIO? - is it better to use mkStdGen or newStdGen or getStdGen? There is Test.QuickCheck and its type(class?) Gen There is a module in Control.Monad (i think) which exports the type Rnd What about performances, and all those options? What do you like to use with random numbers? I know that's a lot of questions. feel free to only answer to a few of them. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Fri Jun 23 15:10:05 2017 From: toad3k at gmail.com (David McBride) Date: Fri, 23 Jun 2017 11:10:05 -0400 Subject: [Haskell-beginners] What to use when you need random values? In-Reply-To: References: Message-ID: When you are unsure about the differences between functions, it can be good to read the haddocks for the library. http://hackage.haskell.org/package/random-1.1/docs/System-Random.html The standard haskell random library supports the idea of splitting a seed randomly. You take one seed and split it, and now you have two seeds, which will each generate different randoms independently. getStdGen gets the current global seed. newStdGen splits new a seed off of the current global seed. mkStdGen allows you to create a seed from a value so that you can get the same set of randoms repeatedly. I would say if you are in IO, just use randomRIO. If you are in monadic code that not IO at its base, you should use MonadRandom library on hackage. Quickcheck randomness is only really used in quickcheck, although it is probably based off the standard libraries. Just keep in mind that randomness is a concept that is a little hard to wrap your head around in haskell until you've been using it a little while. On Fri, Jun 23, 2017 at 10:24 AM, Silent Leaf wrote: > Hi, > I've had trouble finding the best way(s) to use random values in haskell, as > it seems like there are several modules that either do the same thing or > reuse one another i'm not sure. > > There is System.Random > - is it better to use the streams random(R)s or a more imperative randomRIO? > - is it better to use mkStdGen or newStdGen or getStdGen? > There is Test.QuickCheck and its type(class?) Gen > There is a module in Control.Monad (i think) which exports the type Rnd > > What about performances, and all those options? What do you like to use with > random numbers? > > I know that's a lot of questions. feel free to only answer to a few of them. > :) > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From frederic-emmanuel.picca at synchrotron-soleil.fr Sat Jun 24 13:47:44 2017 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Sat, 24 Jun 2017 13:47:44 +0000 Subject: [Haskell-beginners] which typefor this FFI call Message-ID: Hello I would like to create a binding for this function [1]. herr_t H5Literate( hid_t group_id, H5_index_t index_type, H5_iter_order_t order, hsize_t *idx, H5L_iterate_t op, void *op_data ) My "only" problem is with the op and op_data part. Here the C op signature[2] op -> herr_t (*H5L_iterate_t)( hid_t g_id, const char *name, const H5L_info_t *info, void *op_data) What I would like to do is to create an Haskell function which allows to return what is contained under the op_data. What I understand from this is that I give the H5Literate function an op function which is executed for each group of my hdf5 file. So the op method is called with the releavant parameters. The op_data can be use to accumulate things during the traversal. H5Literate :: Hid -> Index -> Order -> Maybe HSize -> H5Iterate -> _ -> _ type H5Iterate = Hid -> ByteString -> Info -> _ -> _ So it seems to me that I need to use a State inorder to do the accumulation. For exemple,I want to collect each group names and accumulate then in a list. Somy questioniswhat should be the signature of both function. I have also the fealing that the return type MUST have a Storableinstance. Thanks for your help Frederic [1] https://support.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Iterate [2] https://support.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Visit From silent.leaf0 at gmail.com Mon Jun 26 05:35:09 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Mon, 26 Jun 2017 07:35:09 +0200 Subject: [Haskell-beginners] R/W from/to partitions (on linux) Message-ID: Hi, I'd like to be able to read and write from/to partitions directly. I've had trouble with the documentation (honestly i can't find anything, and any mention of partitions leads to mathematical partitioning of lists or whatever). I obviously would need to be able to write or read from a specific position in the partition. Mind you that would be good too for files (that is, being able to read/write from a specific position in it) since i plan on making disk images. Thanks in advance! -------------- next part -------------- An HTML attachment was scrubbed... URL: From sylvain at haskus.fr Mon Jun 26 05:51:41 2017 From: sylvain at haskus.fr (Sylvain Henry) Date: Mon, 26 Jun 2017 07:51:41 +0200 Subject: [Haskell-beginners] R/W from/to partitions (on linux) In-Reply-To: References: Message-ID: Hi, It is not Haskell specific. You just have to read from the partition device special file (e.g., something like /dev/sdb2) as you would do with a normal file. You must have the permission to do so (e.g., be root). Be careful as you can destroy your system if you write something incorrect in your partitions. Repositioning handles: https://www.stackage.org/haddock/lts-8.20/base-4.9.1.0/System-IO.html#g:13 Read/write: https://www.stackage.org/haddock/lts-8.20/base-4.9.1.0/System-IO.html#v:hPutBuf Sylvain On 26/06/2017 07:35, Silent Leaf wrote: > Hi, > > I'd like to be able to read and write from/to partitions directly. > I've had trouble with the documentation (honestly i can't find > anything, and any mention of partitions leads to mathematical > partitioning of lists or whatever). > > I obviously would need to be able to write or read from a specific > position in the partition. Mind you that would be good too for files > (that is, being able to read/write from a specific position in it) > since i plan on making disk images. > > Thanks in advance! > > > _______________________________________________ > 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 silent.leaf0 at gmail.com Mon Jun 26 05:57:01 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Mon, 26 Jun 2017 07:57:01 +0200 Subject: [Haskell-beginners] R/W from/to partitions (on linux) In-Reply-To: References: Message-ID: Darn quick answer! Thanks Sylvain, that may be all i need to start! 2017-06-26 7:51 GMT+02:00 Sylvain Henry : > Hi, > > It is not Haskell specific. You just have to read from the partition > device special file (e.g., something like /dev/sdb2) as you would do with a > normal file. You must have the permission to do so (e.g., be root). Be > careful as you can destroy your system if you write something incorrect in > your partitions. > > Repositioning handles: https://www.stackage.org/ > haddock/lts-8.20/base-4.9.1.0/System-IO.html#g:13 > > Read/write: https://www.stackage.org/haddock/lts-8.20/base-4.9.1.0/ > System-IO.html#v:hPutBuf > > Sylvain > > On 26/06/2017 07:35, Silent Leaf wrote: > > Hi, > > I'd like to be able to read and write from/to partitions directly. I've > had trouble with the documentation (honestly i can't find anything, and any > mention of partitions leads to mathematical partitioning of lists or > whatever). > > I obviously would need to be able to write or read from a specific > position in the partition. Mind you that would be good too for files (that > is, being able to read/write from a specific position in it) since i plan > on making disk images. > > Thanks in advance! > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://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 sylvain at haskus.fr Mon Jun 26 06:18:08 2017 From: sylvain at haskus.fr (Sylvain Henry) Date: Mon, 26 Jun 2017 08:18:08 +0200 Subject: [Haskell-beginners] which typefor this FFI call In-Reply-To: References: Message-ID: <830739f6-c249-fde2-a549-3b02bd2e2ef2@haskus.fr> Hi, I would use IORef and StablePtr: import Foreign.StablePtr import Foreign.Ptr import Data.IORef type H5Iterate = Hid -> CString -> Ptr () -> Ptr () -> IO () -- see https://wiki.haskell.org/Foreign_Function_Interface#Function_pointers foreign import ccall "wrapper" mkOp :: H5Iterate -> FunPtr (H5Iterate) foreign import ccall "H5Lvisit" h5iterate :: Hid -> Index -> Order -> FunPtr H5Iterate -> Ptr () -> IO () main = do state <- newIORef [] statePtr <- newStablePtr state let callback :: H5Iterate callback hid name infoptr dataptr = do -- get the state stRef <- deRefStablePtr (castPtrToStablePtr dataptr) st <- readIORef stRef -- compute the new state newSt <- ... -- store the new state writeIORef stRef newSt h5iterate gid idttyp order (mkOp callback) (castStablePtrToPtr statePtr) -- retrieve the final state finalState <- readIORef state - Sylvain On 24/06/2017 15:47, PICCA Frederic-Emmanuel wrote: > Hello > > I would like to create a binding for this function [1]. > > herr_t H5Literate( hid_t group_id, H5_index_t index_type, H5_iter_order_t order, hsize_t *idx, H5L_iterate_t op, void *op_data ) > > My "only" problem is with the op and op_data part. > Here the C op signature[2] > > op -> herr_t (*H5L_iterate_t)( hid_t g_id, const char *name, const H5L_info_t *info, void *op_data) > > What I would like to do is to create an Haskell function which allows to return what is contained under the op_data. > What I understand from this is that I give the H5Literate function an op function which is executed for each group of my hdf5 file. > So the op method is called with the releavant parameters. > The op_data can be use to accumulate things during the traversal. > > H5Literate :: Hid -> Index -> Order -> Maybe HSize -> H5Iterate -> _ -> _ > > type H5Iterate = Hid -> ByteString -> Info -> _ -> _ > > So it seems to me that I need to use a State inorder to do the accumulation. > > For exemple,I want to collect each group names and accumulate then in a list. > > Somy questioniswhat should be the signature of both function. > > I have also the fealing that the return type MUST have a Storableinstance. > > > Thanks for your help > > Frederic > > > [1] https://support.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Iterate > [2] https://support.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Visit > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From sylvain at haskus.fr Mon Jun 26 06:33:44 2017 From: sylvain at haskus.fr (Sylvain Henry) Date: Mon, 26 Jun 2017 08:33:44 +0200 Subject: [Haskell-beginners] which typefor this FFI call In-Reply-To: <830739f6-c249-fde2-a549-3b02bd2e2ef2@haskus.fr> References: <830739f6-c249-fde2-a549-3b02bd2e2ef2@haskus.fr> Message-ID: <46ecc981-a136-705b-48fc-93d512016a92@haskus.fr> On 26/06/2017 08:18, Sylvain Henry wrote: > Hi, > > I would use IORef and StablePtr: > > import Foreign.StablePtr > import Foreign.Ptr > import Data.IORef > > type H5Iterate = Hid -> CString -> Ptr () -> Ptr () -> IO () > > -- see > https://wiki.haskell.org/Foreign_Function_Interface#Function_pointers > foreign import ccall "wrapper" mkOp :: H5Iterate -> FunPtr (H5Iterate) > > foreign import ccall "H5Lvisit" h5iterate :: Hid -> Index -> Order -> > FunPtr H5Iterate -> Ptr () -> IO () > > main = do > state <- newIORef [] > statePtr <- newStablePtr state > > let > callback :: H5Iterate > callback hid name infoptr dataptr = do > -- get the state > stRef <- deRefStablePtr (castPtrToStablePtr dataptr) > st <- readIORef stRef > -- compute the new state > newSt <- ... > -- store the new state > writeIORef stRef newSt > > h5iterate gid idttyp order (mkOp callback) (castStablePtrToPtr > statePtr) > Don't forget to: freeStablePtr statePtr > -- retrieve the final state > finalState <- readIORef state > > > - Sylvain > > > On 24/06/2017 15:47, PICCA Frederic-Emmanuel wrote: >> Hello >> >> I would like to create a binding for this function [1]. >> >> herr_t H5Literate( hid_t group_id, H5_index_t index_type, >> H5_iter_order_t order, hsize_t *idx, H5L_iterate_t op, void *op_data ) >> >> My "only" problem is with the op and op_data part. >> Here the C op signature[2] >> >> op -> herr_t (*H5L_iterate_t)( hid_t g_id, const char *name, const >> H5L_info_t *info, void *op_data) >> >> What I would like to do is to create an Haskell function which allows >> to return what is contained under the op_data. >> What I understand from this is that I give the H5Literate function an >> op function which is executed for each group of my hdf5 file. >> So the op method is called with the releavant parameters. >> The op_data can be use to accumulate things during the traversal. >> >> H5Literate :: Hid -> Index -> Order -> Maybe HSize -> H5Iterate -> _ >> -> _ >> >> type H5Iterate = Hid -> ByteString -> Info -> _ -> _ >> >> So it seems to me that I need to use a State inorder to do the >> accumulation. >> >> For exemple,I want to collect each group names and accumulate then in >> a list. >> >> Somy questioniswhat should be the signature of both function. >> >> I have also the fealing that the return type MUST have a >> Storableinstance. >> >> >> Thanks for your help >> >> Frederic >> >> >> [1] https://support.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Iterate >> [2] https://support.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Visit >> _______________________________________________ >> 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 From frederic-emmanuel.picca at synchrotron-soleil.fr Mon Jun 26 06:51:48 2017 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Mon, 26 Jun 2017 06:51:48 +0000 Subject: [Haskell-beginners] which typefor this FFI call In-Reply-To: <830739f6-c249-fde2-a549-3b02bd2e2ef2@haskus.fr> References: , <830739f6-c249-fde2-a549-3b02bd2e2ef2@haskus.fr> Message-ID: Thanks a lot Sylvain, I will try this as soon as possible. Frédéric From silent.leaf0 at gmail.com Mon Jun 26 08:35:56 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Mon, 26 Jun 2017 10:35:56 +0200 Subject: [Haskell-beginners] R/W from/to partitions (on linux) In-Reply-To: References: Message-ID: i'm reading on the doc of BS.Lazy.hGetContents: "Once EOF is encountered, the Handle is closed." what does that imply if i'm using it inside of withFile? no risk of getting prematurely out of the function right? that doesn seem possible in a pure function but i'm asking either way. if say i do something that reads the whole file, say calculating its length, does it mean since EOF will be reached i'll have to open the file again? i think i'm a bit lost... i'm trying to find how to read big chunks of two files, do stuff with each pair of chunk, and so on till the EOF, which may or may not happen at the same time for both... i don't really know how lazy bytestrings handle, for example, taking too much from a file. one way would be to calculate the length, ofc, but for files (partition) of several dozens of gigabytes, it's a bit delicate... the ideal would be to get the length from the system itself rather than calculate the whole string ... 2017-06-26 7:57 GMT+02:00 Silent Leaf : > Darn quick answer! Thanks Sylvain, that may be all i need to start! > > 2017-06-26 7:51 GMT+02:00 Sylvain Henry : > >> Hi, >> >> It is not Haskell specific. You just have to read from the partition >> device special file (e.g., something like /dev/sdb2) as you would do with a >> normal file. You must have the permission to do so (e.g., be root). Be >> careful as you can destroy your system if you write something incorrect in >> your partitions. >> >> Repositioning handles: https://www.stackage.org/haddo >> ck/lts-8.20/base-4.9.1.0/System-IO.html#g:13 >> >> Read/write: https://www.stackage.org/haddock/lts-8.20/base-4.9.1.0/Syste >> m-IO.html#v:hPutBuf >> >> Sylvain >> >> On 26/06/2017 07:35, Silent Leaf wrote: >> >> Hi, >> >> I'd like to be able to read and write from/to partitions directly. I've >> had trouble with the documentation (honestly i can't find anything, and any >> mention of partitions leads to mathematical partitioning of lists or >> whatever). >> >> I obviously would need to be able to write or read from a specific >> position in the partition. Mind you that would be good too for files (that >> is, being able to read/write from a specific position in it) since i plan >> on making disk images. >> >> Thanks in advance! >> >> >> _______________________________________________ >> Beginners mailing listBeginners at haskell.orghttp://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 silent.leaf0 at gmail.com Mon Jun 26 08:38:25 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Mon, 26 Jun 2017 10:38:25 +0200 Subject: [Haskell-beginners] R/W from/to partitions (on linux) In-Reply-To: References: Message-ID: also what happens to the result of Lazy.hGetContents after i close the handle i used for accessing the file content? can i still browse the part of th file cached? will there be an exception? it does not seem to be the case from tests on GHCI but then... 2017-06-26 10:35 GMT+02:00 Silent Leaf : > i'm reading on the doc of BS.Lazy.hGetContents: > "Once EOF is encountered, the Handle is closed." > > what does that imply if i'm using it inside of withFile? no risk of > getting prematurely out of the function right? that doesn seem possible in > a pure function but i'm asking either way. > if say i do something that reads the whole file, say calculating its > length, does it mean since EOF will be reached i'll have to open the file > again? i think i'm a bit lost... > > i'm trying to find how to read big chunks of two files, do stuff with each > pair of chunk, and so on till the EOF, which may or may not happen at the > same time for both... i don't really know how lazy bytestrings handle, for > example, taking too much from a file. one way would be to calculate the > length, ofc, but for files (partition) of several dozens of gigabytes, it's > a bit delicate... the ideal would be to get the length from the system > itself rather than calculate the whole string ... > > 2017-06-26 7:57 GMT+02:00 Silent Leaf : > >> Darn quick answer! Thanks Sylvain, that may be all i need to start! >> >> 2017-06-26 7:51 GMT+02:00 Sylvain Henry : >> >>> Hi, >>> >>> It is not Haskell specific. You just have to read from the partition >>> device special file (e.g., something like /dev/sdb2) as you would do with a >>> normal file. You must have the permission to do so (e.g., be root). Be >>> careful as you can destroy your system if you write something incorrect in >>> your partitions. >>> >>> Repositioning handles: https://www.stackage.org/haddo >>> ck/lts-8.20/base-4.9.1.0/System-IO.html#g:13 >>> >>> Read/write: https://www.stackage.org/haddock/lts-8.20/base-4.9.1.0/Syste >>> m-IO.html#v:hPutBuf >>> >>> Sylvain >>> >>> On 26/06/2017 07:35, Silent Leaf wrote: >>> >>> Hi, >>> >>> I'd like to be able to read and write from/to partitions directly. I've >>> had trouble with the documentation (honestly i can't find anything, and any >>> mention of partitions leads to mathematical partitioning of lists or >>> whatever). >>> >>> I obviously would need to be able to write or read from a specific >>> position in the partition. Mind you that would be good too for files (that >>> is, being able to read/write from a specific position in it) since i plan >>> on making disk images. >>> >>> Thanks in advance! >>> >>> >>> _______________________________________________ >>> Beginners mailing listBeginners at haskell.orghttp://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 steffenomak at gmail.com Mon Jun 26 08:42:43 2017 From: steffenomak at gmail.com (Stefan Risberg) Date: Mon, 26 Jun 2017 10:42:43 +0200 Subject: [Haskell-beginners] R/W from/to partitions (on linux) In-Reply-To: References: Message-ID: I would use some streaming library instead of lazy bytestring to keep memory at reasonably low levels. It will also help with reading chunks, and then composing actions on it. For library need you got: conduits, iostreams and pipes On 26 Jun. 2017 10:37, "Silent Leaf" wrote: i'm reading on the doc of BS.Lazy.hGetContents: "Once EOF is encountered, the Handle is closed." what does that imply if i'm using it inside of withFile? no risk of getting prematurely out of the function right? that doesn seem possible in a pure function but i'm asking either way. if say i do something that reads the whole file, say calculating its length, does it mean since EOF will be reached i'll have to open the file again? i think i'm a bit lost... i'm trying to find how to read big chunks of two files, do stuff with each pair of chunk, and so on till the EOF, which may or may not happen at the same time for both... i don't really know how lazy bytestrings handle, for example, taking too much from a file. one way would be to calculate the length, ofc, but for files (partition) of several dozens of gigabytes, it's a bit delicate... the ideal would be to get the length from the system itself rather than calculate the whole string ... 2017-06-26 7:57 GMT+02:00 Silent Leaf : > Darn quick answer! Thanks Sylvain, that may be all i need to start! > > 2017-06-26 7:51 GMT+02:00 Sylvain Henry : > >> Hi, >> >> It is not Haskell specific. You just have to read from the partition >> device special file (e.g., something like /dev/sdb2) as you would do with a >> normal file. You must have the permission to do so (e.g., be root). Be >> careful as you can destroy your system if you write something incorrect in >> your partitions. >> >> Repositioning handles: https://www.stackage.org/haddo >> ck/lts-8.20/base-4.9.1.0/System-IO.html#g:13 >> >> Read/write: https://www.stackage.org/haddock/lts-8.20/base-4.9.1.0/Syste >> m-IO.html#v:hPutBuf >> >> Sylvain >> >> On 26/06/2017 07:35, Silent Leaf wrote: >> >> Hi, >> >> I'd like to be able to read and write from/to partitions directly. I've >> had trouble with the documentation (honestly i can't find anything, and any >> mention of partitions leads to mathematical partitioning of lists or >> whatever). >> >> I obviously would need to be able to write or read from a specific >> position in the partition. Mind you that would be good too for files (that >> is, being able to read/write from a specific position in it) since i plan >> on making disk images. >> >> Thanks in advance! >> >> >> _______________________________________________ >> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> >> _______________________________________________ >> 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 mike_k_houghton at yahoo.co.uk Mon Jun 26 09:18:06 2017 From: mike_k_houghton at yahoo.co.uk (mike h) Date: Mon, 26 Jun 2017 09:18:06 +0000 (UTC) Subject: [Haskell-beginners] What to use when you need random values? In-Reply-To: References: Message-ID: <1681965374.3354616.1498468686696@mail.yahoo.com> This post is a useful discussion on randomness . Abstract Nonsense | | | Abstract Nonsense | | | On Friday, 23 June 2017, 16:11, David McBride wrote: When you are unsure about the differences between functions, it can be good to read the haddocks for the library. http://hackage.haskell.org/package/random-1.1/docs/System-Random.html The standard haskell random library supports the idea of splitting a seed randomly.  You take one seed and split it, and now you  have two seeds, which will each generate different randoms independently. getStdGen gets the current global seed.  newStdGen splits new a seed off of the current global seed.  mkStdGen allows you to create a seed from a value so that you can get the same set of randoms repeatedly. I would say if you are in IO, just use randomRIO.  If you are in monadic code that not IO at its base, you should use MonadRandom library on hackage.  Quickcheck randomness is only really used in quickcheck, although it is probably based off the standard libraries. Just keep in mind that randomness is a concept that is a little hard to wrap your head around in haskell until you've been using it a little while. On Fri, Jun 23, 2017 at 10:24 AM, Silent Leaf wrote: > Hi, > I've had trouble finding the best way(s) to use random values in haskell, as > it seems like there are several modules that either do the same thing or > reuse one another i'm not sure. > > There is System.Random > - is it better to use the streams random(R)s or a more imperative randomRIO? > - is it better to use mkStdGen or newStdGen or getStdGen? > There is Test.QuickCheck and its type(class?) Gen > There is a module in Control.Monad (i think) which exports the type Rnd > > What about performances, and all those options? What do you like to use with > random numbers? > > I know that's a lot of questions. feel free to only answer to a few of them. > :) > > _______________________________________________ > 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 patrick.browne at dit.ie Mon Jun 26 09:38:10 2017 From: patrick.browne at dit.ie (PATRICK BROWNE) Date: Mon, 26 Jun 2017 10:38:10 +0100 Subject: [Haskell-beginners] Improve my lambda expressions Message-ID: The code below provides a distance function that works for points and moving point. I am happy with the result, but I have a problem with the lambda expressions. Instead of supplying an argument to each 'mpXX', is it possible to have a single lambda argument on the entire final 'md' function? (e.g. 'md 2') Thanks in advance, Pat data Point a = Point { abscissa :: a, ordinate :: a } deriving Show dist a b = sqrt (((abscissa a) - (abscissa b))^2 + ((ordinate a) - (ordinate b))^2) -- Sttic points p1, p2 :: Point Float p1 = Point 0.0 0.0 p2 = Point 4.0 4.0 d = dist p1 p2 -- Moving points mp1, mp2 :: Point Float mp1x = (\t -> 4.0 + 0.5 * t) mp1y = (\t -> 4.0 - 0.5 * t) mp1 = Point (mp1x 2) (mp1y 2) mp2x = (\t -> 0.0 + 1.0 * t) mp2y = (\t -> 0.0 - 1.0 * t) mp2 = Point (mp2x 2) (mp2y 2) md = dist mp1 mp2 -- This email originated from DIT. If you received this email in error, please delete it from your system. Please note that if you are not the named addressee, disclosing, copying, distributing or taking any action based on the contents of this email or attachments is prohibited. www.dit.ie Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa ríomhphost nó sna hiatáin seo. www.dit.ie Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to Grangegorman -------------- next part -------------- An HTML attachment was scrubbed... URL: From silent.leaf0 at gmail.com Mon Jun 26 10:37:01 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Mon, 26 Jun 2017 12:37:01 +0200 Subject: [Haskell-beginners] Improve my lambda expressions In-Reply-To: References: Message-ID: yes you can, it's actually better to encapsulate all "lambdas" and intermediate values inside one function, provided you never use them anywhere else. i advise using "where" as such: md n = dist (Point (fx n) (fy n)) (Point (gx n) (gy n)) where fx n = 4.0 + 0.5 * n fy n = 4.0 - 0.5 * n gx n = n * 1.0 gy n = n * (-1.0) -- then you can call "foo = md 2" it's more idiomatic to use where, i believe. however you can also choose to define the helpers before the expression defining the function, using "let ... in" like that: md n = let fx n = 4.0 + 0.5 * n fy n = 4.0 - 0.5 * n gx n = n * 1.0 gy n = n * (-1.0) in dist (Point (fx n) (fy n)) (Point (gx n) (gy n)) be careful about the alignment. both ways are (in this example) strictly equivalent, it all depends on circumstances and taste. mind you if you don't want a function to be reused, merely one single value foo = md 2, you can always just write directly: foo = dist (Point (fx 2) (fy 2)) (Point (gx 2) (gy 2)) where fx n = 4.0 + 0.5 * n fy n = 4.0 - 0.5 * n gx n = n * 1.0 gy n = n * (-1.0) 2017-06-26 11:38 GMT+02:00 PATRICK BROWNE : > The code below provides a distance function that works for points and > moving point. > I am happy with the result, but I have a problem with the lambda > expressions. > Instead of supplying an argument to each 'mpXX', is it possible to have a > single lambda argument on the entire final 'md' function? (e.g. 'md 2') > Thanks in advance, > Pat > > data Point a = Point { abscissa :: a, ordinate :: a } deriving Show > dist a b = sqrt (((abscissa a) - (abscissa b))^2 + ((ordinate a) - > (ordinate b))^2) > > -- Sttic points > p1, p2 :: Point Float > p1 = Point 0.0 0.0 > p2 = Point 4.0 4.0 > d = dist p1 p2 > > > -- Moving points > mp1, mp2 :: Point Float > mp1x = (\t -> 4.0 + 0.5 * t) > mp1y = (\t -> 4.0 - 0.5 * t) > mp1 = Point (mp1x 2) (mp1y 2) > mp2x = (\t -> 0.0 + 1.0 * t) > mp2y = (\t -> 0.0 - 1.0 * t) > mp2 = Point (mp2x 2) (mp2y 2) > md = dist mp1 mp2 > > This email originated from DIT. If you received this email in error, > please delete it from your system. Please note that if you are not the > named addressee, disclosing, copying, distributing or taking any action > based on the contents of this email or attachments is prohibited. > www.dit.ie > > Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí > earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an > seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon > dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa > ríomhphost nó sna hiatáin seo. www.dit.ie > > Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to > Grangegorman > > _______________________________________________ > 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 silent.leaf0 at gmail.com Mon Jun 26 10:53:57 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Mon, 26 Jun 2017 12:53:57 +0200 Subject: [Haskell-beginners] R/W from/to partitions (on linux) In-Reply-To: References: Message-ID: yes, conduits really seem optimal! i'll probably use that in my final version, thanks! however i'll first try without using pre-made tools, to get the handle (ha) of manually using (binary) files with haskell, as after all my program isn that complicated. 2017-06-26 10:42 GMT+02:00 Stefan Risberg : > I would use some streaming library instead of lazy bytestring to keep > memory at reasonably low levels. It will also help with reading chunks, and > then composing actions on it. > > For library need you got: conduits, iostreams and pipes > > > > > On 26 Jun. 2017 10:37, "Silent Leaf" wrote: > > i'm reading on the doc of BS.Lazy.hGetContents: > "Once EOF is encountered, the Handle is closed." > > what does that imply if i'm using it inside of withFile? no risk of > getting prematurely out of the function right? that doesn seem possible in > a pure function but i'm asking either way. > if say i do something that reads the whole file, say calculating its > length, does it mean since EOF will be reached i'll have to open the file > again? i think i'm a bit lost... > > i'm trying to find how to read big chunks of two files, do stuff with each > pair of chunk, and so on till the EOF, which may or may not happen at the > same time for both... i don't really know how lazy bytestrings handle, for > example, taking too much from a file. one way would be to calculate the > length, ofc, but for files (partition) of several dozens of gigabytes, it's > a bit delicate... the ideal would be to get the length from the system > itself rather than calculate the whole string ... > > 2017-06-26 7:57 GMT+02:00 Silent Leaf : > >> Darn quick answer! Thanks Sylvain, that may be all i need to start! >> >> 2017-06-26 7:51 GMT+02:00 Sylvain Henry : >> >>> Hi, >>> >>> It is not Haskell specific. You just have to read from the partition >>> device special file (e.g., something like /dev/sdb2) as you would do with a >>> normal file. You must have the permission to do so (e.g., be root). Be >>> careful as you can destroy your system if you write something incorrect in >>> your partitions. >>> >>> Repositioning handles: https://www.stackage.org/haddo >>> ck/lts-8.20/base-4.9.1.0/System-IO.html#g:13 >>> >>> Read/write: https://www.stackage.org/haddock/lts-8.20/base-4.9.1.0/Syste >>> m-IO.html#v:hPutBuf >>> >>> Sylvain >>> >>> On 26/06/2017 07:35, Silent Leaf wrote: >>> >>> Hi, >>> >>> I'd like to be able to read and write from/to partitions directly. I've >>> had trouble with the documentation (honestly i can't find anything, and any >>> mention of partitions leads to mathematical partitioning of lists or >>> whatever). >>> >>> I obviously would need to be able to write or read from a specific >>> position in the partition. Mind you that would be good too for files (that >>> is, being able to read/write from a specific position in it) since i plan >>> on making disk images. >>> >>> Thanks in advance! >>> >>> >>> _______________________________________________ >>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> >>> _______________________________________________ >>> 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 > > > > _______________________________________________ > 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 raabe at froglogic.com Mon Jun 26 11:04:27 2017 From: raabe at froglogic.com (Frerich Raabe) Date: Mon, 26 Jun 2017 13:04:27 +0200 Subject: [Haskell-beginners] Improve my lambda expressions In-Reply-To: References: Message-ID: <05f193b817de0d6796b52d3e42cd9e26@froglogic.com> On 2017-06-26 11:38, PATRICK BROWNE wrote: > The code below provides a distance function that works for points and moving > point. > I am happy with the result, but I have a problem with the lambda > expressions. [..] > -- Sttic points > p1, p2 :: Point Float > p1 = Point 0.0 0.0 > p2 = Point 4.0 4.0 > d = dist p1 p2 > > -- Moving points > mp1, mp2 :: Point Float > mp1x = (\t -> 4.0 + 0.5 * t) > mp1y = (\t -> 4.0 - 0.5 * t) > mp1 = Point (mp1x 2) (mp1y 2) > mp2x = (\t -> 0.0 + 1.0 * t) > mp2y = (\t -> 0.0 - 1.0 * t) > mp2 = Point (mp2x 2) (mp2y 2) > md = dist mp1 mp2 Maybe you could reduce the number of lambda expressions by extracting common logic. It seems to me that 'mp1' and 'mp2' are moved versions of the same point (2,2) except that they apply different functions to the coordinates. These functions follow a pattern (a factor is applied to the component and then an 'offset' is added). For instance, it might be worthwhile to define movePoint :: Float -> Float -> Point -> Point movePoint offset factor (Point x y) = Point (offset + factor * x) (offset - factor * y) ...such that you could then define md = let p = Point 2 2 in dist (movePoint 4 0.5 p) (movePoint 0 1 p) -- Frerich Raabe - raabe at froglogic.com www.froglogic.com - Multi-Platform GUI Testing From silent.leaf0 at gmail.com Mon Jun 26 11:33:24 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Mon, 26 Jun 2017 13:33:24 +0200 Subject: [Haskell-beginners] R/W from/to partitions (on linux) In-Reply-To: References: Message-ID: i'm trying to get for which purpose BS.strict and BS.lazy are adapted. am i right to think that: lazy bytestrings are not optimal when needing to read huge files of several gigabytes, bc they are only lazy to the extent that the very long bytestring is not read to the end. aka it's like haskell's natural laziness, if i compute [0..2^20] == [0..2^20] it won't just take a lot of time but will also (try to) keep in memory both huge lists, aka the operation is not intrinsically on minimal resources, comparing each item of each list and discarding the previous ones at the same time; more generally the lists or bytestrings, be they lazy, are still only deallocated when the whole variable (the whole list/array) is dereferenced. thus if i need say to read very huge files and compare them together block by block, it's better for me to use strict bytestrings for each pair of chunks and manually move the handle from one block to the other, looping over the whole file. correct? 2017-06-26 12:53 GMT+02:00 Silent Leaf : > yes, conduits really seem optimal! i'll probably use that in my final > version, thanks! > however i'll first try without using pre-made tools, to get the handle > (ha) of manually using (binary) files with haskell, as after all my program > isn that complicated. > > 2017-06-26 10:42 GMT+02:00 Stefan Risberg : > >> I would use some streaming library instead of lazy bytestring to keep >> memory at reasonably low levels. It will also help with reading chunks, and >> then composing actions on it. >> >> For library need you got: conduits, iostreams and pipes >> >> >> >> >> On 26 Jun. 2017 10:37, "Silent Leaf" wrote: >> >> i'm reading on the doc of BS.Lazy.hGetContents: >> "Once EOF is encountered, the Handle is closed." >> >> what does that imply if i'm using it inside of withFile? no risk of >> getting prematurely out of the function right? that doesn seem possible in >> a pure function but i'm asking either way. >> if say i do something that reads the whole file, say calculating its >> length, does it mean since EOF will be reached i'll have to open the file >> again? i think i'm a bit lost... >> >> i'm trying to find how to read big chunks of two files, do stuff with >> each pair of chunk, and so on till the EOF, which may or may not happen at >> the same time for both... i don't really know how lazy bytestrings handle, >> for example, taking too much from a file. one way would be to calculate the >> length, ofc, but for files (partition) of several dozens of gigabytes, it's >> a bit delicate... the ideal would be to get the length from the system >> itself rather than calculate the whole string ... >> >> 2017-06-26 7:57 GMT+02:00 Silent Leaf : >> >>> Darn quick answer! Thanks Sylvain, that may be all i need to start! >>> >>> 2017-06-26 7:51 GMT+02:00 Sylvain Henry : >>> >>>> Hi, >>>> >>>> It is not Haskell specific. You just have to read from the partition >>>> device special file (e.g., something like /dev/sdb2) as you would do with a >>>> normal file. You must have the permission to do so (e.g., be root). Be >>>> careful as you can destroy your system if you write something incorrect in >>>> your partitions. >>>> >>>> Repositioning handles: https://www.stackage.org/haddo >>>> ck/lts-8.20/base-4.9.1.0/System-IO.html#g:13 >>>> >>>> Read/write: https://www.stackage.org/haddo >>>> ck/lts-8.20/base-4.9.1.0/System-IO.html#v:hPutBuf >>>> >>>> Sylvain >>>> >>>> On 26/06/2017 07:35, Silent Leaf wrote: >>>> >>>> Hi, >>>> >>>> I'd like to be able to read and write from/to partitions directly. I've >>>> had trouble with the documentation (honestly i can't find anything, and any >>>> mention of partitions leads to mathematical partitioning of lists or >>>> whatever). >>>> >>>> I obviously would need to be able to write or read from a specific >>>> position in the partition. Mind you that would be good too for files (that >>>> is, being able to read/write from a specific position in it) since i plan >>>> on making disk images. >>>> >>>> Thanks in advance! >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>>> >>>> _______________________________________________ >>>> 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 >> >> >> >> _______________________________________________ >> 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 silent.leaf0 at gmail.com Mon Jun 26 11:35:20 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Mon, 26 Jun 2017 13:35:20 +0200 Subject: [Haskell-beginners] R/W from/to partitions (on linux) In-Reply-To: References: Message-ID: btw i just tried my comparison of lists, and it seems there's an intermediate type holding the concept of boundaries and so on, aka it does not need to compute them beyond comparing their boundaries. clever haskell! a bit too much, you never know how smart it exactly is... 2017-06-26 13:33 GMT+02:00 Silent Leaf : > i'm trying to get for which purpose BS.strict and BS.lazy are adapted. am > i right to think that: > > lazy bytestrings are not optimal when needing to read huge files of > several gigabytes, bc they are only lazy to the extent that the very long > bytestring is not read to the end. aka it's like haskell's natural > laziness, if i compute [0..2^20] == [0..2^20] it won't just take a lot of > time but will also (try to) keep in memory both huge lists, aka the > operation is not intrinsically on minimal resources, comparing each item of > each list and discarding the previous ones at the same time; more generally > the lists or bytestrings, be they lazy, are still only deallocated when the > whole variable (the whole list/array) is dereferenced. > > thus if i need say to read very huge files and compare them together block > by block, it's better for me to use strict bytestrings for each pair of > chunks and manually move the handle from one block to the other, looping > over the whole file. correct? > > 2017-06-26 12:53 GMT+02:00 Silent Leaf : > >> yes, conduits really seem optimal! i'll probably use that in my final >> version, thanks! >> however i'll first try without using pre-made tools, to get the handle >> (ha) of manually using (binary) files with haskell, as after all my program >> isn that complicated. >> >> 2017-06-26 10:42 GMT+02:00 Stefan Risberg : >> >>> I would use some streaming library instead of lazy bytestring to keep >>> memory at reasonably low levels. It will also help with reading chunks, and >>> then composing actions on it. >>> >>> For library need you got: conduits, iostreams and pipes >>> >>> >>> >>> >>> On 26 Jun. 2017 10:37, "Silent Leaf" wrote: >>> >>> i'm reading on the doc of BS.Lazy.hGetContents: >>> "Once EOF is encountered, the Handle is closed." >>> >>> what does that imply if i'm using it inside of withFile? no risk of >>> getting prematurely out of the function right? that doesn seem possible in >>> a pure function but i'm asking either way. >>> if say i do something that reads the whole file, say calculating its >>> length, does it mean since EOF will be reached i'll have to open the file >>> again? i think i'm a bit lost... >>> >>> i'm trying to find how to read big chunks of two files, do stuff with >>> each pair of chunk, and so on till the EOF, which may or may not happen at >>> the same time for both... i don't really know how lazy bytestrings handle, >>> for example, taking too much from a file. one way would be to calculate the >>> length, ofc, but for files (partition) of several dozens of gigabytes, it's >>> a bit delicate... the ideal would be to get the length from the system >>> itself rather than calculate the whole string ... >>> >>> 2017-06-26 7:57 GMT+02:00 Silent Leaf : >>> >>>> Darn quick answer! Thanks Sylvain, that may be all i need to start! >>>> >>>> 2017-06-26 7:51 GMT+02:00 Sylvain Henry : >>>> >>>>> Hi, >>>>> >>>>> It is not Haskell specific. You just have to read from the partition >>>>> device special file (e.g., something like /dev/sdb2) as you would do with a >>>>> normal file. You must have the permission to do so (e.g., be root). Be >>>>> careful as you can destroy your system if you write something incorrect in >>>>> your partitions. >>>>> >>>>> Repositioning handles: https://www.stackage.org/haddo >>>>> ck/lts-8.20/base-4.9.1.0/System-IO.html#g:13 >>>>> >>>>> Read/write: https://www.stackage.org/haddo >>>>> ck/lts-8.20/base-4.9.1.0/System-IO.html#v:hPutBuf >>>>> >>>>> Sylvain >>>>> >>>>> On 26/06/2017 07:35, Silent Leaf wrote: >>>>> >>>>> Hi, >>>>> >>>>> I'd like to be able to read and write from/to partitions directly. >>>>> I've had trouble with the documentation (honestly i can't find anything, >>>>> and any mention of partitions leads to mathematical partitioning of lists >>>>> or whatever). >>>>> >>>>> I obviously would need to be able to write or read from a specific >>>>> position in the partition. Mind you that would be good too for files (that >>>>> is, being able to read/write from a specific position in it) since i plan >>>>> on making disk images. >>>>> >>>>> Thanks in advance! >>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> 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 >>> >>> >>> >>> _______________________________________________ >>> 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 eyeinsky9 at gmail.com Mon Jun 26 17:12:15 2017 From: eyeinsky9 at gmail.com (eyeinsky .) Date: Mon, 26 Jun 2017 19:12:15 +0200 Subject: [Haskell-beginners] R/W from/to partitions (on linux) In-Reply-To: References: Message-ID: AFAIK, in the list comparison case you mention, it will just build and destroy the lists until it reaches the end or finds a non-equal pair and returns False at that point. So no keeping the list in memory, since computing equality for lists doesn't require it. On Jun 26, 2017 2:39 PM, "Silent Leaf" wrote: > btw i just tried my comparison of lists, and it seems there's an > intermediate type holding the concept of boundaries and so on, aka it does > not need to compute them beyond comparing their boundaries. clever haskell! > a bit too much, you never know how smart it exactly is... > > 2017-06-26 13:33 GMT+02:00 Silent Leaf : > >> i'm trying to get for which purpose BS.strict and BS.lazy are adapted. am >> i right to think that: >> >> lazy bytestrings are not optimal when needing to read huge files of >> several gigabytes, bc they are only lazy to the extent that the very long >> bytestring is not read to the end. aka it's like haskell's natural >> laziness, if i compute [0..2^20] == [0..2^20] it won't just take a lot of >> time but will also (try to) keep in memory both huge lists, aka the >> operation is not intrinsically on minimal resources, comparing each item of >> each list and discarding the previous ones at the same time; more generally >> the lists or bytestrings, be they lazy, are still only deallocated when the >> whole variable (the whole list/array) is dereferenced. >> >> thus if i need say to read very huge files and compare them together >> block by block, it's better for me to use strict bytestrings for each pair >> of chunks and manually move the handle from one block to the other, looping >> over the whole file. correct? >> >> 2017-06-26 12:53 GMT+02:00 Silent Leaf : >> >>> yes, conduits really seem optimal! i'll probably use that in my final >>> version, thanks! >>> however i'll first try without using pre-made tools, to get the handle >>> (ha) of manually using (binary) files with haskell, as after all my program >>> isn that complicated. >>> >>> 2017-06-26 10:42 GMT+02:00 Stefan Risberg : >>> >>>> I would use some streaming library instead of lazy bytestring to keep >>>> memory at reasonably low levels. It will also help with reading chunks, and >>>> then composing actions on it. >>>> >>>> For library need you got: conduits, iostreams and pipes >>>> >>>> >>>> >>>> >>>> On 26 Jun. 2017 10:37, "Silent Leaf" wrote: >>>> >>>> i'm reading on the doc of BS.Lazy.hGetContents: >>>> "Once EOF is encountered, the Handle is closed." >>>> >>>> what does that imply if i'm using it inside of withFile? no risk of >>>> getting prematurely out of the function right? that doesn seem possible in >>>> a pure function but i'm asking either way. >>>> if say i do something that reads the whole file, say calculating its >>>> length, does it mean since EOF will be reached i'll have to open the file >>>> again? i think i'm a bit lost... >>>> >>>> i'm trying to find how to read big chunks of two files, do stuff with >>>> each pair of chunk, and so on till the EOF, which may or may not happen at >>>> the same time for both... i don't really know how lazy bytestrings handle, >>>> for example, taking too much from a file. one way would be to calculate the >>>> length, ofc, but for files (partition) of several dozens of gigabytes, it's >>>> a bit delicate... the ideal would be to get the length from the system >>>> itself rather than calculate the whole string ... >>>> >>>> 2017-06-26 7:57 GMT+02:00 Silent Leaf : >>>> >>>>> Darn quick answer! Thanks Sylvain, that may be all i need to start! >>>>> >>>>> 2017-06-26 7:51 GMT+02:00 Sylvain Henry : >>>>> >>>>>> Hi, >>>>>> >>>>>> It is not Haskell specific. You just have to read from the partition >>>>>> device special file (e.g., something like /dev/sdb2) as you would do with a >>>>>> normal file. You must have the permission to do so (e.g., be root). Be >>>>>> careful as you can destroy your system if you write something incorrect in >>>>>> your partitions. >>>>>> >>>>>> Repositioning handles: https://www.stackage.org/haddo >>>>>> ck/lts-8.20/base-4.9.1.0/System-IO.html#g:13 >>>>>> >>>>>> Read/write: https://www.stackage.org/haddo >>>>>> ck/lts-8.20/base-4.9.1.0/System-IO.html#v:hPutBuf >>>>>> >>>>>> Sylvain >>>>>> >>>>>> On 26/06/2017 07:35, Silent Leaf wrote: >>>>>> >>>>>> Hi, >>>>>> >>>>>> I'd like to be able to read and write from/to partitions directly. >>>>>> I've had trouble with the documentation (honestly i can't find anything, >>>>>> and any mention of partitions leads to mathematical partitioning of lists >>>>>> or whatever). >>>>>> >>>>>> I obviously would need to be able to write or read from a specific >>>>>> position in the partition. Mind you that would be good too for files (that >>>>>> is, being able to read/write from a specific position in it) since i plan >>>>>> on making disk images. >>>>>> >>>>>> Thanks in advance! >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> 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 >>>> >>>> >>>> >>>> _______________________________________________ >>>> 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 patrick.browne at dit.ie Tue Jun 27 16:35:11 2017 From: patrick.browne at dit.ie (PATRICK BROWNE) Date: Tue, 27 Jun 2017 17:35:11 +0100 Subject: [Haskell-beginners] Improve my lambda expressions Message-ID: Thanks for all your help. I was unaware that there was a relation between let/where and lambdas. Here is my effort to use a single lamda md3 n = (\n -> (dist (Point (4.0 + 0.5 * n) (4.0 - 0.5 * n)) (Point (n * 1.0) ( n * (-1.0))))) n I imagine that this function could be written without lambdas, let, or where. Is it generally true the all/most functions could be written without lambdas, let, or where? Thanks, Pat On 26 June 2017 at 12:04, Frerich Raabe wrote: > On 2017-06-26 11:38, PATRICK BROWNE wrote: > >> The code below provides a distance function that works for points and >> moving point. >> I am happy with the result, but I have a problem with the lambda >> expressions. >> > > [..] > > -- Sttic points >> p1, p2 :: Point Float >> p1 = Point 0.0 0.0 >> p2 = Point 4.0 4.0 >> d = dist p1 p2 >> >> -- Moving points >> mp1, mp2 :: Point Float >> mp1x = (\t -> 4.0 + 0.5 * t) >> mp1y = (\t -> 4.0 - 0.5 * t) >> mp1 = Point (mp1x 2) (mp1y 2) >> mp2x = (\t -> 0.0 + 1.0 * t) >> mp2y = (\t -> 0.0 - 1.0 * t) >> mp2 = Point (mp2x 2) (mp2y 2) >> md = dist mp1 mp2 >> > > Maybe you could reduce the number of lambda expressions by extracting > common logic. It seems to me that 'mp1' and 'mp2' are moved versions of the > same point (2,2) except that they apply different functions to the > coordinates. These functions follow a pattern (a factor is applied to the > component and then an 'offset' is added). > > For instance, it might be worthwhile to define > > movePoint :: Float -> Float -> Point -> Point > movePoint offset factor (Point x y) = Point (offset + factor * x) > (offset - factor * y) > > ...such that you could then define > > md = let p = Point 2 2 in dist (movePoint 4 0.5 p) (movePoint 0 1 p) > > -- > Frerich Raabe - raabe at froglogic.com > www.froglogic.com - Multi-Platform GUI Testing > -- This email originated from DIT. If you received this email in error, please delete it from your system. Please note that if you are not the named addressee, disclosing, copying, distributing or taking any action based on the contents of this email or attachments is prohibited. www.dit.ie Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa ríomhphost nó sna hiatáin seo. www.dit.ie Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to Grangegorman -------------- next part -------------- An HTML attachment was scrubbed... URL: From silent.leaf0 at gmail.com Tue Jun 27 19:42:03 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Tue, 27 Jun 2017 21:42:03 +0200 Subject: [Haskell-beginners] a way to check whether a file is actually being written on Message-ID: Hi, i created a small clone of dd in haskell. I made it so it only copies block by block and only if there's any difference between each pair of blocks from each file. the idea is to use this dd clone as backup system, especially since my partitions are nearly full, so no real loss in copying the whole things. I'm wondering if there's any way to check if my program never ever writes onto the target unless actually needed. obviously by reading the code i'd say it does what i want, but we do make test cases rather than rely on what we think the code does. i can't run it with a target file that would be made read-only in the filesys (and hope for an error for trying to write on it) since obviously i need to open it in read-write right from the beginning, in case of actual need of writing (as apparently i can't have two handles on the same file... although maybe there's a way to change the mode of opening on the run? did not find it in System.IO nor in Hoogle or Hayoo) so if anyone has an idea, in or outside of haskell, that would be great! -------------- next part -------------- An HTML attachment was scrubbed... URL: From silent.leaf0 at gmail.com Tue Jun 27 20:14:24 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Tue, 27 Jun 2017 22:14:24 +0200 Subject: [Haskell-beginners] a way to check whether a file is actually being written on In-Reply-To: References: Message-ID: by the way: dd has this option that says "in case of read error, do not stop, continue". it's recomended to use it altho i never actually gotten why. my point is: how to handle any kind of read/write exception with my clone? i used withBinaryFile which promised to close my handles no matter what, which is great, but i don't feel much secured since i don't know how my program would handle a bumpy ride or even if it would tell me anything... i don't even know what would happen if it were cut in the middle, etc. on this general topic, by the way, are there good resources for system-programming with haskell? is it even manageable to do so rather than use c-like (go, c++, etc) languages? 2017-06-27 21:42 GMT+02:00 Silent Leaf : > Hi, > > i created a small clone of dd in haskell. I made it so it only copies > block by block and only if there's any difference between each pair of > blocks from each file. the idea is to use this dd clone as backup system, > especially since my partitions are nearly full, so no real loss in copying > the whole things. > > I'm wondering if there's any way to check if my program never ever writes > onto the target unless actually needed. obviously by reading the code i'd > say it does what i want, but we do make test cases rather than rely on what > we think the code does. > > i can't run it with a target file that would be made read-only in the > filesys (and hope for an error for trying to write on it) since obviously i > need to open it in read-write right from the beginning, in case of actual > need of writing (as apparently i can't have two handles on the same file... > although maybe there's a way to change the mode of opening on the run? did > not find it in System.IO nor in Hoogle or Hayoo) > > so if anyone has an idea, in or outside of haskell, that would be great! > -------------- next part -------------- An HTML attachment was scrubbed... URL: From saikyun at gmail.com Tue Jun 27 20:42:53 2017 From: saikyun at gmail.com (Jona Ekenberg) Date: Tue, 27 Jun 2017 22:42:53 +0200 Subject: [Haskell-beginners] a way to check whether a file is actually being written on In-Reply-To: References: Message-ID: Den 27 juni 2017 9:47 em skrev "Silent Leaf" : Hi, i created a small clone of dd in haskell. I made it so it only copies block by block and only if there's any difference between each pair of blocks from each file. the idea is to use this dd clone as backup system, especially since my partitions are nearly full, so no real loss in copying the whole things. I'm wondering if there's any way to check if my program never ever writes onto the target unless actually needed. obviously by reading the code i'd say it does what i want, but we do make test cases rather than rely on what we think the code does. i can't run it with a target file that would be made read-only in the filesys (and hope for an error for trying to write on it) since obviously i need to open it in read-write right from the beginning, in case of actual need of writing (as apparently i can't have two handles on the same file... although maybe there's a way to change the mode of opening on the run? did not find it in System.IO nor in Hoogle or Hayoo) so if anyone has an idea, in or outside of haskell, that would be great! ______________________________ Maybe you can use strace? https://youtu.be/4pEHfGKB-OE 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 yin.137 at gmail.com Wed Jun 28 05:39:28 2017 From: yin.137 at gmail.com (Ning Yin) Date: Wed, 28 Jun 2017 13:39:28 +0800 Subject: [Haskell-beginners] Beginners Digest, Vol 108, Issue 12 In-Reply-To: References: Message-ID: 发自我的 iPad > 在 2017年6月24日,20:00,beginners-request at haskell.org 写道: > > Send Beginners mailing list submissions to > beginners at 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-request at haskell.org > > You can reach the person managing the list at > beginners-owner at 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: help designing types for a gsl fit (David McBride) > 2. What to use when you need random values? (Silent Leaf) > 3. Re: What to use when you need random values? (David McBride) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Fri, 23 Jun 2017 09:58:35 -0400 > From: David McBride > To: The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > Subject: Re: [Haskell-beginners] help designing types for a gsl fit > Message-ID: > > Content-Type: text/plain; charset="UTF-8" > > If you look at the type of labelNew > > GlibString string => Maybe string -> IO Label > > If you look at the instances for GlibString, they could be Text or > [Char]. You have to decide which. The fact that you are using > Nothing does not tell you the entire final type. It could be Maybe > [Char], or Maybe Text. Even though the choice seems arbitrary in this > instance, you have to decide which it is. So try this. > > lprog <- G.labelNew (Nothing :: Maybe [Char]) > > On Fri, Jun 23, 2017 at 3:22 AM, Agustin Larreinegabe > wrote: >> Hello, >> I'm trying to install an application Termite - Debug but I get this error in >> line 929:14 >> >> when it try to do this >> >> >> >> lprog <- G.labelNew Nothing >> >> >> The error says: >> >> Could not deduce (glib-0.13.4.1:System.Glib.UTFString.GlibString string0) >> arising from a use of ‘G.labelNew’ from the context (D.Rel c v a s) bound by >> the type signature for sourceWindowCreate :: D.Rel c v a s => RSourceView c >> a u -> IO G.Widget at Debug/SourceView.hs:913:23-73 instance >> glib-0.13.4.1:System.Glib.UTFString.GlibString [Char] -- Defined in >> ‘glib-0.13.4.1:System.Glib.UTFString’ In a stmt of a 'do' block: lprog <- >> G.labelNew Nothing In the expression: do { vbox <- G.vBoxNew False 0; >> G.widgetShow vbox; spec <- getIORef svInputSpec ref; code <- codeWinNew >> spec; .... } In an equation for ‘sourceWindowCreate’: sourceWindowCreate ref >> = do { vbox <- G.vBoxNew False 0; G.widgetShow vbox; spec <- getIORef >> svInputSpec ref; cabal: Error: some packages failed to install: >> >> I really don't know how to proceed, I'm new with Haskell >> >> >> Thanks in advance. >> >> >> ----------------- >> Agustin Larreinegabe >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > ------------------------------ > > Message: 2 > Date: Fri, 23 Jun 2017 16:24:07 +0200 > From: Silent Leaf > To: The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > Subject: [Haskell-beginners] What to use when you need random values? > Message-ID: > > Content-Type: text/plain; charset="utf-8" > > Hi, > I've had trouble finding the best way(s) to use random values in haskell, > as it seems like there are several modules that either do the same thing or > reuse one another i'm not sure. > > There is System.Random > - is it better to use the streams random(R)s or a more imperative randomRIO? > - is it better to use mkStdGen or newStdGen or getStdGen? > There is Test.QuickCheck and its type(class?) Gen > There is a module in Control.Monad (i think) which exports the type Rnd > > What about performances, and all those options? What do you like to use > with random numbers? > > I know that's a lot of questions. feel free to only answer to a few of > them. :) > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > > ------------------------------ > > Message: 3 > Date: Fri, 23 Jun 2017 11:10:05 -0400 > From: David McBride > To: The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > Subject: Re: [Haskell-beginners] What to use when you need random > values? > Message-ID: > > Content-Type: text/plain; charset="UTF-8" > > When you are unsure about the differences between functions, it can be > good to read the haddocks for the library. > > http://hackage.haskell.org/package/random-1.1/docs/System-Random.html > > The standard haskell random library supports the idea of splitting a > seed randomly. You take one seed and split it, and now you have two > seeds, which will each generate different randoms independently. > getStdGen gets the current global seed. newStdGen splits new a seed > off of the current global seed. mkStdGen allows you to create a seed > from a value so that you can get the same set of randoms repeatedly. > > I would say if you are in IO, just use randomRIO. If you are in > monadic code that not IO at its base, you should use MonadRandom > library on hackage. Quickcheck randomness is only really used in > quickcheck, although it is probably based off the standard libraries. > > Just keep in mind that randomness is a concept that is a little hard > to wrap your head around in haskell until you've been using it a > little while. > >> On Fri, Jun 23, 2017 at 10:24 AM, Silent Leaf wrote: >> Hi, >> I've had trouble finding the best way(s) to use random values in haskell, as >> it seems like there are several modules that either do the same thing or >> reuse one another i'm not sure. >> >> There is System.Random >> - is it better to use the streams random(R)s or a more imperative randomRIO? >> - is it better to use mkStdGen or newStdGen or getStdGen? >> There is Test.QuickCheck and its type(class?) Gen >> There is a module in Control.Monad (i think) which exports the type Rnd >> >> What about performances, and all those options? What do you like to use with >> random numbers? >> >> I know that's a lot of questions. feel free to only answer to a few of them. >> :) >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > ------------------------------ > > End of Beginners Digest, Vol 108, Issue 12 > ****************************************** From silent.leaf0 at gmail.com Wed Jun 28 06:07:19 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Wed, 28 Jun 2017 08:07:19 +0200 Subject: [Haskell-beginners] a way to check whether a file is actually being written on In-Reply-To: References: Message-ID: strace sounds really great, i'll test it, thanks :) 2017-06-27 22:42 GMT+02:00 Jona Ekenberg : > > > Den 27 juni 2017 9:47 em skrev "Silent Leaf" : > > Hi, > > i created a small clone of dd in haskell. I made it so it only copies > block by block and only if there's any difference between each pair of > blocks from each file. the idea is to use this dd clone as backup system, > especially since my partitions are nearly full, so no real loss in copying > the whole things. > > I'm wondering if there's any way to check if my program never ever writes > onto the target unless actually needed. obviously by reading the code i'd > say it does what i want, but we do make test cases rather than rely on what > we think the code does. > > i can't run it with a target file that would be made read-only in the > filesys (and hope for an error for trying to write on it) since obviously i > need to open it in read-write right from the beginning, in case of actual > need of writing (as apparently i can't have two handles on the same file... > although maybe there's a way to change the mode of opening on the run? did > not find it in System.IO nor in Hoogle or Hayoo) > > so if anyone has an idea, in or outside of haskell, that would be great! > ______________________________ > > Maybe you can use strace? https://youtu.be/4pEHfGKB-OE > > > 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 raabe at froglogic.com Wed Jun 28 06:26:20 2017 From: raabe at froglogic.com (Frerich Raabe) Date: Wed, 28 Jun 2017 08:26:20 +0200 Subject: [Haskell-beginners] Improve my lambda expressions In-Reply-To: References: Message-ID: <2b58f301f228aa26ba3d26c11ee341f7@froglogic.com> On 2017-06-27 18:35, PATRICK BROWNE wrote: > Thanks for all your help. > I was unaware that there was a relation between let/where and lambdas. > Here is my effort to use a single lamda > md3 n = (\n -> (dist (Point (4.0 + 0.5 * n) (4.0 - 0.5 * n)) (Point (n * > 1.0) ( n * (-1.0))))) n > > I imagine that this function could be written without lambdas, let, or > where. Indeed, it could. Note that your definition has the form md3 n = (\n -> (dist )) n I.e. the expression 'md3 n' is equivalent to the expression '(\n -> (dist ..)) n', which means 'apply the lambda expression to n'. You don't need the lambda expression if you apply it to a given argument directly though, i.e. the above definition is equivalent to md3 n = dist .. > Is it generally true the all/most functions could be written without > lambdas, let, or where? I believe it is true since you could define any function as a global definition (i.e. not a nested scope as in let..in or where). -- Frerich Raabe - raabe at froglogic.com www.froglogic.com - Multi-Platform GUI Testing From frederic-emmanuel.picca at synchrotron-soleil.fr Wed Jun 28 13:27:02 2017 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Wed, 28 Jun 2017 13:27:02 +0000 Subject: [Haskell-beginners] which typefor this FFI call In-Reply-To: <46ecc981-a136-705b-48fc-93d512016a92@haskus.fr> References: <830739f6-c249-fde2-a549-3b02bd2e2ef2@haskus.fr>, <46ecc981-a136-705b-48fc-93d512016a92@haskus.fr> Message-ID: Hello, I end up with this and it works :) thanks type H5Iterate a = HId_t -> CString -> In H5L_info_t -> InOut a -> IO HErr_t foreign import ccall "wrapper" mkOp :: H5Iterate a -> IO (FunPtr (H5Iterate a)) nxEntries ∷ FilePath → IO [String] nxEntries f = withH5File f $ \h → do state <- newIORef [] statePtr <- newStablePtr state let opData = InOut $ castStablePtrToPtr statePtr let startIndex = Nothing let indexType = ByName let order = Native iop <- mkOp callback _ <- withInOut_ (maybe 0 hSize startIndex) $ \ioStartIndex -> h5l_iterate (hid h) (indexTypeCode indexType) (iterOrderCode order) ioStartIndex iop opData freeHaskellFunPtr iop freeStablePtr statePtr -- retrieve the final state readIORef state where callback ∷ H5Iterate a callback _g n _i (InOut dataptr) = do let opData = castWrappedPtr dataptr -- get the state stRef <- deRefStablePtr (castPtrToStablePtr opData) st <- readIORef stRef -- compute the new state name <- peekCString n let newSt = st ++ [name] print st print name print newSt -- store the new state writeIORef stRef newSt return $ HErr_t 0 BUT I lose the type checking at the callback interface. the ffi call of the h5l_iterate method is #ccall H5Literate, -> -> -> InOut -> H5L_iterate_t a -> InOut a -> IO where H5L_iterate_t a = H5Iterate So the call back should keep the information of the type via a my question is, when I write this let opData = InOut $ castStablePtrToPtr statePtr I have InOut (Ptr ()) is it possible to have somthing more like InOut (Ptr a) instead ? Thanks Fred From sylvain at haskus.fr Wed Jun 28 14:24:49 2017 From: sylvain at haskus.fr (Sylvain Henry) Date: Wed, 28 Jun 2017 16:24:49 +0200 Subject: [Haskell-beginners] which typefor this FFI call In-Reply-To: References: <830739f6-c249-fde2-a549-3b02bd2e2ef2@haskus.fr> <46ecc981-a136-705b-48fc-93d512016a92@haskus.fr> Message-ID: <14138a68-a608-194e-b94a-1f0e09dc62de@haskus.fr> On 28/06/2017 15:27, PICCA Frederic-Emmanuel wrote: > my question is, when I write this > > let opData = InOut $ castStablePtrToPtr statePtr > > I have InOut (Ptr ()) is it possible to have somthing more like InOut (Ptr a) instead ? > Yes it's strange that `castStablePtrToPtr` returns `Ptr ()` instead of `Ptr a`. You can use `castPtr` to get the type back: let opData = InOut $ castPtr $ castStablePtrToPtr statePtr https://www.stackage.org/haddock/lts-8.20/base-4.9.1.0/Foreign-Ptr.html#v:castPtr -Sylvain From frederic-emmanuel.picca at synchrotron-soleil.fr Wed Jun 28 14:48:56 2017 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Wed, 28 Jun 2017 14:48:56 +0000 Subject: [Haskell-beginners] which typefor this FFI call In-Reply-To: <14138a68-a608-194e-b94a-1f0e09dc62de@haskus.fr> References: <830739f6-c249-fde2-a549-3b02bd2e2ef2@haskus.fr> <46ecc981-a136-705b-48fc-93d512016a92@haskus.fr> , <14138a68-a608-194e-b94a-1f0e09dc62de@haskus.fr> Message-ID: > Yes it's strange that `castStablePtrToPtr` returns `Ptr ()` instead of > `Ptr a`. You can use `castPtr` to get the type back: the type signature of castStablePtrTOPtr is :: StablePtr a -> Ptr () So yes we loose the type. I will check if this work > let opData = InOut $ castPtr $ castStablePtrToPtr statePtr Thanks Frederic ps: http://hackage.haskell.org/package/base-4.9.1.0/docs/Foreign-StablePtr.html#v:castStablePtrToPtr From silent.leaf0 at gmail.com Wed Jun 28 20:01:10 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Wed, 28 Jun 2017 22:01:10 +0200 Subject: [Haskell-beginners] tail recursion optimizations and monads Message-ID: Hi, If i do this: f :: (Monad m) => a -> m a f a = ma >>= f or maybe this: f :: (Monad m) => Foo -> m a f foo = mb >>= \foo' -> mc >> f foo' can i be sure it's tail recursive (as in, with optimization)? is it in fact ever the case? does it depend on the monad? esp obviously i'm very interested in the IO monad in those cases. esp, even if it's tail recursive on the level of haskell, does it entail an execution of the underlying IO action in any way tail-recursively optimized? or does it not even matter because at the level of the execution of the IO value, there's no recursion to speak of anymore? just wondering. thanks in advance! -------------- next part -------------- An HTML attachment was scrubbed... URL: From silent.leaf0 at gmail.com Thu Jun 29 10:12:07 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Thu, 29 Jun 2017 12:12:07 +0200 Subject: [Haskell-beginners] where do non-beginners haskellers go to expose code to the community? Message-ID: hi, let's say i'm a real-deal but typically open-source/not-employed haskeller, i have a really well-done library/program. i want to publish it so it's available, but i also want to just broadcast to at least a part of the haskell community basically saying "hiya, made that cool code, go check it out". both to get returns and ideas, but not so much for code-review, since it's about reviewing a finished product, or at least an alpha/beta version. where would i go to do that? (again, it's hypothetical, i'm not real-deal yet) i mean what's the point of coding if nobody knows what you do, right? (of course the question is not serious, but still, it must count for a bit right? if you don't get paid or you don't sell your code and it's not only for your own usage?) but maybe there are ways by which most haskellers go check the latest published packages? or maybe the community is not that tight-knit? or maybe it does not depend on the language, and there are places where to make your code known to potential users? i admit i don't actually know how someone with an opensource program would go to advertize it. even creating a website for it does not tell anybody that it exists. was just wondering. it'd be somewhat good if there were a centralized place where to review any package published on official repositories, both wrt the code and the functionalities. a kind of message board automatically plugged to the flux of published packages. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Thu Jun 29 10:54:06 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 29 Jun 2017 12:54:06 +0200 Subject: [Haskell-beginners] where do non-beginners haskellers go to expose code to the community? In-Reply-To: References: Message-ID: <20170629105406.ld5gmdrsbc7jsqoi@x60s.casa> On Thu, Jun 29, 2017 at 12:12:07PM +0200, Silent Leaf wrote: > hi, > > let's say i'm a real-deal but typically open-source/not-employed haskeller, > i have a really well-done library/program. i want to publish it so it's > available, but i also want to just broadcast to at least a part of the > haskell community basically saying "hiya, made that cool code, go check it > out". both to get returns and ideas, but not so much for code-review, since > it's about reviewing a finished product, or at least an alpha/beta version. > where would i go to do that? (again, it's hypothetical, i'm not real-deal > yet) Hello Silent Leaf, usually I keep up with the Haskellers in 3 ways: 1. by checking the `Haskell Communities and Activities Report` [1] 2. by being subscribed to Haskell announce [2] 3. by subscribing to the "uploaded recently" RSS feed [3] If I want to broadcast a release and get feedback, writing to haskell-announce and haskell-cafe is the way to go. [1] https://wiki.haskell.org/Haskell_Communities_and_Activities_Report [2] https://mail.haskell.org/mailman/listinfo/haskell [3] https://hackage.haskell.org/packages/recent.rss From silent.leaf0 at gmail.com Thu Jun 29 11:55:24 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Thu, 29 Jun 2017 13:55:24 +0200 Subject: [Haskell-beginners] where do non-beginners haskellers go to expose code to the community? In-Reply-To: <20170629105406.ld5gmdrsbc7jsqoi@x60s.casa> References: <20170629105406.ld5gmdrsbc7jsqoi@x60s.casa> Message-ID: great, that's what i was looking for! thanks :) maybe in several months i'll be good enough for publishing :) 2017-06-29 12:54 GMT+02:00 Francesco Ariis : > On Thu, Jun 29, 2017 at 12:12:07PM +0200, Silent Leaf wrote: > > hi, > > > > let's say i'm a real-deal but typically open-source/not-employed > haskeller, > > i have a really well-done library/program. i want to publish it so it's > > available, but i also want to just broadcast to at least a part of the > > haskell community basically saying "hiya, made that cool code, go check > it > > out". both to get returns and ideas, but not so much for code-review, > since > > it's about reviewing a finished product, or at least an alpha/beta > version. > > where would i go to do that? (again, it's hypothetical, i'm not real-deal > > yet) > > Hello Silent Leaf, > usually I keep up with the Haskellers in 3 ways: > > 1. by checking the `Haskell Communities and Activities Report` [1] > 2. by being subscribed to Haskell announce [2] > 3. by subscribing to the "uploaded recently" RSS feed [3] > > If I want to broadcast a release and get feedback, writing to > haskell-announce and haskell-cafe is the way to go. > > [1] https://wiki.haskell.org/Haskell_Communities_and_Activities_Report > [2] https://mail.haskell.org/mailman/listinfo/haskell > [3] https://hackage.haskell.org/packages/recent.rss > _______________________________________________ > 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 saikyun at gmail.com Thu Jun 29 12:33:22 2017 From: saikyun at gmail.com (Jona Ekenberg) Date: Thu, 29 Jun 2017 14:33:22 +0200 Subject: [Haskell-beginners] How do I map a String and a IO String? Message-ID: I want to replace lines with the content of a file if the line is a filename > {-# LANGUAGE LambdaCase #-} > test = do > putStrLn $ concatMap (\l -> l ++ "\n") > $ map (\case l > | (isPrefixOf "./" l) -> readFile l > | otherwise -> l) But since l is a String and readFile gives an IO String this doesn't work. How should I get around this? Kind regards, Jona -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Thu Jun 29 13:16:02 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 29 Jun 2017 15:16:02 +0200 Subject: [Haskell-beginners] How do I map a String and a IO String? In-Reply-To: References: Message-ID: <20170629131602.rwkbt4dypkefx3af@x60s.casa> On Thu, Jun 29, 2017 at 02:33:22PM +0200, Jona Ekenberg wrote: > I want to replace lines with the content of a file if the line is a filename Hello Jonas, you want to user `return`: λ> :t return return :: Monad m => a -> m a which lifts a simple value inside a monad (in this case, a -> IO a), like this: lineOrIO :: String -> IO String lineOrIO cs | (isPrefixOf "./" cs) = readFile cs | otherwise = return cs If this is not a school assignment, consider replacing `isPrefixOf "./"` with something from `System.Directory`. Does this help? From saikyun at gmail.com Thu Jun 29 14:15:16 2017 From: saikyun at gmail.com (Jona Ekenberg) Date: Thu, 29 Jun 2017 16:15:16 +0200 Subject: [Haskell-beginners] How do I map a String and a IO String? In-Reply-To: <20170629131602.rwkbt4dypkefx3af@x60s.casa> References: <20170629131602.rwkbt4dypkefx3af@x60s.casa> Message-ID: 2017-06-29 15:16 GMT+02:00 Francesco Ariis : > On Thu, Jun 29, 2017 at 02:33:22PM +0200, Jona Ekenberg wrote: > > I want to replace lines with the content of a file if the line is a > filename > > Hello Jonas, you want to user `return`: > > λ> :t return > return :: Monad m => a -> m a > > which lifts a simple value inside a monad (in this case, a -> IO a), like > this: > > lineOrIO :: String -> IO String > lineOrIO cs | (isPrefixOf "./" cs) = readFile cs > | otherwise = return cs > > If this is not a school assignment, consider replacing `isPrefixOf "./"` > with something from `System.Directory`. > > Does this help? Thank you for your help Francesco! I tried writing it like this: > lineOrIo :: String -> IO String > lineOrIo cs | (isPrefixOf "./" cs) = readFile cs > | otherwise = return cs > > printLines path = do > file <- readFile path > lines <- map lineOrIo (lines file) > print lines But when evaluating I get this error: PrintComments.lhs:20:14-38: error: … • Couldn't match type ‘[]’ with ‘IO’ Expected type: IO (IO String) Actual type: [IO String] • In a stmt of a 'do' block: lines <- map lineOrIo (lines file) In the expression: do { file <- readFile path; lines <- map lineOrIo (lines file); print lines } In an equation for ‘printLines’: printLines path = do { file <- readFile path; lines <- map lineOrIo (lines file); print lines } Compilation failed. Sadly I am not yet very used to the error messages, so I don't understand what ghci is telling me. As far as I can tell (lines file) should give me an array of strings, which I turn into an array of IO String. Could that be the error? It shouldn't be [IO String] but instead IO [String]? How do I turn the former into the latter? Kind regards, Jona PS. It is not a school assignment, so I'll make sure to check out System.Directory. > _______________________________________________ > 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 silent.leaf0 at gmail.com Thu Jun 29 14:22:34 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Thu, 29 Jun 2017 16:22:34 +0200 Subject: [Haskell-beginners] order of things in a file.hs? Message-ID: hi, what is your personal practice of ordering data/functions/main/hidden functions, etc in a haskell file? like all trivial things they are very hard to decide upon, given that either order of helpers then main function / value, or the other way round, has tempting pros and cons. thanks in advance for your opinion! -------------- next part -------------- An HTML attachment was scrubbed... URL: From timmelzer at gmail.com Thu Jun 29 14:31:30 2017 From: timmelzer at gmail.com (Norbert Melzer) Date: Thu, 29 Jun 2017 14:31:30 +0000 Subject: [Haskell-beginners] order of things in a file.hs? In-Reply-To: References: Message-ID: In all languages that support arbitrary ordering I try to keep exported stuff to the top and private stuff somewhere below. Silent Leaf schrieb am Do., 29. Juni 2017, 16:23: > hi, > > what is your personal practice of ordering data/functions/main/hidden > functions, etc in a haskell file? like all trivial things they are very > hard to decide upon, given that either order of helpers then main function > / value, or the other way round, has tempting pros and cons. > > thanks in advance for your opinion! > _______________________________________________ > 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 saikyun at gmail.com Thu Jun 29 14:47:32 2017 From: saikyun at gmail.com (Jona Ekenberg) Date: Thu, 29 Jun 2017 16:47:32 +0200 Subject: [Haskell-beginners] order of things in a file.hs? In-Reply-To: References: Message-ID: 2017-06-29 16:22 GMT+02:00 Silent Leaf : > hi, > > what is your personal practice of ordering data/functions/main/hidden > functions, etc in a haskell file? like all trivial things they are very > hard to decide upon, given that either order of helpers then main function > / value, or the other way round, has tempting pros and cons. > > thanks in advance for your opinion! > > I've started trying to write my program in a way that makes sense as when reading it from top to bottom, like a story. So if you write a function that calls upon other functions, those functions can come immediately afterwards, if they're relevant, or if their names are enough, they could be put in a different file altogether. Some functions are bigger, like stories of their own. In those cases I generally put them in a new file, like a new chapter. Those should be coherent in themselves, and not depend on the first file in order to make sense. If chapters are dependent on each other in that way, then maybe they have to be rewritten. This is a really course generalization, and I've actually not written code like this for long. But I do think writing code in a way that makes sense as a human reader is important, and humans tend to enjoy reading stories. It doesn't really have to be some sort of magical journey (though it very well could be!), but I think there should be some sort of red thread that goes from one place in the code to the next, without extreme leaps that are hard to understand. > _______________________________________________ > 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 Thu Jun 29 14:48:46 2017 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 29 Jun 2017 16:48:46 +0200 Subject: [Haskell-beginners] How do I map a String and a IO String? In-Reply-To: References: <20170629131602.rwkbt4dypkefx3af@x60s.casa> Message-ID: <20170629144846.3pwqpxytpwcrg4ep@x60s.casa> On Thu, Jun 29, 2017 at 04:15:16PM +0200, Jona Ekenberg wrote: > Thank you for your help Francesco! > > I tried writing it like this: > > > lineOrIo :: String -> IO String > > lineOrIo cs | (isPrefixOf "./" cs) = readFile cs > > | otherwise = return cs > > > > printLines path = do > > file <- readFile path > > lines <- map lineOrIo (lines file) > > print lines You are using `map`, which has signature λ> :t map map :: (a -> b) -> [a] -> [b] But lineOrIo hasn't signature `a -> b` but `a -> m b` (where m is a monad)! mapM will fit the bill: mapM :: Monad m => (a -> m b) -> [a] -> m [b] and that should do it! From silent.leaf0 at gmail.com Thu Jun 29 17:15:26 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Thu, 29 Jun 2017 19:15:26 +0200 Subject: [Haskell-beginners] special polymorphic default of typeclass depending on other typeclasses? Message-ID: hi, say i have the following typeclass: class Foo a where bar :: a -> String looks a lot like the Read typeclass, right? (at least i think it should?) well say it's a different meaning (in other terms i can't or do not want to use Read, but i'd like to implement a default version of bar for those instances that also implement Read. is there a way to do so? -------------- next part -------------- An HTML attachment was scrubbed... URL: From hawu.bnu at gmail.com Thu Jun 29 17:27:21 2017 From: hawu.bnu at gmail.com (Jean Lopes) Date: Thu, 29 Jun 2017 14:27:21 -0300 Subject: [Haskell-beginners] special polymorphic default of typeclass depending on other typeclasses? In-Reply-To: References: Message-ID: It appear more like Show, you can add a constraint to the generic instance instance Show a => Foo a where bar x = show x Em 29 de jun de 2017 2:16 PM, "Silent Leaf" escreveu: hi, say i have the following typeclass: class Foo a where bar :: a -> String looks a lot like the Read typeclass, right? (at least i think it should?) well say it's a different meaning (in other terms i can't or do not want to use Read, but i'd like to implement a default version of bar for those instances that also implement Read. is there a way to do so? _______________________________________________ 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 sylvain at haskus.fr Thu Jun 29 17:34:55 2017 From: sylvain at haskus.fr (Sylvain Henry) Date: Thu, 29 Jun 2017 19:34:55 +0200 Subject: [Haskell-beginners] special polymorphic default of typeclass depending on other typeclasses? In-Reply-To: References: Message-ID: <4103a59a-956e-042f-70f4-1e330b19fee1@haskus.fr> Constraints aren't considered when instance selection is performed. I.e. you can't have both: instance Foo a where ... instance Show a => Foo a where .... But you can use default method signatures: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#default-method-signatures On 29/06/2017 19:27, Jean Lopes wrote: > It appear more like Show, you can add a constraint to the generic > instance > > instance Show a => Foo a where > bar x = show x > > > > > Em 29 de jun de 2017 2:16 PM, "Silent Leaf" > escreveu: > > hi, > > say i have the following typeclass: > > class Foo a where > bar :: a -> String > > looks a lot like the Read typeclass, right? (at least i think it > should?) > well say it's a different meaning (in other terms i can't or do > not want to use Read, but i'd like to implement a default version > of bar for those instances that also implement Read. is there a > way to do so? > > _______________________________________________ > 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 toad3k at gmail.com Thu Jun 29 17:45:14 2017 From: toad3k at gmail.com (David McBride) Date: Thu, 29 Jun 2017 13:45:14 -0400 Subject: [Haskell-beginners] special polymorphic default of typeclass depending on other typeclasses? In-Reply-To: References: Message-ID: This is a common mistake that people who try to use type classes run into. I remember banging my head against it pretty hard when I first started out. There's this temptation that you should be able to write the following: class Foo a where bar :: a -> String instance Read a => Foo a where bar a = read a instance Foo () where bar _ = "bar" But the problem with that is that now () applies to two conflicting classes. It is both a Read and a Foo. So when you go bar (), which instance should fire? The Foo instance or the Read () => Foo instance? There are a multitude of ways you could try to resolve this. Let's say obviously the Read constrainted instance is more specific, we should use that. But then what if the user of your library happens to have a instance Ord a => Foo a in his library, now which one of those is more specific? Read or Ord? Because of all these ambiguities during type checking ghc doesn't even look at the constraint. It would see instance Foo a, and instance Foo (), and then say oh! those are overlapping instances because () could apply to either class before you consider what constraints apply. There's actually several very in depth answers on stackoverflow for this questions like this, such as this one: https://stackoverflow.com/a/3216937/1500583 It might give you some ideas on what to do about this. On Thu, Jun 29, 2017 at 1:15 PM, Silent Leaf wrote: > hi, > > say i have the following typeclass: > > class Foo a where > bar :: a -> String > > looks a lot like the Read typeclass, right? (at least i think it should?) > well say it's a different meaning (in other terms i can't or do not want to > use Read, but i'd like to implement a default version of bar for those > instances that also implement Read. is there a way to do so? > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From silent.leaf0 at gmail.com Thu Jun 29 18:08:08 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Thu, 29 Jun 2017 20:08:08 +0200 Subject: [Haskell-beginners] special polymorphic default of typeclass depending on other typeclasses? In-Reply-To: References: Message-ID: you're right my example is more like Show, it's because i change two times the order of input and output, and did not check at the end if it was what i wanted... Actually i did not mean constraints on instances, especially thereafter ad-hoc polymorphic instances. I rather meant what i said, as in default implementation (as in, right inside the body of the class). like that: class Foo a where bar :: a -> String bar :: Show a => a -> String bar = show -- default implementation: in other terms, if you define an instance without defining this method the idea would be then that if you have Foo (), you can either implement a special version, or leave it to show. mind you i'm not even sure we can define an instance without any specific implementation of method? --that would be allowed: instance Show => Foo () where -- nothing, if it's even legal by default -- and of course that would be allowed to if someone wanted a special function bar :: Foo () => () -> String instance Foo () where bar = .... obviously, i do not mean *both* instances of Foo (), just, one or the other. it would merely be a way to implement ad-hoc polymorphism onto *default implementations of methods*, that is, those inside the body of the class. 2017-06-29 19:45 GMT+02:00 David McBride : > This is a common mistake that people who try to use type classes run > into. I remember banging my head against it pretty hard when I first > started out. > > There's this temptation that you should be able to write the following: > > class Foo a where > bar :: a -> String > > instance Read a => Foo a where > bar a = read a > > instance Foo () where > bar _ = "bar" > > But the problem with that is that now () applies to two conflicting > classes. It is both a Read and a Foo. So when you go bar (), which > instance should fire? The Foo instance or the Read () => Foo > instance? > > There are a multitude of ways you could try to resolve this. Let's > say obviously the Read constrainted instance is more specific, we > should use that. But then what if the user of your library happens to > have a instance Ord a => Foo a in his library, now which one of those > is more specific? Read or Ord? > > Because of all these ambiguities during type checking ghc doesn't even > look at the constraint. It would see instance Foo a, and instance Foo > (), and then say oh! those are overlapping instances because () could > apply to either class before you consider what constraints apply. > > There's actually several very in depth answers on stackoverflow for > this questions like this, such as this one: > https://stackoverflow.com/a/3216937/1500583 It might give you some > ideas on what to do about this. > > On Thu, Jun 29, 2017 at 1:15 PM, Silent Leaf > wrote: > > hi, > > > > say i have the following typeclass: > > > > class Foo a where > > bar :: a -> String > > > > looks a lot like the Read typeclass, right? (at least i think it should?) > > well say it's a different meaning (in other terms i can't or do not want > to > > use Read, but i'd like to implement a default version of bar for those > > instances that also implement Read. is there a way to do so? > > > > _______________________________________________ > > 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 silent.leaf0 at gmail.com Thu Jun 29 18:10:59 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Thu, 29 Jun 2017 20:10:59 +0200 Subject: [Haskell-beginners] special polymorphic default of typeclass depending on other typeclasses? In-Reply-To: References: Message-ID: typos in my previous message (including in the code), don't pay attention, any error is an error :P 2017-06-29 20:08 GMT+02:00 Silent Leaf : > you're right my example is more like Show, it's because i change two times > the order of input and output, and did not check at the end if it was what > i wanted... > > Actually i did not mean constraints on instances, especially thereafter > ad-hoc polymorphic instances. > I rather meant what i said, as in default implementation (as in, right > inside the body of the class). > like that: > > class Foo a where > bar :: a -> String > bar :: Show a => a -> String > bar = show -- default implementation: in other terms, if you define an > instance without defining this method > > the idea would be then that if you have Foo (), you can either implement a > special version, or leave it to show. mind you i'm not even sure we can > define an instance without any specific implementation of method? > > --that would be allowed: > instance Show => Foo () where > -- nothing, if it's even legal by default > > -- and of course that would be allowed to if someone wanted a special > function bar :: Foo () => () -> String > instance Foo () where > bar = .... > > obviously, i do not mean *both* instances of Foo (), just, one or the > other. it would merely be a way to implement ad-hoc polymorphism onto > *default implementations of methods*, that is, those inside the body of the > class. > > > > 2017-06-29 19:45 GMT+02:00 David McBride : > >> This is a common mistake that people who try to use type classes run >> into. I remember banging my head against it pretty hard when I first >> started out. >> >> There's this temptation that you should be able to write the following: >> >> class Foo a where >> bar :: a -> String >> >> instance Read a => Foo a where >> bar a = read a >> >> instance Foo () where >> bar _ = "bar" >> >> But the problem with that is that now () applies to two conflicting >> classes. It is both a Read and a Foo. So when you go bar (), which >> instance should fire? The Foo instance or the Read () => Foo >> instance? >> >> There are a multitude of ways you could try to resolve this. Let's >> say obviously the Read constrainted instance is more specific, we >> should use that. But then what if the user of your library happens to >> have a instance Ord a => Foo a in his library, now which one of those >> is more specific? Read or Ord? >> >> Because of all these ambiguities during type checking ghc doesn't even >> look at the constraint. It would see instance Foo a, and instance Foo >> (), and then say oh! those are overlapping instances because () could >> apply to either class before you consider what constraints apply. >> >> There's actually several very in depth answers on stackoverflow for >> this questions like this, such as this one: >> https://stackoverflow.com/a/3216937/1500583 It might give you some >> ideas on what to do about this. >> >> On Thu, Jun 29, 2017 at 1:15 PM, Silent Leaf >> wrote: >> > hi, >> > >> > say i have the following typeclass: >> > >> > class Foo a where >> > bar :: a -> String >> > >> > looks a lot like the Read typeclass, right? (at least i think it >> should?) >> > well say it's a different meaning (in other terms i can't or do not >> want to >> > use Read, but i'd like to implement a default version of bar for those >> > instances that also implement Read. is there a way to do so? >> > >> > _______________________________________________ >> > 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 silent.leaf0 at gmail.com Thu Jun 29 18:13:56 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Thu, 29 Jun 2017 20:13:56 +0200 Subject: [Haskell-beginners] special polymorphic default of typeclass depending on other typeclasses? In-Reply-To: References: Message-ID: Sylvain Henri's link did the trick, that's what i was looking for (they call it generic implementation). in terms of terminology, is there an intrinsic difference between generic and polymorphic? 2017-06-29 20:10 GMT+02:00 Silent Leaf : > typos in my previous message (including in the code), don't pay attention, > any error is an error :P > > 2017-06-29 20:08 GMT+02:00 Silent Leaf : > >> you're right my example is more like Show, it's because i change two >> times the order of input and output, and did not check at the end if it was >> what i wanted... >> >> Actually i did not mean constraints on instances, especially thereafter >> ad-hoc polymorphic instances. >> I rather meant what i said, as in default implementation (as in, right >> inside the body of the class). >> like that: >> >> class Foo a where >> bar :: a -> String >> bar :: Show a => a -> String >> bar = show -- default implementation: in other terms, if you define an >> instance without defining this method >> >> the idea would be then that if you have Foo (), you can either implement >> a special version, or leave it to show. mind you i'm not even sure we can >> define an instance without any specific implementation of method? >> >> --that would be allowed: >> instance Show => Foo () where >> -- nothing, if it's even legal by default >> >> -- and of course that would be allowed to if someone wanted a special >> function bar :: Foo () => () -> String >> instance Foo () where >> bar = .... >> >> obviously, i do not mean *both* instances of Foo (), just, one or the >> other. it would merely be a way to implement ad-hoc polymorphism onto >> *default implementations of methods*, that is, those inside the body of the >> class. >> >> >> >> 2017-06-29 19:45 GMT+02:00 David McBride : >> >>> This is a common mistake that people who try to use type classes run >>> into. I remember banging my head against it pretty hard when I first >>> started out. >>> >>> There's this temptation that you should be able to write the following: >>> >>> class Foo a where >>> bar :: a -> String >>> >>> instance Read a => Foo a where >>> bar a = read a >>> >>> instance Foo () where >>> bar _ = "bar" >>> >>> But the problem with that is that now () applies to two conflicting >>> classes. It is both a Read and a Foo. So when you go bar (), which >>> instance should fire? The Foo instance or the Read () => Foo >>> instance? >>> >>> There are a multitude of ways you could try to resolve this. Let's >>> say obviously the Read constrainted instance is more specific, we >>> should use that. But then what if the user of your library happens to >>> have a instance Ord a => Foo a in his library, now which one of those >>> is more specific? Read or Ord? >>> >>> Because of all these ambiguities during type checking ghc doesn't even >>> look at the constraint. It would see instance Foo a, and instance Foo >>> (), and then say oh! those are overlapping instances because () could >>> apply to either class before you consider what constraints apply. >>> >>> There's actually several very in depth answers on stackoverflow for >>> this questions like this, such as this one: >>> https://stackoverflow.com/a/3216937/1500583 It might give you some >>> ideas on what to do about this. >>> >>> On Thu, Jun 29, 2017 at 1:15 PM, Silent Leaf >>> wrote: >>> > hi, >>> > >>> > say i have the following typeclass: >>> > >>> > class Foo a where >>> > bar :: a -> String >>> > >>> > looks a lot like the Read typeclass, right? (at least i think it >>> should?) >>> > well say it's a different meaning (in other terms i can't or do not >>> want to >>> > use Read, but i'd like to implement a default version of bar for those >>> > instances that also implement Read. is there a way to do so? >>> > >>> > _______________________________________________ >>> > 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 silent.leaf0 at gmail.com Thu Jun 29 18:36:26 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Thu, 29 Jun 2017 20:36:26 +0200 Subject: [Haskell-beginners] lost a typeclass maybe? Message-ID: hi, i keep trying to find something that feels terribly obvious but i can't make any link. say i have a function of the following type: foo :: (a, b) -> ([a], [b]) -> ([a], [b]) or perhaps more generally: foo :: SomeClass f => f a b -> f [a] [b] -> f [a] [b] is SomeClass supposed to be BiFunctor or something else? clearly, what i want to do is to combine the elements of the first pair into the elements of the second, preferrably without pattern matching, that is, merely in function of (:). i think the problem with bifunctor is that it seems to only allow the application of both arguments in a separate fashion. but here the first argument is in one block, that is (a,b). i know, ofc we could do something like: foo pair pairList = bimap (fst pair :) (snd pair:) pairList or maybe use curry or whatever. but i'd like my pair to not need to be unboxed! is there not a way to not have to manually call fst and snd? are both of these functions typeclass methods by any chance? then we could write a generalized function that could work for any f = (:) or any kind of pair-like thingy. mind you i'm not sure to which extent it would keep the opacity of the type constructor (,). especially, it's a bit like unboxing the Maybe type constructor: you can do it manually by pattern matching, but when you have the exact same issue but with IO, it's not possible anymore to unbox the underlying type equally, i bet one could invent IO a b, in a way that you could not just get a and b, but you could somehow implement opaqueBimap :: (i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b) with here of course f = (,), k = [] or List, and (i -> k i) = (:) -------------- next part -------------- An HTML attachment was scrubbed... URL: From silent.leaf0 at gmail.com Thu Jun 29 18:38:01 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Thu, 29 Jun 2017 20:38:01 +0200 Subject: [Haskell-beginners] lost a typeclass maybe? In-Reply-To: References: Message-ID: well, i sent once more my message too early by mistake. when i say invent IO a b, i don't actually mean an IO type, i meant just, any type you can't manually unbox via pattern matching or otherwise. 2017-06-29 20:36 GMT+02:00 Silent Leaf : > hi, > > i keep trying to find something that feels terribly obvious but i can't > make any link. > > say i have a function of the following type: > > foo :: (a, b) -> ([a], [b]) -> ([a], [b]) > or perhaps more generally: > foo :: SomeClass f => f a b -> f [a] [b] -> f [a] [b] > > is SomeClass supposed to be BiFunctor or something else? > clearly, what i want to do is to combine the elements of the first pair > into the elements of the second, preferrably without pattern matching, that > is, merely in function of (:). > > i think the problem with bifunctor is that it seems to only allow the > application of both arguments in a separate fashion. but here the first > argument is in one block, that is (a,b). > i know, ofc we could do something like: > foo pair pairList = bimap (fst pair :) (snd pair:) pairList > or maybe use curry or whatever. but i'd like my pair to not need to be > unboxed! > > is there not a way to not have to manually call fst and snd? are both of > these functions typeclass methods by any chance? then we could write a > generalized function that could work for any f = (:) or any kind of > pair-like thingy. mind you i'm not sure to which extent it would keep the > opacity of the type constructor (,). > > especially, it's a bit like unboxing the Maybe type constructor: you can > do it manually by pattern matching, but when you have the exact same issue > but with IO, it's not possible anymore to unbox the underlying type > equally, i bet one could invent IO a b, in a way that you could not just > get a and b, but you could somehow implement > opaqueBimap :: (i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b) > with here of course f = (,), k = [] or List, and (i -> k i) = (:) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From silent.leaf0 at gmail.com Thu Jun 29 18:44:56 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Thu, 29 Jun 2017 20:44:56 +0200 Subject: [Haskell-beginners] lost a typeclass maybe? In-Reply-To: References: Message-ID: ah, obviously, the first parameter is meant to be (i -> k i -> k i). mind you my opaqueBimap looks very peculiar... if i isolate half of f a b: Foo :: (i -> k i -> k i) -> f a -> f (k a) -> f (k a) Foo f fa fas = lift f fa fas so maybe i'd need a BiApplicative? 2017-06-29 20:38 GMT+02:00 Silent Leaf : > well, i sent once more my message too early by mistake. > when i say invent IO a b, i don't actually mean an IO type, i meant just, > any type you can't manually unbox via pattern matching or otherwise. > > 2017-06-29 20:36 GMT+02:00 Silent Leaf : > >> hi, >> >> i keep trying to find something that feels terribly obvious but i can't >> make any link. >> >> say i have a function of the following type: >> >> foo :: (a, b) -> ([a], [b]) -> ([a], [b]) >> or perhaps more generally: >> foo :: SomeClass f => f a b -> f [a] [b] -> f [a] [b] >> >> is SomeClass supposed to be BiFunctor or something else? >> clearly, what i want to do is to combine the elements of the first pair >> into the elements of the second, preferrably without pattern matching, that >> is, merely in function of (:). >> >> i think the problem with bifunctor is that it seems to only allow the >> application of both arguments in a separate fashion. but here the first >> argument is in one block, that is (a,b). >> i know, ofc we could do something like: >> foo pair pairList = bimap (fst pair :) (snd pair:) pairList >> or maybe use curry or whatever. but i'd like my pair to not need to be >> unboxed! >> >> is there not a way to not have to manually call fst and snd? are both of >> these functions typeclass methods by any chance? then we could write a >> generalized function that could work for any f = (:) or any kind of >> pair-like thingy. mind you i'm not sure to which extent it would keep the >> opacity of the type constructor (,). >> >> especially, it's a bit like unboxing the Maybe type constructor: you can >> do it manually by pattern matching, but when you have the exact same issue >> but with IO, it's not possible anymore to unbox the underlying type >> equally, i bet one could invent IO a b, in a way that you could not just >> get a and b, but you could somehow implement >> opaqueBimap :: (i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b) >> with here of course f = (,), k = [] or List, and (i -> k i) = (:) >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From silent.leaf0 at gmail.com Thu Jun 29 18:51:30 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Thu, 29 Jun 2017 20:51:30 +0200 Subject: [Haskell-beginners] lost a typeclass maybe? In-Reply-To: References: Message-ID: hey it does seem to exist, so that would be foo :: (BiApplicative f) :: (i -> k i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b) foo f fab fkakb = bipure f f <<$>> fab <<*>> fkakb pretty neat. i'm not sure the <<$>> operator exist, but the `ap` one does apparently. however i'm not sure that many people use BiApplicative ^^ But hey why not. don't pay attention to my code here, it's terribly typoed, i have no idea why i put the uppercase on the function Foo... 2017-06-29 20:44 GMT+02:00 Silent Leaf : > ah, obviously, the first parameter is meant to be (i -> k i -> k i). > mind you my opaqueBimap looks very peculiar... > if i isolate half of f a b: > Foo :: (i -> k i -> k i) -> f a -> f (k a) -> f (k a) > Foo f fa fas = lift f fa fas > so maybe i'd need a BiApplicative? > > 2017-06-29 20:38 GMT+02:00 Silent Leaf : > >> well, i sent once more my message too early by mistake. >> when i say invent IO a b, i don't actually mean an IO type, i meant just, >> any type you can't manually unbox via pattern matching or otherwise. >> >> 2017-06-29 20:36 GMT+02:00 Silent Leaf : >> >>> hi, >>> >>> i keep trying to find something that feels terribly obvious but i can't >>> make any link. >>> >>> say i have a function of the following type: >>> >>> foo :: (a, b) -> ([a], [b]) -> ([a], [b]) >>> or perhaps more generally: >>> foo :: SomeClass f => f a b -> f [a] [b] -> f [a] [b] >>> >>> is SomeClass supposed to be BiFunctor or something else? >>> clearly, what i want to do is to combine the elements of the first pair >>> into the elements of the second, preferrably without pattern matching, that >>> is, merely in function of (:). >>> >>> i think the problem with bifunctor is that it seems to only allow the >>> application of both arguments in a separate fashion. but here the first >>> argument is in one block, that is (a,b). >>> i know, ofc we could do something like: >>> foo pair pairList = bimap (fst pair :) (snd pair:) pairList >>> or maybe use curry or whatever. but i'd like my pair to not need to be >>> unboxed! >>> >>> is there not a way to not have to manually call fst and snd? are both of >>> these functions typeclass methods by any chance? then we could write a >>> generalized function that could work for any f = (:) or any kind of >>> pair-like thingy. mind you i'm not sure to which extent it would keep the >>> opacity of the type constructor (,). >>> >>> especially, it's a bit like unboxing the Maybe type constructor: you can >>> do it manually by pattern matching, but when you have the exact same issue >>> but with IO, it's not possible anymore to unbox the underlying type >>> equally, i bet one could invent IO a b, in a way that you could not just >>> get a and b, but you could somehow implement >>> opaqueBimap :: (i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b) >>> with here of course f = (,), k = [] or List, and (i -> k i) = (:) >>> >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjakway at nyu.edu Thu Jun 29 21:05:23 2017 From: tjakway at nyu.edu (Thomas Jakway) Date: Thu, 29 Jun 2017 17:05:23 -0400 Subject: [Haskell-beginners] lost a typeclass maybe? In-Reply-To: References: Message-ID: For what it's worth I think Bifunctors are more useful than one might think given the lack of attention they get. On Jun 29, 2017 2:51 PM, "Silent Leaf" wrote: > hey it does seem to exist, so that would be > > foo :: (BiApplicative f) :: (i -> k i -> k i) -> f a b -> f (k a) (k b) -> > f (k a) (k b) > foo f fab fkakb = bipure f f <<$>> fab <<*>> fkakb > > pretty neat. i'm not sure the <<$>> operator exist, but the `ap` one does > apparently. > however i'm not sure that many people use BiApplicative ^^ But hey why not. > > don't pay attention to my code here, it's terribly typoed, i have no idea > why i put the uppercase on the function Foo... > > 2017-06-29 20:44 GMT+02:00 Silent Leaf : > >> ah, obviously, the first parameter is meant to be (i -> k i -> k i). >> mind you my opaqueBimap looks very peculiar... >> if i isolate half of f a b: >> Foo :: (i -> k i -> k i) -> f a -> f (k a) -> f (k a) >> Foo f fa fas = lift f fa fas >> so maybe i'd need a BiApplicative? >> >> 2017-06-29 20:38 GMT+02:00 Silent Leaf : >> >>> well, i sent once more my message too early by mistake. >>> when i say invent IO a b, i don't actually mean an IO type, i meant >>> just, any type you can't manually unbox via pattern matching or otherwise. >>> >>> 2017-06-29 20:36 GMT+02:00 Silent Leaf : >>> >>>> hi, >>>> >>>> i keep trying to find something that feels terribly obvious but i can't >>>> make any link. >>>> >>>> say i have a function of the following type: >>>> >>>> foo :: (a, b) -> ([a], [b]) -> ([a], [b]) >>>> or perhaps more generally: >>>> foo :: SomeClass f => f a b -> f [a] [b] -> f [a] [b] >>>> >>>> is SomeClass supposed to be BiFunctor or something else? >>>> clearly, what i want to do is to combine the elements of the first pair >>>> into the elements of the second, preferrably without pattern matching, that >>>> is, merely in function of (:). >>>> >>>> i think the problem with bifunctor is that it seems to only allow the >>>> application of both arguments in a separate fashion. but here the first >>>> argument is in one block, that is (a,b). >>>> i know, ofc we could do something like: >>>> foo pair pairList = bimap (fst pair :) (snd pair:) pairList >>>> or maybe use curry or whatever. but i'd like my pair to not need to be >>>> unboxed! >>>> >>>> is there not a way to not have to manually call fst and snd? are both >>>> of these functions typeclass methods by any chance? then we could write a >>>> generalized function that could work for any f = (:) or any kind of >>>> pair-like thingy. mind you i'm not sure to which extent it would keep the >>>> opacity of the type constructor (,). >>>> >>>> especially, it's a bit like unboxing the Maybe type constructor: you >>>> can do it manually by pattern matching, but when you have the exact same >>>> issue but with IO, it's not possible anymore to unbox the underlying type >>>> equally, i bet one could invent IO a b, in a way that you could not >>>> just get a and b, but you could somehow implement >>>> opaqueBimap :: (i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b) >>>> with here of course f = (,), k = [] or List, and (i -> k i) = (:) >>>> >>> >>> >> > > _______________________________________________ > 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 silent.leaf0 at gmail.com Fri Jun 30 08:56:35 2017 From: silent.leaf0 at gmail.com (Silent Leaf) Date: Fri, 30 Jun 2017 10:56:35 +0200 Subject: [Haskell-beginners] lost a typeclass maybe? In-Reply-To: References: Message-ID: Good to know, thanks :) Then i won't automatically doubt my program structure if one day i end up needing it. 2017-06-29 23:05 GMT+02:00 Thomas Jakway : > For what it's worth I think Bifunctors are more useful than one might > think given the lack of attention they get. > > On Jun 29, 2017 2:51 PM, "Silent Leaf" wrote: > >> hey it does seem to exist, so that would be >> >> foo :: (BiApplicative f) :: (i -> k i -> k i) -> f a b -> f (k a) (k b) >> -> f (k a) (k b) >> foo f fab fkakb = bipure f f <<$>> fab <<*>> fkakb >> >> pretty neat. i'm not sure the <<$>> operator exist, but the `ap` one does >> apparently. >> however i'm not sure that many people use BiApplicative ^^ But hey why >> not. >> >> don't pay attention to my code here, it's terribly typoed, i have no idea >> why i put the uppercase on the function Foo... >> >> 2017-06-29 20:44 GMT+02:00 Silent Leaf : >> >>> ah, obviously, the first parameter is meant to be (i -> k i -> k i). >>> mind you my opaqueBimap looks very peculiar... >>> if i isolate half of f a b: >>> Foo :: (i -> k i -> k i) -> f a -> f (k a) -> f (k a) >>> Foo f fa fas = lift f fa fas >>> so maybe i'd need a BiApplicative? >>> >>> 2017-06-29 20:38 GMT+02:00 Silent Leaf : >>> >>>> well, i sent once more my message too early by mistake. >>>> when i say invent IO a b, i don't actually mean an IO type, i meant >>>> just, any type you can't manually unbox via pattern matching or otherwise. >>>> >>>> 2017-06-29 20:36 GMT+02:00 Silent Leaf : >>>> >>>>> hi, >>>>> >>>>> i keep trying to find something that feels terribly obvious but i >>>>> can't make any link. >>>>> >>>>> say i have a function of the following type: >>>>> >>>>> foo :: (a, b) -> ([a], [b]) -> ([a], [b]) >>>>> or perhaps more generally: >>>>> foo :: SomeClass f => f a b -> f [a] [b] -> f [a] [b] >>>>> >>>>> is SomeClass supposed to be BiFunctor or something else? >>>>> clearly, what i want to do is to combine the elements of the first >>>>> pair into the elements of the second, preferrably without pattern matching, >>>>> that is, merely in function of (:). >>>>> >>>>> i think the problem with bifunctor is that it seems to only allow the >>>>> application of both arguments in a separate fashion. but here the first >>>>> argument is in one block, that is (a,b). >>>>> i know, ofc we could do something like: >>>>> foo pair pairList = bimap (fst pair :) (snd pair:) pairList >>>>> or maybe use curry or whatever. but i'd like my pair to not need to be >>>>> unboxed! >>>>> >>>>> is there not a way to not have to manually call fst and snd? are both >>>>> of these functions typeclass methods by any chance? then we could write a >>>>> generalized function that could work for any f = (:) or any kind of >>>>> pair-like thingy. mind you i'm not sure to which extent it would keep the >>>>> opacity of the type constructor (,). >>>>> >>>>> especially, it's a bit like unboxing the Maybe type constructor: you >>>>> can do it manually by pattern matching, but when you have the exact same >>>>> issue but with IO, it's not possible anymore to unbox the underlying type >>>>> equally, i bet one could invent IO a b, in a way that you could not >>>>> just get a and b, but you could somehow implement >>>>> opaqueBimap :: (i -> k i) -> f a b -> f (k a) (k b) -> f (k a) (k b) >>>>> with here of course f = (,), k = [] or List, and (i -> k i) = (:) >>>>> >>>> >>>> >>> >> >> _______________________________________________ >> 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: