From laiboonh at gmail.com Tue Nov 1 15:42:06 2016 From: laiboonh at gmail.com (Lai Boon Hui) Date: Tue, 1 Nov 2016 23:42:06 +0800 Subject: [Haskell-beginners] Sum a tuple of Monoids Message-ID: Hi all, Is it possible to sum a tuple of monoids for example sum (Just 1, Nothing) expected result Just 1 sum (Just 1, Just 2) expected result Just 3 -- Best Regards, Boon Hui -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Tue Nov 1 15:55:38 2016 From: imantc at gmail.com (Imants Cekusins) Date: Tue, 1 Nov 2016 16:55:38 +0100 Subject: [Haskell-beginners] Sum a tuple of Monoids In-Reply-To: References: Message-ID: > sum a tuple of monoids here is something, not quite what you are looking for, but close: Monoid a => Monoid (Maybe a) (Monoid a, Monoid b) => Monoid (a, b) mappend (Just [1], Just [2,3]) (Nothing, Just [5])::(Maybe [Int],Maybe [Int]) (Just [1],Just [2,3,5]) ​ -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Tue Nov 1 15:58:07 2016 From: toad3k at gmail.com (David McBride) Date: Tue, 1 Nov 2016 11:58:07 -0400 Subject: [Haskell-beginners] Sum a tuple of Monoids In-Reply-To: References: Message-ID: I don't know if there is generally, but some people would use the lens library to do such things. import Control.Lens > sumOf (each . _Just) (Just 1, Nothing, Just 2) 3 Just keep in mind that each member of the tuple must be the same type. On Tue, Nov 1, 2016 at 11:42 AM, Lai Boon Hui wrote: > Hi all, > > Is it possible to sum a tuple of monoids for example > > sum (Just 1, Nothing) > > expected result Just 1 > > sum (Just 1, Just 2) > > expected result Just 3 > > -- > Best Regards, > Boon Hui > > _______________________________________________ > 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 jolivetdesonte at yahoo.com Thu Nov 3 04:49:36 2016 From: jolivetdesonte at yahoo.com (Desonte Jolivet) Date: Thu, 3 Nov 2016 04:49:36 +0000 (UTC) Subject: [Haskell-beginners] =?utf-8?q?Java-Bridge=2C_Ambiguous_occurrence?= =?utf-8?b?IOKAmDwk4oCZ?= References: <1487192299.175038.1478148576572.ref@mail.yahoo.com> Message-ID: <1487192299.175038.1478148576572@mail.yahoo.com> Hello All: Im interested interfacing with the JVM through Haskell and I found this neat library on Hackag name java-bridge although when I try and install with cabal I get the below error, "Ambiguous occurrence ‘<$’". Any tips on how to clear this up or how I should proceed would be very helpful, Thank you all in advance. src/Foreign/Java/IO.hs:5:7: Warning:    -XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS[ 1 of 24] Compiling Foreign.Java.Tutorial ( src/Foreign/Java/Tutorial.hs, dist/build/Foreign/Java/Tutorial.o )[ 2 of 24] Compiling Foreign.Java.IO  ( src/Foreign/Java/IO.hs, dist/build/Foreign/Java/IO.o )[ 3 of 24] Compiling Foreign.Java.Control ( src/Foreign/Java/Control.hs, dist/build/Foreign/Java/Control.o )[ 4 of 24] Compiling Foreign.Java.Bindings.ReflectHaskell ( src/Foreign/Java/Bindings/ReflectHaskell.hs, dist/build/Foreign/Java/Bindings/ReflectHaskell.o )[ 5 of 24] Compiling Foreign.Java.Bindings.Haskell2Java ( dist/build/Foreign/Java/Bindings/Haskell2Java.hs, dist/build/Foreign/Java/Bindings/Haskell2Java.o )[ 6 of 24] Compiling Foreign.Java.Bindings.HaskellTypes ( src/Foreign/Java/Bindings/HaskellTypes.hs, dist/build/Foreign/Java/Bindings/HaskellTypes.o )[ 7 of 24] Compiling Foreign.Java.Bindings.JavaSE6 ( src/Foreign/Java/Bindings/JavaSE6.hs, dist/build/Foreign/Java/Bindings/JavaSE6.o )[ 8 of 24] Compiling Foreign.Java.Utils ( src/Foreign/Java/Utils.hs, dist/build/Foreign/Java/Utils.o )[ 9 of 24] Compiling Foreign.Java.Bindings.JavaTypes ( src/Foreign/Java/Bindings/JavaTypes.hs, dist/build/Foreign/Java/Bindings/JavaTypes.o )[10 of 24] Compiling Foreign.Java.Util ( src/Foreign/Java/Util.hs, dist/build/Foreign/Java/Util.o ) src/Foreign/Java/Util.hs:5:19:    Ambiguous occurrence ‘<$’    It could refer to either ‘Foreign.Java.Util.<$’,                             defined at src/Foreign/Java/Util.hs:24:1                          or ‘Prelude.<$’,                             imported from ‘Prelude’ at src/Foreign/Java/Util.hs:4:8-24                             (and originally defined in ‘GHC.Base’)cabal: Error: some packages failed to install:java-bridge-0.20130606.3 failed during the building phase. The exception was:ExitFailure 1 -Jo -------------- next part -------------- An HTML attachment was scrubbed... URL: From defigueiredo at ucdavis.edu Thu Nov 3 15:43:33 2016 From: defigueiredo at ucdavis.edu (Dimitri DeFigueiredo) Date: Thu, 3 Nov 2016 09:43:33 -0600 Subject: [Haskell-beginners] Constructor classes and type classes. In-Reply-To: References: Message-ID: <80e94e0d-d05b-3606-290f-edcd7d8ef25b@ucdavis.edu> Hi Patrick, I am not sure I understand what you are trying to do, but here are some thoughts. - your use of the names `typeVar` and `typeCons` make total sense to me. But your name `dataCons` in the definition of SetClass2 does not. You are only talking about types here. All you are doing is talking about *type* constructors. You are not constructing a specific value of that type. Maybe one way to see the difference between the type constructors and the data constructors is to change your first line to: data SetType typeVar = SetTypeDataConstructor [typeVar] deriving Show - I also don't understand why you named your type variable `dataVariable` instead of sticking to `typeVar` in SetClass3. It is a *type* variable in the type signature of the functions in the type class. - I don't understand what you mean by a "constructor class". My simple understanding of what a type constructors and data constructors are is here https://wiki.haskell.org/Constructor#Type_constructor. - I don't see the terms super class and sub class ever used in haskell land. Although I do understand they make sense, I think they are really OO terms. I've tried to map OO concepts into haskell and there are many different ways to do it. The best description of all those ways that I found was in Oleg Kiselyov's work https://arxiv.org/pdf/cs/0509027.pdf - I think parametric polymorphism as used in haskell forces us to compare types in terms of equality constraints (this type is "the same" as that), whereas subtype polymorphism as used in OO languages forces us to think in terms of inequalities (this type is "more specific" than that). I think those force fundamentally different ways to think about and model your problems. I would encourage you to use equality as much as possible, but if you want to model subtyping in haskell, I think Oleg's work above has a few approaches that I think are better than type classes. In particular, in OO there was always an ambiguity between modelling subtyping with inheritance or with a "has a" relationship when the subclass explicitly contains an object of the superclass. You can use the latter idea in haskell, Oleg's work has a good way to do it. Hope this helps. Cheers, Dimitri > From: PATRICK BROWNE > To: The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > Subject: [Haskell-beginners] Constructor classes and type classes. > Message-ID: > > Content-Type: text/plain; charset="utf-8" > > {- > I am trying to understand constructor classes and their relationship with > ordinary type classes. > I wrote the code below to help me understand the distinction. The code is > only for explanatory purposes, set operations use a tuple syntax. > > I use the naming convention of 'typeVar', 'typeCons', and 'dataCons' for > type variables, type constructors, and data constructors respectively. > Question1: > Is my naming convention correct? > I am particularly concerned about SetClass3 where the super class seems to > use a type constructor but the subclass seems to use the same term as a > data constructor. > > Q2: > In this case constructor classes and type classes seem to provide similar > functionality. > In general what situation are each best suited? > -} > > import Data.List > data SetType typeVar = SetType [typeVar] deriving Show > > > class SetClass1 typeCons where > member1 :: Eq typeVar => (typeVar, typeCons typeVar) -> Bool > intersect1 :: (Eq typeVar,Show typeVar) => (typeCons typeVar, typeCons > typeVar) -> typeCons typeVar > > > class SetClass2 dataCons typeVar where > member2 :: (typeVar, (dataCons typeVar)) -> Bool > intersect2 :: (dataCons typeVar, dataCons typeVar) -> dataCons typeVar > > > class SetClass1 typeCons => SetClass3 typeCons dataVariable where > union3 :: (Eq dataVariable,Show dataVariable) => (typeCons dataVariable, > typeCons dataVariable) -> typeCons dataVariable > > instance SetClass1 SetType where > member1 (x ,(SetType y)) = elem x y > intersect1 ((SetType x),(SetType y)) = SetType (intersect x y) > > instance SetClass2 SetType Int where > member2 (x ,SetType y) = elem x y > intersect2 (SetType x,SetType y) = SetType (intersect x y) > > instance SetClass3 SetType Int where > union3 (SetType x,SetType y) = SetType (union x y) > > > test1a = member1 (1, (SetType [1,2])) > test1b = intersect1 ((SetType [1,3,4]),(SetType [1,2])) > test2a = member2 (1, (SetType [1::Int])) > test2b = intersect2 ((SetType [1::Int]), (SetType [(1::Int)])) > test3a = union3 ((SetType [1::Int,2::Int,3::Int]),(SetType [4::Int,5::Int])) > -- 2E45 D376 A744 C671 5100 A261 210B 8461 0FB0 CA1F -- 2E45 D376 A744 C671 5100 A261 210B 8461 0FB0 CA1F From patrick.browne at dit.ie Thu Nov 3 17:51:14 2016 From: patrick.browne at dit.ie (PATRICK BROWNE) Date: Thu, 3 Nov 2016 17:51:14 +0000 Subject: [Haskell-beginners] Constructor classes and type classes. In-Reply-To: <80e94e0d-d05b-3606-290f-edcd7d8ef25b@ucdavis.edu> References: <80e94e0d-d05b-3606-290f-edcd7d8ef25b@ucdavis.edu> Message-ID: Dimitri, Thanks for taking the time and effort to respond. Your comments have clarified some of my confusion. My motivation is that I am trying to implement the code from a paper with the following data and classes: {-# LANGUAGE MultiParamTypeClasses #-} data TimeFacts t = Bef (t, t, TimeFacts t) | New class SetClass t where class SetClass t => Time l t where class Time l t => TimeE l t where class Time l t => TimeTO l t where However I cannot get the instances to compile: instance SetClass (TimeFacts t) where -- OK instance (SetClass t) => Time TimeFacts t where -- Expecting one more argument to 'TimeFacts' instance TimeE TimeFacts t where -- Expecting one more argument to 'TimeFacts' instance TimeTO TimeFacts t where -- Expecting one more argument to 'TimeFacts' Note, I am only using the headings for the classes and instances, which should be OK. Any pointers to a solution would be much appreciated. Regards, Pat -- 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 imantc at gmail.com Thu Nov 3 18:05:10 2016 From: imantc at gmail.com (Imants Cekusins) Date: Thu, 3 Nov 2016 19:05:10 +0100 Subject: [Haskell-beginners] Constructor classes and type classes. In-Reply-To: References: <80e94e0d-d05b-3606-290f-edcd7d8ef25b@ucdavis.edu> Message-ID: this builds. not sure if the instances are as intended {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-} module SetClass where data TimeFacts t = Bef (t, t, TimeFacts t) | New class SetClass t where class SetClass t => Time l t where class Time l t => TimeE l t where class Time l t => TimeTO l t where instance SetClass (TimeFacts t) where -- OK instance (SetClass t) => Time (TimeFacts t) t where instance (SetClass t) => TimeE (TimeFacts t) t where instance (SetClass t) => TimeTO (TimeFacts t) t where ​ -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Thu Nov 3 19:58:01 2016 From: toad3k at gmail.com (David McBride) Date: Thu, 3 Nov 2016 15:58:01 -0400 Subject: [Haskell-beginners] =?utf-8?q?Java-Bridge=2C_Ambiguous_occurrence?= =?utf-8?b?IOKAmDwk4oCZ?= In-Reply-To: <1487192299.175038.1478148576572@mail.yahoo.com> References: <1487192299.175038.1478148576572.ref@mail.yahoo.com> <1487192299.175038.1478148576572@mail.yahoo.com> Message-ID: That specific error can be fixed by simply removing that function and its export from src/Foreign/Java/Util.hs as it is exported by Prelude now and there is no reason for it to be in his code. Given the amount of bitrot that package has probably suffered, I'm not sure how much faith I have that it will work. That said, if you are enterprising it probably wouldn't be too hard to fix all these errors. In other news there are some other recent developments on this front. There is an inline-java project that looks very promising and may actually be very simple to get up and working with stack. https://github.com/tweag/inline-java#readme On Thu, Nov 3, 2016 at 12:49 AM, Desonte Jolivet wrote: > Hello All: > > Im interested interfacing with the JVM through Haskell and I found this > neat library on Hackag name java-bridge although when I try and install > with cabal I get the below error, "Ambiguous occurrence ‘<$’". Any tips on > how to clear this up or how I should proceed would be very helpful, Thank > you all in advance. > > src/Foreign/Java/IO.hs:5:7: Warning: > -XOverlappingInstances is deprecated: instead use per-instance pragmas > OVERLAPPING/OVERLAPPABLE/OVERLAPS > [ 1 of 24] Compiling Foreign.Java.Tutorial ( src/Foreign/Java/Tutorial.hs, > dist/build/Foreign/Java/Tutorial.o ) > [ 2 of 24] Compiling Foreign.Java.IO ( src/Foreign/Java/IO.hs, > dist/build/Foreign/Java/IO.o ) > [ 3 of 24] Compiling Foreign.Java.Control ( src/Foreign/Java/Control.hs, > dist/build/Foreign/Java/Control.o ) > [ 4 of 24] Compiling Foreign.Java.Bindings.ReflectHaskell ( > src/Foreign/Java/Bindings/ReflectHaskell.hs, dist/build/Foreign/Java/Bindings/ReflectHaskell.o > ) > [ 5 of 24] Compiling Foreign.Java.Bindings.Haskell2Java ( > dist/build/Foreign/Java/Bindings/Haskell2Java.hs, dist/build/Foreign/Java/Bindings/Haskell2Java.o > ) > [ 6 of 24] Compiling Foreign.Java.Bindings.HaskellTypes ( > src/Foreign/Java/Bindings/HaskellTypes.hs, dist/build/Foreign/Java/Bindings/HaskellTypes.o > ) > [ 7 of 24] Compiling Foreign.Java.Bindings.JavaSE6 ( > src/Foreign/Java/Bindings/JavaSE6.hs, dist/build/Foreign/Java/Bindings/JavaSE6.o > ) > [ 8 of 24] Compiling Foreign.Java.Utils ( src/Foreign/Java/Utils.hs, > dist/build/Foreign/Java/Utils.o ) > [ 9 of 24] Compiling Foreign.Java.Bindings.JavaTypes ( > src/Foreign/Java/Bindings/JavaTypes.hs, dist/build/Foreign/Java/Bindings/JavaTypes.o > ) > [10 of 24] Compiling Foreign.Java.Util ( src/Foreign/Java/Util.hs, > dist/build/Foreign/Java/Util.o ) > > src/Foreign/Java/Util.hs:5:19: > Ambiguous occurrence ‘<$’ > It could refer to either ‘Foreign.Java.Util.<$’, > defined at src/Foreign/Java/Util.hs:24:1 > or ‘Prelude.<$’, > imported from ‘Prelude’ at > src/Foreign/Java/Util.hs:4:8-24 > (and originally defined in ‘GHC.Base’) > cabal: Error: some packages failed to install: > java-bridge-0.20130606.3 failed during the building phase. The exception > was: > ExitFailure 1 > > > -Jo > > _______________________________________________ > 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 Fri Nov 4 00:10:26 2016 From: patrick.browne at dit.ie (PATRICK BROWNE) Date: Fri, 4 Nov 2016 00:10:26 +0000 Subject: [Haskell-beginners] Constructor classes and type classes. Message-ID: Imants Thanks for the sanity check on the instances. I am concerned about the use of the function immsucc' from the same paper , which is defined in instances the Time class (but omitted from the class). The function immsucc' is first used without arguments, which to me implies that it 'might' a function passed to the higher-order closure function. It is then used as just an ordinary function with arguments. I have found a version of closure based on Craft of Function Programming. which does not require a function as an argument. So basically my question is: does the usage of immsucc' make sense in the code below?, do the types match up? Regards, Pat data TimeFacts t = Bef (t, t, TimeFacts t) | New class SetClass t => Time l t where new :: (t, t) -> l t bef :: (t, t, l t) -> l t succ , pred :: (t, l t) -> Set t immsucc , immpred :: (t, l t) -> Set t before, after :: (t, t, l t) -> Bool immedbefore, immedafter :: (t, t, l t) -> Bool immedafter (a, b, t) = immedbefore (b, a, t) after (a, b, t) = before (b, a, t) before (a, b, t) = memberInSet (b, succ (a, t)) succ (a, tl) = closure ([a], immsucc' , tl) pred (a, tl) = closure ([a], immpred' , tl) immsucc (a, tl) = immsucc' ([a], [], tl) immpred (a, tl) = immpred' ([a], [], tl) instance (SetClass t) => Time TimeFacts t where immsucc’ (a, s, New ) = s immsucc’ (a, s, Bef (e, f, tt)) = if memberInSet (e,a) then immsucc’ (a, insertInSet (f,s), tt) else immsucc’ (a, s,tt) On 3 November 2016 at 18:05, Imants Cekusins wrote: > this builds. not sure if the instances are as intended > > > {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-} > module SetClass where > > data TimeFacts t = Bef (t, t, TimeFacts t) | New > > class SetClass t where > class SetClass t => Time l t where > class Time l t => TimeE l t where > class Time l t => TimeTO l t where > > > instance SetClass (TimeFacts t) where -- OK > instance (SetClass t) => Time (TimeFacts t) t where > instance (SetClass t) => TimeE (TimeFacts t) t where > instance (SetClass t) => TimeTO (TimeFacts t) t where > > ​ > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- 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 brutallesale at gmail.com Thu Nov 10 18:44:17 2016 From: brutallesale at gmail.com (sasa bogicevic) Date: Thu, 10 Nov 2016 19:44:17 +0100 Subject: [Haskell-beginners] OI UTCTime to String Message-ID: <7085A8E2-7469-440C-BD04-747A056008B5@gmail.com> Hi All, This is a small program {-# LANGUAGE OverloadedStrings #-} module Main where import Control.Monad.IO.Class (liftIO) import qualified Data.ByteString.Lazy.Char8 as L import Data.Time import Network (withSocketsDo) import Network.HTTP.Conduit createRequestData today = [("index:brKursneListe",""), ("index:year","2016"), ("index:inputCalendar1", today), ("index:vrsta","3"), ("index:prikaz","0"), ("index:buttonShow","Prikazi")] timeFromString s = parseTimeOrError True defaultTimeLocale "%d %b %Y %l:%M %p" s formatDateString time = formatTime defaultTimeLocale "%m/%d/%Y" time getDateString = getCurrentTime getFormatedDate = formatDateString $ timeFromString getDateString main = do print $ getFormatedDate And here is my error main.hs:25:54: error: • Couldn't match type ‘IO UTCTime’ with ‘[Char]’ Expected type: String Actual type: IO UTCTime • In the first argument of ‘timeFromString’, namely ‘getDateString’ In the second argument of ‘($)’, namely ‘timeFromString getDateString’ In the expression: formatDateString $ timeFromString getDateString Thanks! From fa-ml at ariis.it Thu Nov 10 18:52:21 2016 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 10 Nov 2016 19:52:21 +0100 Subject: [Haskell-beginners] OI UTCTime to String In-Reply-To: <7085A8E2-7469-440C-BD04-747A056008B5@gmail.com> References: <7085A8E2-7469-440C-BD04-747A056008B5@gmail.com> Message-ID: <20161110185221.GA18500@casa.casa> On Thu, Nov 10, 2016 at 07:44:17PM +0100, sasa bogicevic wrote: > Hi All, > > This is a small program > > [...] Hey Sasa, If we put this into ghci λ> :t formatDateString $ timeFromString _ the "hole" tells us we need something of type String, but `getDateString` is not! λ> :t getDateString getDateString :: IO UTCTime That means you have to bind it inside a `do` block (or use >>=). Ask for more if I was not clear! From nrujac at gmail.com Thu Nov 10 19:07:09 2016 From: nrujac at gmail.com (Arjun Comar) Date: Thu, 10 Nov 2016 19:07:09 +0000 Subject: [Haskell-beginners] OI UTCTime to String In-Reply-To: <20161110185221.GA18500@casa.casa> References: <7085A8E2-7469-440C-BD04-747A056008B5@gmail.com> <20161110185221.GA18500@casa.casa> Message-ID: Adding to Francesco's reply, UTCTime is not a String either. Luckily, it does have a Show instance however, which means you probably want something like: getDateString = do date <- getCurrentTime return $ show date Or, more simply: getDateString = fmap show getCurrentTime You will still need to use bind, fmap, or do to get at the actual date string however. Thanks, Arjun On Thu, Nov 10, 2016 at 1:58 PM Francesco Ariis wrote: > On Thu, Nov 10, 2016 at 07:44:17PM +0100, sasa bogicevic wrote: > > Hi All, > > > > This is a small program > > > > [...] > > Hey Sasa, > If we put this into ghci > > λ> :t formatDateString $ timeFromString _ > > the "hole" tells us we need something of type String, but `getDateString` > is not! > > λ> :t getDateString > getDateString :: IO UTCTime > > That means you have to bind it inside a `do` block (or use >>=). > Ask for more if I was not clear! > _______________________________________________ > 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 Nov 10 19:23:36 2016 From: toad3k at gmail.com (David McBride) Date: Thu, 10 Nov 2016 14:23:36 -0500 Subject: [Haskell-beginners] OI UTCTime to String In-Reply-To: <7085A8E2-7469-440C-BD04-747A056008B5@gmail.com> References: <7085A8E2-7469-440C-BD04-747A056008B5@gmail.com> Message-ID: It looks like you are trying to get time in UTC, then figuring out what date it is? You should be able to get the answer you are looking for with getFormattedDate = do utc <- getCurrentTime return $ formatTime defaultTimeLocale "%m/%d/%Y" utc Just keep in mind that that is the date in UTC. Not in your local time zone and it ignores daylight savings time. To get it in your time you'll have to replace getCurrentTime with getZonedTime. On Thu, Nov 10, 2016 at 1:44 PM, sasa bogicevic wrote: > Hi All, > > This is a small program > > {-# LANGUAGE OverloadedStrings #-} > module Main where > > import Control.Monad.IO.Class (liftIO) > import qualified Data.ByteString.Lazy.Char8 as L > import Data.Time > import Network (withSocketsDo) > import Network.HTTP.Conduit > > > createRequestData today = [("index:brKursneListe",""), > ("index:year","2016"), > ("index:inputCalendar1", today), > ("index:vrsta","3"), > ("index:prikaz","0"), > ("index:buttonShow","Prikazi")] > > > timeFromString s = parseTimeOrError True defaultTimeLocale "%d %b %Y > %l:%M %p" s > > formatDateString time = formatTime defaultTimeLocale "%m/%d/%Y" time > > getDateString = getCurrentTime > > getFormatedDate = formatDateString $ timeFromString getDateString > > main = do > print $ getFormatedDate > > > And here is my error > > main.hs:25:54: error: > • Couldn't match type ‘IO UTCTime’ with ‘[Char]’ > Expected type: String > Actual type: IO UTCTime > • In the first argument of ‘timeFromString’, namely ‘getDateString’ > In the second argument of ‘($)’, namely > ‘timeFromString getDateString’ > In the expression: formatDateString $ timeFromString getDateString > > Thanks! > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brutallesale at gmail.com Thu Nov 10 20:44:37 2016 From: brutallesale at gmail.com (sasa bogicevic) Date: Thu, 10 Nov 2016 21:44:37 +0100 Subject: [Haskell-beginners] OI UTCTime to String In-Reply-To: References: <7085A8E2-7469-440C-BD04-747A056008B5@gmail.com> Message-ID: <69791B07-41A4-4397-96DB-469E42C3459C@gmail.com> Thanks guys! Didn't expect this much help so fast, great community! I think my main problem was that I was constantly trying to print the result for my formatted date string which was of type IO String (at some point) I just learned that to print IO you need to bind it something like this main = getFormattedDate >>= putStrLn Thanks a lot, You rock! > On Nov 10, 2016, at 20:23, David McBride wrote: > > It looks like you are trying to get time in UTC, then figuring out what date it is? You should be able to get the answer you are looking for with > > getFormattedDate = do > utc <- getCurrentTime > return $ formatTime defaultTimeLocale "%m/%d/%Y" utc > > Just keep in mind that that is the date in UTC. Not in your local time zone and it ignores daylight savings time. To get it in your time you'll have to replace getCurrentTime with getZonedTime. > > On Thu, Nov 10, 2016 at 1:44 PM, sasa bogicevic wrote: > Hi All, > > This is a small program > > {-# LANGUAGE OverloadedStrings #-} > module Main where > > import Control.Monad.IO.Class (liftIO) > import qualified Data.ByteString.Lazy.Char8 as L > import Data.Time > import Network (withSocketsDo) > import Network.HTTP.Conduit > > > createRequestData today = [("index:brKursneListe",""), > ("index:year","2016"), > ("index:inputCalendar1", today), > ("index:vrsta","3"), > ("index:prikaz","0"), > ("index:buttonShow","Prikazi")] > > > timeFromString s = parseTimeOrError True defaultTimeLocale "%d %b %Y %l:%M %p" s > > formatDateString time = formatTime defaultTimeLocale "%m/%d/%Y" time > > getDateString = getCurrentTime > > getFormatedDate = formatDateString $ timeFromString getDateString > > main = do > print $ getFormatedDate > > > And here is my error > > main.hs:25:54: error: > • Couldn't match type ‘IO UTCTime’ with ‘[Char]’ > Expected type: String > Actual type: IO UTCTime > • In the first argument of ‘timeFromString’, namely ‘getDateString’ > In the second argument of ‘($)’, namely > ‘timeFromString getDateString’ > In the expression: formatDateString $ timeFromString getDateString > > Thanks! > > _______________________________________________ > 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 skippy_lou at hotmail.com Sat Nov 12 20:20:19 2016 From: skippy_lou at hotmail.com (Lawrence Wickert) Date: Sat, 12 Nov 2016 20:20:19 +0000 Subject: [Haskell-beginners] Equivalence (or not) of lists Message-ID: Hello all, I am a rank beginner to functional languages. Working through Lipovaca's book, up to Chapter 3. Ok, setup this function in editor and compiled: length' :: (Num b) => [a] -> b length' [] = 0 length' (_:xs) = 1 + length' xs skippy at skippy:~$ ghci GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help Prelude> :l baby [1 of 1] Compiling Main ( baby.hs, interpreted ) Ok, modules loaded: Main. *Main> length' [1,2,3] 3 *Main> 1:2:3:[] [1,2,3] *Main> length' 1:2:3:[] :5:9: Could not deduce (Num [a0]) arising from the literal '1' from the context (Num a) bound by the inferred type of it :: Num a => [a] at :5:1-16 The type variable 'a0' is ambiguous In the first argument of 'length'', namely '1' In the first argument of '(:)', namely 'length' 1' In the expression: length' 1 : 2 : 3 : [] *Main> Obviously, there is something I don't understand about the apparent non-equivalence of the lists [1,2,3] and 1:2:3:[]I am guessing that the solution is contained in that error message but I can't quite decipher it. Thanks for any help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sylvain at haskus.fr Sat Nov 12 20:30:07 2016 From: sylvain at haskus.fr (Sylvain Henry) Date: Sat, 12 Nov 2016 21:30:07 +0100 Subject: [Haskell-beginners] Equivalence (or not) of lists In-Reply-To: References: Message-ID: Hi, > length' 1:2:3:[] is equivalent to: > (length' 1):2:3:[] hence the error. Try: > length' (1:2:3:[]) Sylvain On 12/11/2016 21:20, Lawrence Wickert wrote: > Hello all, > > I am a rank beginner to functional languages. Working through > Lipovaca's book, up to Chapter 3. > > Ok, setup this function in editor and compiled: > > length' :: (Num b) => [a] -> b > length' [] = 0 > length' (_:xs) = 1 + length' xs > > > skippy at skippy:~$ ghci > GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help > Prelude> :l baby > [1 of 1] Compiling Main ( baby.hs, interpreted ) > Ok, modules loaded: Main. > *Main> length' [1,2,3] > 3 > *Main> 1:2:3:[] > [1,2,3] > *Main> length' 1:2:3:[] > > :5:9: > Could not deduce (Num [a0]) arising from the literal ‘1’ > from the context (Num a) > bound by the inferred type of it :: Num a => [a] > at :5:1-16 > The type variable ‘a0’ is ambiguous > In the first argument of ‘length'’, namely ‘1’ > In the first argument of ‘(:)’, namely ‘length' 1’ > In the expression: length' 1 : 2 : 3 : [] > *Main> > > > Obviously, there is something I don't understand about the apparent > non-equivalence of the lists [1,2,3] and 1:2:3:[]I am guessing that > the solution is contained in that error message but I can't quite > decipher it. > > Thanks for any help. > > > > > _______________________________________________ > 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 Sat Nov 12 20:27:21 2016 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 12 Nov 2016 21:27:21 +0100 Subject: [Haskell-beginners] Equivalence (or not) of lists In-Reply-To: References: Message-ID: <20161112202346.GA2465@casa.casa> On Sat, Nov 12, 2016 at 08:20:19PM +0000, Lawrence Wickert wrote: > Hello all, > > I am a rank beginner to functional languages. Working through > Lipovaca's book, up to Chapter 3. > > [...] > > *Main> length' 1:2:3:[] Hello Lawrence, remember that function application has precedence over operators! So writing: *Main> length' 1:2:3:[] is equivalent to writing *Main> (length' 1) :2:3:[] (which is not what you want). If you add parentheses, your expression works again! *Main> length' (1:2:3:[]) From fa-ml at ariis.it Sat Nov 12 20:29:22 2016 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 12 Nov 2016 21:29:22 +0100 Subject: [Haskell-beginners] Equivalence (or not) of lists In-Reply-To: References: Message-ID: <20161112202346.GA2465@casa.casa> On Sat, Nov 12, 2016 at 08:20:19PM +0000, Lawrence Wickert wrote: > Hello all, > > I am a rank beginner to functional languages. Working through > Lipovaca's book, up to Chapter 3. > > [...] > > *Main> length' 1:2:3:[] Hello Lawrence, remember that function application has precedence over operators! So writing: *Main> length' 1:2:3:[] is equivalent to writing *Main> (length' 1) :2:3:[] (which is not what you want). If you add parentheses, your expression works again! *Main> length' (1:2:3:[]) From skippy_lou at hotmail.com Sat Nov 12 20:38:37 2016 From: skippy_lou at hotmail.com (Lawrence Wickert) Date: Sat, 12 Nov 2016 20:38:37 +0000 Subject: [Haskell-beginners] Equivalence (or not) of lists Message-ID: Thanks, Sylvain. That works and I think I understand the difference now. Larry -------------- next part -------------- An HTML attachment was scrubbed... URL: From jan.brusch at gmail.com Sat Nov 12 21:43:13 2016 From: jan.brusch at gmail.com (Jan Brusch) Date: Sat, 12 Nov 2016 22:43:13 +0100 Subject: [Haskell-beginners] Request for Code Review: Dice Game Distribution Message-ID: Hi, I'm currently learning Haskell and as a first project I wrote a little helper for a dice game. It's very short. Nonetheless I would really appreciate a little Code Review or any other input. The Game: Each player writes down the numbers from 1 to 42. Each turn you roll 3 dice (6-sided). The rolling player can cross of any one number that he can construct from the three dice using the math operators +, -, *, /. First player to cross off all numbers wins. The Helper: Calculates the reachable numbers for each dice roll. It the aggregates a count for each number, from how many dice rolls it can be reached. E.g.: There are 216 possible dice rolls (6^3), the number 2 can be reached form 171 of them. The helper gives out the data in JSON format that can be read by NVD3 to be displayed in a browser. The graph helps you to make a decision on which number you should prefer to cross off with your current roll. The Code: http://lpaste.net/338358 The Graph: http://imgur.com/a/NSDT8 Looking forward to any feedback and thanks in advance Jan -------------- next part -------------- An HTML attachment was scrubbed... URL: From laiboonh at gmail.com Mon Nov 14 02:15:23 2016 From: laiboonh at gmail.com (Lai Boon Hui) Date: Mon, 14 Nov 2016 10:15:23 +0800 Subject: [Haskell-beginners] How to tell haskell that 'a' is 'a' ? Message-ID: Hi all, skips :: [a] -> [[a]] skips xs = go 1 [] where go :: Int -> [[a]] -> [[a]] *-- Compiles if i remove this line* go n acc | n > (length xs) = acc | n == 1 = xs : (go (n+1) acc) | n < 1 = [] | otherwise = (everyN n xs) : (go (n+1) acc) everyN :: Int -> [a] -> [a] everyN n xs = case (drop (n-1) xs) of y:ys -> y : (everyN n ys) [] -> [] How can i tell haskell compiler that a is the sub program if the same as a in the main program? -- Best Regards, Boon Hui -------------- next part -------------- An HTML attachment was scrubbed... URL: From sylvain at haskus.fr Mon Nov 14 02:26:27 2016 From: sylvain at haskus.fr (Sylvain Henry) Date: Mon, 14 Nov 2016 03:26:27 +0100 Subject: [Haskell-beginners] How to tell haskell that 'a' is 'a' ? In-Reply-To: References: Message-ID: <3178e490-9884-676d-843a-162e29288b59@haskus.fr> Hi, Use ScopedTypeVariables and forall: {-# LANGUAGE ScopedTypeVariables #-} skips :: forall a. [a] -> [[a]] skips xs = go 1 [] where go :: Int -> [[a]] -> [[a]] * ...* Sylvain On 14/11/2016 03:15, Lai Boon Hui wrote: > Hi all, > > skips :: [a] -> [[a]] > skips xs = go 1 [] where > go :: Int -> [[a]] -> [[a]] *-- Compiles if i remove this line* > go n acc > | n > (length xs) = acc > | n == 1 = xs : (go (n+1) acc) > | n < 1 = [] > | otherwise = (everyN n xs) : (go (n+1) acc) > > everyN :: Int -> [a] -> [a] > everyN n xs = > case (drop (n-1) xs) of > y:ys -> y : (everyN n ys) > [] -> [] > > How can i tell haskell compiler that a is the sub program if the same > as a in the main program? > > > -- > Best Regards, > Boon Hui > > > _______________________________________________ > 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 csasarak at mailbox.org Mon Nov 14 02:58:27 2016 From: csasarak at mailbox.org (Chris Sasarak) Date: Sun, 13 Nov 2016 21:58:27 -0500 Subject: [Haskell-beginners] Equivalence (or not) of lists In-Reply-To: <20161112202346.GA2465@casa.casa> References: <20161112202346.GA2465@casa.casa> Message-ID: <87fumuwywc.fsf@mailbox.org> In this case it's not too bad adding parens to make: length' (1:2:3:[]) But in the future sometimes it can get harder, so we have a handy function '$' which is just function application, but it has the lowest precedence. What this means is everything on its right side is evaluated and then applied to the function on its left. Your code would look like this: length' $ 1:2:3:[] In some cases this can be more readable. Best, Chris Francesco Ariis writes: > On Sat, Nov 12, 2016 at 08:20:19PM +0000, Lawrence Wickert wrote: >> Hello all, >> >> I am a rank beginner to functional languages. Working through >> Lipovaca's book, up to Chapter 3. >> >> [...] >> >> *Main> length' 1:2:3:[] > > Hello Lawrence, > remember that function application has precedence over operators! > > So writing: > > *Main> length' 1:2:3:[] > > is equivalent to writing > > *Main> (length' 1) :2:3:[] > > (which is not what you want). If you add parentheses, your expression > works again! > > *Main> length' (1:2:3:[]) > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From clever97 at gmail.com Thu Nov 17 21:52:14 2016 From: clever97 at gmail.com (Cleverson Casarin Uliana) Date: Thu, 17 Nov 2016 19:52:14 -0200 Subject: [Haskell-beginners] Setting up WXHaskell on the 8.0.1 platform? Message-ID: <2d6245ff-7dcc-2105-2d7d-199e7bb11514@gmail.com> Hello all, I've sent this to the WXHaskell list, but no answers. Please what is the recommended way to set up WXWidgets and WXHaskell for the 8.0.1 Haskell Platform on Windows? I tried using the Achelanne installer, but it gives errors apparently related to packages versions incompatibilities. Thanks, Cleverson From briand at aracnet.com Fri Nov 25 05:46:13 2016 From: briand at aracnet.com (briand at aracnet.com) Date: Thu, 24 Nov 2016 21:46:13 -0800 Subject: [Haskell-beginners] pattern matching on a common element Message-ID: <20161124214613.576a0912@basalt.deldotd.com> Here's what I'm doing: data X = A1 String Double | A2 String Int | A3 String Double Int name c = case c of A1 name _ -> name A2 name _ -> name A3 name _ _ -> name I'm sure there's a better way... From rahulmutt at gmail.com Fri Nov 25 06:36:06 2016 From: rahulmutt at gmail.com (Rahul Muttineni) Date: Fri, 25 Nov 2016 12:06:06 +0530 Subject: [Haskell-beginners] pattern matching on a common element In-Reply-To: <20161124214613.576a0912@basalt.deldotd.com> References: <20161124214613.576a0912@basalt.deldotd.com> Message-ID: data X = A1 { name :: String, d :: Double} | A2 { name :: String, i :: Int} | A3 { name :: String, d1 :: Double, i1 :: Int} Now you can use `name` directly to get the string component of the different variants. Hope that helps! Rahul On Fri, Nov 25, 2016 at 11:16 AM, wrote: > Here's what I'm doing: > > data X = A1 String Double | A2 String Int | A3 String Double Int > > name c = > case c of > A1 name _ -> name > A2 name _ -> name > A3 name _ _ -> name > > I'm sure there's a better way... > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Rahul Muttineni -------------- next part -------------- An HTML attachment was scrubbed... URL: From briand at aracnet.com Fri Nov 25 07:08:02 2016 From: briand at aracnet.com (briand at aracnet.com) Date: Thu, 24 Nov 2016 23:08:02 -0800 Subject: [Haskell-beginners] pattern matching on a common element In-Reply-To: References: <20161124214613.576a0912@basalt.deldotd.com> Message-ID: <20161124230802.2ec92e72@basalt.deldotd.com> On Fri, 25 Nov 2016 12:06:06 +0530 Rahul Muttineni wrote: > data X = > A1 { name :: String, d :: Double} > | A2 { name :: String, i :: Int} > | A3 { name :: String, d1 :: Double, i1 :: Int} > > Now you can use `name` directly to get the string component of the > different variants. > > Hope that helps! oops, i forgot to mention. i'd like to be able to write my code; x = [ A1 "a1" 2.0, A2 "a2" 3 ] etc... to save myself a lot of typing. From jeffbrown.the at gmail.com Fri Nov 25 07:09:26 2016 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Thu, 24 Nov 2016 23:09:26 -0800 Subject: [Haskell-beginners] pattern matching on a common element In-Reply-To: <20161124230802.2ec92e72@basalt.deldotd.com> References: <20161124214613.576a0912@basalt.deldotd.com> <20161124230802.2ec92e72@basalt.deldotd.com> Message-ID: You still can! Using Rahul's solution, that is. On Thu, Nov 24, 2016 at 11:08 PM, wrote: > On Fri, 25 Nov 2016 12:06:06 +0530 > Rahul Muttineni wrote: > > > data X = > > A1 { name :: String, d :: Double} > > | A2 { name :: String, i :: Int} > > | A3 { name :: String, d1 :: Double, i1 :: Int} > > > > Now you can use `name` directly to get the string component of the > > different variants. > > > > Hope that helps! > > oops, i forgot to mention. > > i'd like to be able to write my code; > > x = [ A1 "a1" 2.0, A2 "a2" 3 ] > > etc... to save myself a lot of typing. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Jeff Brown | Jeffrey Benjamin Brown Website | Facebook | LinkedIn (I often miss messages here) | Github -------------- next part -------------- An HTML attachment was scrubbed... URL: From briand at aracnet.com Fri Nov 25 07:34:10 2016 From: briand at aracnet.com (briand at aracnet.com) Date: Thu, 24 Nov 2016 23:34:10 -0800 Subject: [Haskell-beginners] pattern matching on a common element In-Reply-To: References: <20161124214613.576a0912@basalt.deldotd.com> <20161124230802.2ec92e72@basalt.deldotd.com> Message-ID: <20161124233410.35ff48aa@basalt.deldotd.com> On Thu, 24 Nov 2016 23:09:26 -0800 Jeffrey Brown wrote: > You still can! Using Rahul's solution, that is. but wouldn't i have to write A1 {name="a1", d="2.0} A2 {name="a2", i=2} etc... ? That would be ok for these simple examples, but for my actual code the field names would not be just 1 or 2 characters. Brian > > On Thu, Nov 24, 2016 at 11:08 PM, wrote: > > > On Fri, 25 Nov 2016 12:06:06 +0530 > > Rahul Muttineni wrote: > > > > > data X = > > > A1 { name :: String, d :: Double} > > > | A2 { name :: String, i :: Int} > > > | A3 { name :: String, d1 :: Double, i1 :: Int} > > > > > > Now you can use `name` directly to get the string component of the > > > different variants. > > > > > > Hope that helps! > > > > oops, i forgot to mention. > > > > i'd like to be able to write my code; > > > > x = [ A1 "a1" 2.0, A2 "a2" 3 ] > > > > etc... to save myself a lot of typing. > > > > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > From rein.henrichs at gmail.com Fri Nov 25 08:41:46 2016 From: rein.henrichs at gmail.com (Rein Henrichs) Date: Fri, 25 Nov 2016 08:41:46 +0000 Subject: [Haskell-beginners] pattern matching on a common element In-Reply-To: <20161124233410.35ff48aa@basalt.deldotd.com> References: <20161124214613.576a0912@basalt.deldotd.com> <20161124230802.2ec92e72@basalt.deldotd.com> <20161124233410.35ff48aa@basalt.deldotd.com> Message-ID: No, you would not. Record syntax is an addition to, not a replacement for, the form you want to use. On Thu, Nov 24, 2016 at 11:34 PM wrote: On Thu, 24 Nov 2016 23:09:26 -0800 Jeffrey Brown wrote: > You still can! Using Rahul's solution, that is. but wouldn't i have to write A1 {name="a1", d="2.0} A2 {name="a2", i=2} etc... ? That would be ok for these simple examples, but for my actual code the field names would not be just 1 or 2 characters. Brian > > On Thu, Nov 24, 2016 at 11:08 PM, wrote: > > > On Fri, 25 Nov 2016 12:06:06 +0530 > > Rahul Muttineni wrote: > > > > > data X = > > > A1 { name :: String, d :: Double} > > > | A2 { name :: String, i :: Int} > > > | A3 { name :: String, d1 :: Double, i1 :: Int} > > > > > > Now you can use `name` directly to get the string component of the > > > different variants. > > > > > > Hope that helps! > > > > oops, i forgot to mention. > > > > i'd like to be able to write my code; > > > > x = [ A1 "a1" 2.0, A2 "a2" 3 ] > > > > etc... to save myself a lot of typing. > > > > > > _______________________________________________ > > 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 daniel.trstenjak at gmail.com Fri Nov 25 09:19:14 2016 From: daniel.trstenjak at gmail.com (Daniel Trstenjak) Date: Fri, 25 Nov 2016 10:19:14 +0100 Subject: [Haskell-beginners] pattern matching on a common element In-Reply-To: References: <20161124214613.576a0912@basalt.deldotd.com> Message-ID: <20161125091914.GA9587@octa> Hi Rahul, On Fri, Nov 25, 2016 at 12:06:06PM +0530, Rahul Muttineni wrote: > data X = >   A1 { name :: String, d :: Double} > | A2 { name :: String, i :: Int} > | A3 { name :: String, d1 :: Double, i1 :: Int} > > Now you can use `name` directly to get the string component of the different > variants. It's not recommended to mix record syntax and ADTs, because you can get runtime errors that the compiler can't catch during compile time, like calling: i (A1 "foo" 3.2) If you're having the same field in all variants, then an other approach might be better: data A = Ai Int | Ad Double | Aid Int Double data X = X { name :: String, a :: A } Greetings, Daniel From briand at aracnet.com Fri Nov 25 16:08:35 2016 From: briand at aracnet.com (briand at aracnet.com) Date: Fri, 25 Nov 2016 08:08:35 -0800 Subject: [Haskell-beginners] pattern matching on a common element In-Reply-To: References: <20161124214613.576a0912@basalt.deldotd.com> <20161124230802.2ec92e72@basalt.deldotd.com> <20161124233410.35ff48aa@basalt.deldotd.com> Message-ID: <20161125080835.4446131c@basalt.deldotd.com> On Fri, 25 Nov 2016 08:41:46 +0000 Rein Henrichs wrote: > No, you would not. Record syntax is an addition to, not a replacement for, > the form you want to use. > oh, I see. I had tried A1 { "a1" 2.0 } instead of A1 ("a1" 2.0) Brian From briand at aracnet.com Fri Nov 25 16:20:29 2016 From: briand at aracnet.com (briand at aracnet.com) Date: Fri, 25 Nov 2016 08:20:29 -0800 Subject: [Haskell-beginners] pattern matching on a common element In-Reply-To: <20161125091914.GA9587@octa> References: <20161124214613.576a0912@basalt.deldotd.com> <20161125091914.GA9587@octa> Message-ID: <20161125082029.2ca609a7@basalt.deldotd.com> On Fri, 25 Nov 2016 10:19:14 +0100 Daniel Trstenjak wrote: > Hi Rahul, > > On Fri, Nov 25, 2016 at 12:06:06PM +0530, Rahul Muttineni wrote: > > data X = > >   A1 { name :: String, d :: Double} > > | A2 { name :: String, i :: Int} > > | A3 { name :: String, d1 :: Double, i1 :: Int} > > > > Now you can use `name` directly to get the string component of the different > > variants. > > It's not recommended to mix record syntax and ADTs, because you > can get runtime errors that the compiler can't catch during compile > time, like calling: > > i (A1 "foo" 3.2) > agreed. I'm doing this as a form of shorthand instead of creating a text file based input and parsing it. Having any sort of type checking is an advantage. > If you're having the same field in all variants, then an > other approach might be better: > > data A = Ai Int | Ad Double | Aid Int Double > > data X = X { name :: String, a :: A } > yes, that would be better. interestingly in my journeys through the intertubes I have not found a single mention of using the "()" syntax in place of the "{fieldname=value, ...}" syntax as the generator. Brian From daniel.trstenjak at gmail.com Fri Nov 25 17:18:21 2016 From: daniel.trstenjak at gmail.com (Daniel Trstenjak) Date: Fri, 25 Nov 2016 18:18:21 +0100 Subject: [Haskell-beginners] pattern matching on a common element In-Reply-To: <20161125082029.2ca609a7@basalt.deldotd.com> References: <20161124214613.576a0912@basalt.deldotd.com> <20161125091914.GA9587@octa> <20161125082029.2ca609a7@basalt.deldotd.com> Message-ID: <20161125171821.GA4138@octa> Hi Brian, > interestingly in my journeys through the intertubes I have not found a > single mention of using the "()" syntax in place of the > "{fieldname=value, ...}" syntax as the generator. The '()' isn't part of the 'data constructor' (the usual term for A1/A2/A3), but sometimes needed to help the compiler to make an unambiguous parsing of the expression. These are all valid expressions: i $ A1 "foo" 3.2 -- '$' is often used to get rid of parentheses let a1 = A1 "foo" 3.2 in i a1 Greetings, Daniel From briand at aracnet.com Fri Nov 25 20:50:01 2016 From: briand at aracnet.com (briand at aracnet.com) Date: Fri, 25 Nov 2016 12:50:01 -0800 Subject: [Haskell-beginners] pattern matching on a common element In-Reply-To: <20161125171821.GA4138@octa> References: <20161124214613.576a0912@basalt.deldotd.com> <20161125091914.GA9587@octa> <20161125082029.2ca609a7@basalt.deldotd.com> <20161125171821.GA4138@octa> Message-ID: <20161125125001.4e09cbc5@basalt.deldotd.com> On Fri, 25 Nov 2016 18:18:21 +0100 Daniel Trstenjak wrote: > Hi Brian, > > > interestingly in my journeys through the intertubes I have not found a > > single mention of using the "()" syntax in place of the > > "{fieldname=value, ...}" syntax as the generator. > > The '()' isn't part of the 'data constructor' (the usual term for A1/A2/A3), > but sometimes needed to help the compiler to make an unambiguous parsing of the expression. > > These are all valid expressions: > > i $ A1 "foo" 3.2 -- '$' is often used to get rid of parentheses > > let a1 = A1 "foo" 3.2 in i a1 > oh, i see. everything's a function. thanks! Brian From newhoggy at gmail.com Sun Nov 27 21:23:18 2016 From: newhoggy at gmail.com (John Ky) Date: Sun, 27 Nov 2016 21:23:18 +0000 Subject: [Haskell-beginners] Real World Haskell: Deprecated Libraries Message-ID: Hello Haskellers, I have been working through the Real World Haskell chapter on Profiling and Optimisation , and got to the section *Advanced techniques: fusion*, where I encountered some code using Data.Array.Vector from the deprecated library uvector. Does anyone know how to rewrite this to not use deprecated libraries? I have tried to use Data.Vector.Unboxed from vector, but my version consumes a lot of memory. The code I have is here: https://github.com/haskell-works/hw-tutorial-performance/blob/master/hw-tutorial-performance-rwhe/Main.hs With that code, I get “1831 MB total memory in use”, which is terrible Build run steps I used were: stack build --executable-profiling --library-profiling --ghc-options="-fprof-auto -rtsopts -auto-all -caf-all -fforce-recomp" time /Users/jky/wrk/haskell-works/hw-tutorial-performance/.stack-work/install/x86_64-osx/lts-7.10/8.0.1/bin/hw-tutorial-performance-rwhe +RTS -sstderr -p -hy -RTS 1e7 I get very large numbers of allocations of Pair and Double. There is also a very large upfront allocation ARR_WORDS, which I feared would happen when using Data.Vector Any help appreciated. Cheers, -John ​ -------------- next part -------------- An HTML attachment was scrubbed... URL: From newhoggy at gmail.com Sun Nov 27 22:39:29 2016 From: newhoggy at gmail.com (John Ky) Date: Sun, 27 Nov 2016 22:39:29 +0000 Subject: [Haskell-beginners] Real World Haskell: Deprecated Libraries In-Reply-To: References: Message-ID: It looks like Haskell stack's profile options are defeating stream fusion. Anyone know a work-around? On Mon, 28 Nov 2016 at 08:23 John Ky wrote: > Hello Haskellers, > > I have been working through the Real World Haskell chapter on Profiling > and Optimisation > , > and got to the section *Advanced techniques: fusion*, where I encountered > some code using Data.Array.Vector from the deprecated library uvector. > > Does anyone know how to rewrite this to not use deprecated libraries? > > I have tried to use Data.Vector.Unboxed from vector, but my version > consumes a lot of memory. > > The code I have is here: > > > https://github.com/haskell-works/hw-tutorial-performance/blob/master/hw-tutorial-performance-rwhe/Main.hs > > With that code, I get “1831 MB total memory in use”, which is terrible > > Build run steps I used were: > > stack build --executable-profiling --library-profiling --ghc-options="-fprof-auto -rtsopts -auto-all -caf-all -fforce-recomp" > > time /Users/jky/wrk/haskell-works/hw-tutorial-performance/.stack-work/install/x86_64-osx/lts-7.10/8.0.1/bin/hw-tutorial-performance-rwhe +RTS -sstderr -p -hy -RTS 1e7 > > I get very large numbers of allocations of Pair and Double. > > There is also a very large upfront allocation ARR_WORDS, which I feared > would happen when using Data.Vector > > Any help appreciated. > > Cheers, > > -John > ​ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From csasarak at mailbox.org Sun Nov 27 23:08:07 2016 From: csasarak at mailbox.org (Christopher Sasarak) Date: Sun, 27 Nov 2016 18:08:07 -0500 Subject: [Haskell-beginners] Setting up WXHaskell on the 8.0.1 platform? In-Reply-To: <2d6245ff-7dcc-2105-2d7d-199e7bb11514@gmail.com> References: <2d6245ff-7dcc-2105-2d7d-199e7bb11514@gmail.com> Message-ID: <87polgttbc.fsf@mailbox.org> I haven't set it up on windows before, but would you mind showing the error message? That would make it a lot easier to see exactly what the problem is. -Chris Cleverson Casarin Uliana writes: > Hello all, I've sent this to the WXHaskell list, but no answers. Please > what is the recommended way to set up WXWidgets and WXHaskell for the > 8.0.1 Haskell Platform on Windows? I tried using the Achelanne > installer, but it gives errors apparently related to packages versions > incompatibilities. > > Thanks, > Cleverson > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -- Best, Chris From bob at redivi.com Mon Nov 28 00:57:20 2016 From: bob at redivi.com (Bob Ippolito) Date: Sun, 27 Nov 2016 16:57:20 -0800 Subject: [Haskell-beginners] Real World Haskell: Deprecated Libraries In-Reply-To: References: Message-ID: Try using foldl', usually that's the right thing to do for this kind of data structure. On Sun, Nov 27, 2016 at 2:39 PM, John Ky wrote: > It looks like Haskell stack's profile options are defeating stream fusion. > > Anyone know a work-around? > > > On Mon, 28 Nov 2016 at 08:23 John Ky wrote: > >> Hello Haskellers, >> >> I have been working through the Real World Haskell chapter on Profiling >> and Optimisation >> , >> and got to the section *Advanced techniques: fusion*, where I >> encountered some code using Data.Array.Vector from the deprecated >> library uvector. >> >> Does anyone know how to rewrite this to not use deprecated libraries? >> >> I have tried to use Data.Vector.Unboxed from vector, but my version >> consumes a lot of memory. >> >> The code I have is here: >> >> https://github.com/haskell-works/hw-tutorial-performance/ >> blob/master/hw-tutorial-performance-rwhe/Main.hs >> >> With that code, I get “1831 MB total memory in use”, which is terrible >> >> Build run steps I used were: >> >> stack build --executable-profiling --library-profiling --ghc-options="-fprof-auto -rtsopts -auto-all -caf-all -fforce-recomp" >> >> time /Users/jky/wrk/haskell-works/hw-tutorial-performance/.stack-work/install/x86_64-osx/lts-7.10/8.0.1/bin/hw-tutorial-performance-rwhe +RTS -sstderr -p -hy -RTS 1e7 >> >> I get very large numbers of allocations of Pair and Double. >> >> There is also a very large upfront allocation ARR_WORDS, which I feared >> would happen when using Data.Vector >> >> Any help appreciated. >> >> Cheers, >> >> -John >> ​ >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: