From miroslav.karpis at gmail.com Wed Mar 2 10:04:34 2016 From: miroslav.karpis at gmail.com (Miro Karpis) Date: Wed, 2 Mar 2016 11:04:34 +0100 Subject: [Haskell-beginners] problem installing persistent-postgresql together with persistent-template Message-ID: Please,..can you help me with following? I'm trying to install both persistent-postgresql together with persistent-template, but I keep getting: mac:~ miro$ cabal install persistent-template Resolving dependencies... In order, the following would be installed: aeson-0.9.0.1 (latest: 0.11.0.0) (via: persistent-template-2.1.5 persistent-2.2.4 aeson-compat-0.3.1.0) (new version) aeson-compat-0.3.1.0 (via: persistent-template-2.1.5) (new package) persistent-2.2.4 (via: persistent-template-2.1.5) (reinstall) (changes: aeson-0.11.0.0 -> 0.9.0.1) persistent-template-2.1.5 (new package) cabal: The following packages are likely to be broken by the reinstalls: persistent-postgresql-2.2.2 Use --force-reinstalls if you want to install anyway. If I continue with force-reinstall then I broke postgresql. Is there a way to force persistent-template to use 2.2.2 version (I know if I download it and change the dep. in cabal file,....but is that what I should do :) )? running on: mac:~ miro$ cabal --version cabal-install version 1.22.8.0 using version 1.22.7.0 of the Cabal library mac:~ miro$ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.10.3 cheers, m. -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael at snoyman.com Wed Mar 2 10:15:57 2016 From: michael at snoyman.com (Michael Snoyman) Date: Wed, 2 Mar 2016 12:15:57 +0200 Subject: [Haskell-beginners] problem installing persistent-postgresql together with persistent-template In-Reply-To: References: Message-ID: You can force this with cabal using --constraint "persistent-template=2.2.2" or the equivalent. But these kinds of dependency solving problems are the primary reason I recommend using a Stackage snapshot[1]. If you switch over to building with Stack[2], you'll get that behavior by default. [1] https://www.stackage.org/ [2] http://haskellstack.org/ On Wed, Mar 2, 2016 at 12:04 PM, Miro Karpis wrote: > Please,..can you help me with following? > > I'm trying to install both persistent-postgresql together with > persistent-template, but I keep getting: > > > mac:~ miro$ cabal install persistent-template > Resolving dependencies... > In order, the following would be installed: > aeson-0.9.0.1 (latest: 0.11.0.0) (via: persistent-template-2.1.5 > persistent-2.2.4 aeson-compat-0.3.1.0) (new version) > aeson-compat-0.3.1.0 (via: persistent-template-2.1.5) (new package) > persistent-2.2.4 (via: persistent-template-2.1.5) (reinstall) (changes: > aeson-0.11.0.0 -> 0.9.0.1) > persistent-template-2.1.5 (new package) > cabal: The following packages are likely to be broken by the reinstalls: > persistent-postgresql-2.2.2 > Use --force-reinstalls if you want to install anyway. > > > > If I continue with force-reinstall then I broke postgresql. Is there a way > to force persistent-template to use 2.2.2 version (I know if I download it > and change the dep. in cabal file,....but is that what I should do :) )? > > > > running on: > mac:~ miro$ cabal --version > cabal-install version 1.22.8.0 > using version 1.22.7.0 of the Cabal library > > mac:~ miro$ ghc --version > The Glorious Glasgow Haskell Compilation System, version 7.10.3 > > > cheers, > m. > > > > _______________________________________________ > 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 joel.neely at gmail.com Wed Mar 2 22:50:13 2016 From: joel.neely at gmail.com (Joel Neely) Date: Wed, 2 Mar 2016 16:50:13 -0600 Subject: [Haskell-beginners] Question on terminology Message-ID: IIUC, one would describe fmap as "lifting" a function g into a functor f, in the sense of Functor f => (g a b) -> g a -> g b Is there an inverse concept (? co-lift ?) that describes Functor f => (g a -> g b) -> a -> b Similarly is there standard terminology for "distributing" and "gathering" in the sense of Functor f => f [a] -> [f a] and Functor f => [f a] -> f [a] respectively? References much appreciated! -jn- -- Beauty of style and harmony and grace and good rhythm depend on simplicity. - Plato -------------- next part -------------- An HTML attachment was scrubbed... URL: From rein.henrichs at gmail.com Wed Mar 2 23:27:58 2016 From: rein.henrichs at gmail.com (Rein Henrichs) Date: Wed, 02 Mar 2016 23:27:58 +0000 Subject: [Haskell-beginners] Question on terminology In-Reply-To: References: Message-ID: "Co-lift" is not possible for functors generally. Comonads have a method extract :: Comonad w => w a -> a, which is somewhat related. Distributing and gathering are both really distributing. The first example distributes [] over f while the second example distributes f over []. Neither are possible for functors generally, but Applicative and Data.Traversable are strong enough to provide sequenceA :: (Traversable t, Applicative f) => t (f a) -> f (t a). The problem is that the Applicative and Traversable laws alone are not enough to guarantee that this is well behaved. What you actually need is a stronger notion that f (g a) is an "f-structure" containing "g-structures" *all of the same shape*. If they aren't, the inner structures won't be distributed properly and some of the odd shaped bits might get cut off. For example, try to transpose a list of lists (iow, distribute [] over []) and you'll see that all of the inner lists must be the same length for your transposition to be well behaved. Conor McBride covers this in a very interesting way in this StackOverflow answer: http://stackoverflow.com/a/13100857/2225384 On Wed, Mar 2, 2016 at 2:50 PM Joel Neely wrote: > IIUC, one would describe fmap as "lifting" a function g into a functor f, > in the sense of > > Functor f => (g a b) -> g a -> g b > > > Is there an inverse concept (? co-lift ?) that describes > > Functor f => (g a -> g b) -> a -> b > > > Similarly is there standard terminology for "distributing" and "gathering" > in the sense of > > Functor f => f [a] -> [f a] > > > and > > Functor f => [f a] -> f [a] > > > respectively? > > References much appreciated! > -jn- > > -- > Beauty of style and harmony and grace and good rhythm depend on > simplicity. - Plato > _______________________________________________ > 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 jeffbrown.the at gmail.com Thu Mar 3 02:01:22 2016 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Wed, 2 Mar 2016 18:01:22 -0800 Subject: [Haskell-beginners] general observation about programming In-Reply-To: References: <56CF2929.10600@runforyourlife.org> <56D0210A.30301@physics.org> <56D06F3F.9090002@runforyourlife.org> Message-ID: An even more convenient (when applicable) guide to pronunciation: https://wiki.haskell.org/Pronunciation On Sun, Feb 28, 2016 at 4:51 PM, Jeffrey Brown wrote: > That will work in the special case of lists, but there are all sorts of > other things you might want to map across. > > On Sat, Feb 27, 2016 at 7:24 PM, Rustom Mody > wrote: > >> >> >> On Sun, Feb 28, 2016 at 2:26 AM, Jeffrey Brown >> wrote: >> >>> It is, I agree, not appropriate everywhere, but point-free code can in >>> the right place be much more readable. Maps are a good example. Compare: >>> >>> map (f . g . h) xs >>> >>> to >>> >>> map (\x -> f $ g $ h x) xs >>> >> >> Not quite a fair comparison >> How about? >> [ f (g (h x)) | x <- xs ] >> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > > -- > Jeffrey Benjamin Brown > -- Jeffrey Benjamin Brown -------------- next part -------------- An HTML attachment was scrubbed... URL: From bwrogalski at gmail.com Thu Mar 3 18:10:39 2016 From: bwrogalski at gmail.com (Ben Rogalski) Date: Thu, 3 Mar 2016 13:10:39 -0500 Subject: [Haskell-beginners] Question on terminology Message-ID: I'm having trouble understanding this: > IIUC, one would describe fmap as "lifting" a function g into a functor f, > in the sense of > > Functor f => (g a b) -> g a -> g b > > > Is there an inverse concept (? co-lift ?) that describes > > Functor f => (g a -> g b) -> a -> b > It seems like these are type declarations for functions, with class constraints that say f must be a Functor, but then f doesn't appear anywhere else in the declaration. Why is this? Thanks, -Ben -------------- next part -------------- An HTML attachment was scrubbed... URL: From rein.henrichs at gmail.com Thu Mar 3 19:13:25 2016 From: rein.henrichs at gmail.com (Rein Henrichs) Date: Thu, 03 Mar 2016 19:13:25 +0000 Subject: [Haskell-beginners] Question on terminology In-Reply-To: References: Message-ID: Ben, I just assumed that g was a typo for f. On Thu, Mar 3, 2016 at 10:10 AM Ben Rogalski wrote: > I'm having trouble understanding this: > > > IIUC, one would describe fmap as "lifting" a function g into a functor f, > > in the sense of > > > > Functor f => (g a b) -> g a -> g b > > > > > > Is there an inverse concept (? co-lift ?) that describes > > > > Functor f => (g a -> g b) -> a -> b > > > > It seems like these are type declarations for functions, with class > constraints that say f must be a Functor, but then f doesn't appear > anywhere else in the declaration. Why is this? > > Thanks, > -Ben > _______________________________________________ > 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 jeffbrown.the at gmail.com Fri Mar 4 00:56:25 2016 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Thu, 3 Mar 2016 16:56:25 -0800 Subject: [Haskell-beginners] failing to install GHC 7.10.3 appears to have broken cabal and stack Message-ID: I use Ubuntu 14.04. Outside of a stack context, I have been using GHC 7.8.4. I tried to install 7.10.3. ./configure worked, but make install failed with this error: make[1]: *** No rule to make target `utils/haddock/dist/build/tmp/haddock', needed by `install_libexecs'. Stop. make: *** [install] Error 2 I tried to manually undo the install, by deleting it from /usr/local/lib, and by changing all the symlinks in /usr/local/bin back to 7.8.4. If I run ghci without stack, it works, and is still at version 7.8.4. But now cabal and stack are producing errors. "cabal update" runs, but "cabal install" gets confused: jeff at jeffLenovUbu:~/dwt_git_hask$ cabal install regex-compat Warning: cannot determine version of /usr/local/bin/hpc : "" Warning: cannot determine version of /usr/local/bin/hsc2hs : "" Resolving dependencies... Configuring regex-posix-0.95.2... Building regex-posix-0.95.2... Preprocessing library regex-posix-0.95.2... /usr/local/bin/hsc2hs: line 29: /usr/local/lib/ghc-7.10.3/bin/hsc2hs: No such file or directory Failed to install regex-posix-0.95.2 cabal: Error: some packages failed to install: regex-compat-0.95.1 depends on regex-posix-0.95.2 which failed to install. regex-posix-0.95.2 failed during the building phase. The exception was: ExitFailure 127 jeff at jeffLenovUbu:~/dwt_git_hask$ As an example of a stack problem, I downloaded Oleg Prophet's implementation of MicroKanren [1]. "stack build" ran without complaint (or visible output), but "stack ghci" fails thus: jeff at jeffLenovUbu:~/work/computer/Haskell/microKanren/featherweight$ stack ghciConfiguring GHCi with the following packages: microKanren GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help : cannot satisfy -package QuickCheck (use -v for more information) jeff at jeffLenovUbu:~/dwt_git_hask$ stack ghci even fails (with a different error) on my own project [2]: jeff at jeffLenovUbu:~/dwt_git_hask$ stack ghci Configuring GHCi with the following packages: Dwt GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help : can't load .so/.DLL for: /home/jeff/dwt_git_hask/.stack-work/install/x86_64-linux/nightly-2015-08-03/7.10.2/lib/x86_64-linux-ghc-7.10.2/Dwt-0.1.0.0-7VW1kKp7le6K6OdeGoRsDt/ libHSDwt-0.1.0.0-7VW1kKp7le6K6OdeGoRsDt-ghc7.10.2.so (/home/jeff/dwt_git_hask/.stack-work/install/x86_64-linux/nightly-2015-08-03/7.10.2/lib/x86_64-linux-ghc-7.10.2/Dwt-0.1.0.0-7VW1kKp7le6K6OdeGoRsDt/ libHSDwt-0.1.0.0-7VW1kKp7le6K6OdeGoRsDt-ghc7.10.2.so: undefined symbol: Dwtzu7VW1kKp7le6K6OdeGoRsDt_DwtziSearch_QNode_con_info) jeff at jeffLenovUbu:~/dwt_git_hask$ Thanks in advance for your help. [1] https://github.com/Oregu/featherweight [2] https://github.com/JeffreyBenjaminBrown/digraphs-with-text -- Jeffrey Benjamin Brown -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike_k_houghton at yahoo.co.uk Sun Mar 6 09:26:17 2016 From: mike_k_houghton at yahoo.co.uk (Mike Houghton) Date: Sun, 6 Mar 2016 09:26:17 +0000 Subject: [Haskell-beginners] Parsing Message-ID: Hi, I?m using Parsec to parse structured text and have some problems with mandatory and optional text entries and the order in which they occur. For example module{ name = some string source = ? dest = ?.. bundle = ? bundle_dest = ? zip_name = ?. } In the above text the name and source are mandatory and all others are optional. I?m not quite sure how to handle the optional parts once I?ve parsed name and source. Should I enforce the rule that if dest does appear then it must be first in the list? In this situation how should I make use of the various Parsec functions such as choice, option, optionMaybe, lookAhead etc. Thanks Mike From fa-ml at ariis.it Sun Mar 6 09:30:19 2016 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 6 Mar 2016 10:30:19 +0100 Subject: [Haskell-beginners] Parsing In-Reply-To: References: Message-ID: <20160306093019.GA6926@casa.casa> On Sun, Mar 06, 2016 at 09:26:17AM +0000, Mike Houghton wrote: > Hi, I?m using Parsec to parse structured text and have some problems > with mandatory and optional text entries and the order in which they > occur. > For example: > > module{ > > name = some string > source = ? > > dest = ?.. > bundle = ? > bundle_dest = ? > zip_name = ?. > > } Hello Mike, I would personally keep it simple. Parse the (item, value) list and after that check if it is well formed (i.e. contains 'name' and 'source' values). If not, call `parserFail` with an appropriate message. From mike_k_houghton at yahoo.co.uk Sun Mar 6 09:54:34 2016 From: mike_k_houghton at yahoo.co.uk (Mike Houghton) Date: Sun, 6 Mar 2016 09:54:34 +0000 Subject: [Haskell-beginners] Parsing In-Reply-To: <20160306093019.GA6926@casa.casa> References: <20160306093019.GA6926@casa.casa> Message-ID: <07C761EA-42E0-490F-898D-031F52B94EC4@yahoo.co.uk> Hi Francesco, Quick response! Thanks. I see, so would it reduce to something like? many itemValue and originally I was thinking the data structure that it would parse into would be data Module = Module {? some record structure?} but now it would be roughly like? type Entry = (String, String) data Module = Module [Entry] Thanks > On 6 Mar 2016, at 09:30, Francesco Ariis wrote: > > On Sun, Mar 06, 2016 at 09:26:17AM +0000, Mike Houghton wrote: >> Hi, I?m using Parsec to parse structured text and have some problems >> with mandatory and optional text entries and the order in which they >> occur. >> For example: >> >> module{ >> >> name = some string >> source = ? >> >> dest = ?.. >> bundle = ? >> bundle_dest = ? >> zip_name = ?. >> >> } > > Hello Mike, > I would personally keep it simple. Parse the (item, value) list > and after that check if it is well formed (i.e. contains 'name' and > 'source' values). If not, call `parserFail` with an appropriate > message. > _______________________________________________ > 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 Sun Mar 6 10:17:19 2016 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 6 Mar 2016 11:17:19 +0100 Subject: [Haskell-beginners] Parsing In-Reply-To: <07C761EA-42E0-490F-898D-031F52B94EC4@yahoo.co.uk> References: <20160306093019.GA6926@casa.casa> <07C761EA-42E0-490F-898D-031F52B94EC4@yahoo.co.uk> Message-ID: <20160306101719.GA7364@casa.casa> On Sun, Mar 06, 2016 at 09:54:34AM +0000, Mike Houghton wrote: > Hi Francesco, > Quick response! Thanks. > > I see, so would it reduce to something like? > many itemValue > > and originally I was thinking the data structure that it would parse > into would be > > data Module = Module {? some record structure?} > > but now it would be roughly like? > > type Entry = (String, String) > > data Module = Module [Entry] > > Thanks Yes, it would lead to some kind of (YourType, String) association list. If you are more interested in a datatype with records I see two ways of achieving it: a. a function `[(YrType, String)] -> RecordsData` (not so pretty but doable, also you can check for well-formedness here) (Using a sum type YrType is in my opinion better than plain Strings as it catches some more errors at compile time). b. directly via parsing, using `optionMaybe` and glue. Depending on how your input is structured this may or may not be more hairy (can name and source appear after an optional tag? What about duplicated tags? etc.). In its simplest form you can use a succinct applicative-style, but the castle crumbles if want more. See which fits better (I suspect a.), play with it and report back; parsing has never been an elegant business! From mike_k_houghton at yahoo.co.uk Sun Mar 6 10:48:11 2016 From: mike_k_houghton at yahoo.co.uk (Mike Houghton) Date: Sun, 6 Mar 2016 10:48:11 +0000 Subject: [Haskell-beginners] Parsing In-Reply-To: <20160306101719.GA7364@casa.casa> References: <20160306093019.GA6926@casa.casa> <07C761EA-42E0-490F-898D-031F52B94EC4@yahoo.co.uk> <20160306101719.GA7364@casa.casa> Message-ID: <29058C45-277E-40FC-81DE-A0BF0F176485@yahoo.co.uk> Hi Francesco, This is really helpful - thank you. I?m neutral about using a record - it is just how I?d done other simple parsers before. Using a list of tuples seems to simplify the parsing but then the ?hit? comes on converting to a record. However, this has made me question the necessity of a record, I suspect the processing subsequent to parsing can be better achieved by mapping over the list. Thanks > On 6 Mar 2016, at 10:17, Francesco Ariis wrote: > > On Sun, Mar 06, 2016 at 09:54:34AM +0000, Mike Houghton wrote: >> Hi Francesco, >> Quick response! Thanks. >> >> I see, so would it reduce to something like? >> many itemValue >> >> and originally I was thinking the data structure that it would parse >> into would be >> >> data Module = Module {? some record structure?} >> >> but now it would be roughly like? >> >> type Entry = (String, String) >> >> data Module = Module [Entry] >> >> Thanks > > Yes, it would lead to some kind of (YourType, String) association list. > If you are more interested in a datatype with records I see two > ways of achieving it: > > a. a function `[(YrType, String)] -> RecordsData` (not so > pretty but doable, also you can check for well-formedness here) > (Using a sum type YrType is in my opinion better than plain > Strings as it catches some more errors at compile time). > > b. directly via parsing, using `optionMaybe` and glue. > Depending on how your input is structured this may or may not be > more hairy (can name and source appear after an optional tag? > What about duplicated tags? etc.). > In its simplest form you can use a succinct applicative-style, > but the castle crumbles if want more. > > > See which fits better (I suspect a.), play with it and report > back; parsing has never been an elegant business! > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From k-bx at k-bx.com Sun Mar 6 11:04:51 2016 From: k-bx at k-bx.com (Kostiantyn Rybnikov) Date: Sun, 6 Mar 2016 13:04:51 +0200 Subject: [Haskell-beginners] Question on terminology In-Reply-To: References: Message-ID: (f a b) still doesn't make a lot of sense, I assume (a -> b) was meant in that argument type. On Mar 3, 2016 21:13, "Rein Henrichs" wrote: > Ben, I just assumed that g was a typo for f. > > On Thu, Mar 3, 2016 at 10:10 AM Ben Rogalski wrote: > >> I'm having trouble understanding this: >> >> > IIUC, one would describe fmap as "lifting" a function g into a functor >> f, >> > in the sense of >> > >> > Functor f => (g a b) -> g a -> g b >> > >> > >> > Is there an inverse concept (? co-lift ?) that describes >> > >> > Functor f => (g a -> g b) -> a -> b >> > >> >> It seems like these are type declarations for functions, with class >> constraints that say f must be a Functor, but then f doesn't appear >> anywhere else in the declaration. Why is this? >> >> Thanks, >> -Ben >> _______________________________________________ >> 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 njdupreez at yahoo.com Sun Mar 6 10:38:47 2016 From: njdupreez at yahoo.com (Nicolaas du Preez) Date: Sun, 6 Mar 2016 12:38:47 +0200 Subject: [Haskell-beginners] Getting a specified number of lines from stdin Message-ID: <6B6F0C1D-7CEA-46E4-9E1B-C3C78709BCCB@yahoo.com> Good day All, Why does liftM (take 5) $ sequence $ repeat getLine not stop at reading only 5 lines from stdin but keeps on reading more? What I?m really trying to achieve is to get input from the user until an empty line is read with the code below. But this doesn?t work as I expected, similar to the above. liftM (takeWhile (/= "")) $ sequence $ repeat getLine Regards, Nicolaas du Preez -------------- next part -------------- An HTML attachment was scrubbed... URL: From hjgtuyl at chello.nl Mon Mar 7 10:32:36 2016 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Mon, 07 Mar 2016 11:32:36 +0100 Subject: [Haskell-beginners] Getting a specified number of lines from stdin In-Reply-To: <6B6F0C1D-7CEA-46E4-9E1B-C3C78709BCCB@yahoo.com> References: <6B6F0C1D-7CEA-46E4-9E1B-C3C78709BCCB@yahoo.com> Message-ID: On Sun, 06 Mar 2016 11:38:47 +0100, Nicolaas du Preez wrote: : > Why does > > liftM (take 5) $ sequence $ repeat getLine > > not stop at reading only 5 lines from stdin but keeps on reading more? > > What I?m really trying to achieve is to get input from the user until > an empty line is read with the code below. But this doesn?t work > as I expected, similar to the above. > > liftM (takeWhile (/= "")) $ sequence $ repeat getLine : It seems that sequence $ repeat getLine is too strict for this; to get five lines, you could use: sequence $ replicate 5 getLine . To read until the first empty line, I would write something in do-notation. Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From anfelor at posteo.de Mon Mar 7 11:29:36 2016 From: anfelor at posteo.de (Anton Felix Lorenzen) Date: Mon, 7 Mar 2016 12:29:36 +0100 Subject: [Haskell-beginners] Getting a specified number of lines from stdin In-Reply-To: <6B6F0C1D-7CEA-46E4-9E1B-C3C78709BCCB@yahoo.com> References: <6B6F0C1D-7CEA-46E4-9E1B-C3C78709BCCB@yahoo.com> Message-ID: <56DD6620.2010101@posteo.de> You can define a mixture of takeWhile and sequence as: takeWhileM :: (a -> Bool) -> [IO a] -> IO [a] takeWhileM _ [] = return [] takeWhileM p (x:xs) = do e <- x if p e then do xs' <- takeWhileM p xs return (e : xs') else return [] and then write: ghci> takeWhileM (/="") (repeat getLine) >>= print asdf asdf ["asdf","asdf"] Yours, Anton Felix Lorenzen From kwangyul.seo at gmail.com Mon Mar 7 12:03:12 2016 From: kwangyul.seo at gmail.com (KwangYul Seo) Date: Mon, 7 Mar 2016 21:03:12 +0900 Subject: [Haskell-beginners] Getting a specified number of lines from stdin In-Reply-To: <6B6F0C1D-7CEA-46E4-9E1B-C3C78709BCCB@yahoo.com> References: <6B6F0C1D-7CEA-46E4-9E1B-C3C78709BCCB@yahoo.com> Message-ID: Hi, Your code does not work because sequence function can't be lazy due to the strictness of IO monad's >>= operation. Here's a more verbose version: readWhile :: (String -> Bool) -> IO [String] readWhile p = do line <- getLine if p line then do lines <- readWhile p return $ line : lines else return [] ghci> readWhile (/="") foo bar ["foo","bar"] On Sun, Mar 6, 2016 at 7:38 PM, Nicolaas du Preez wrote: > Good day All, > > Why does > > liftM (take 5) $ sequence $ repeat getLine > > not stop at reading only 5 lines from stdin but keeps on reading more? > > What I?m really trying to achieve is to get input from the user until > an empty line is read with the code below. But this doesn?t work > as I expected, similar to the above. > > liftM (takeWhile (/= "")) $ sequence $ repeat getLine > > > Regards, > Nicolaas du Preez > > _______________________________________________ > 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 exitconsole at gmail.com Mon Mar 7 18:06:03 2016 From: exitconsole at gmail.com (=?UTF-8?B?RMOhbmllbCBBcmF0w7M=?=) Date: Mon, 7 Mar 2016 19:06:03 +0100 Subject: [Haskell-beginners] Showing Types Message-ID: How does GHCi show types? Is there a magic function (showType :: a -> String) that does that? Or is this feature buried somewhere deep in the compiler? Can I show, compare and reason about types in a Haskell program? This would be cool: ```haskell test = do let len = sum . map (const 1) when (isInfixOf "Integer" (showType len)) $ putStrLn "restrictive type inferred; maybe try turning off monomorphism restriction" ``` From toad3k at gmail.com Mon Mar 7 18:27:31 2016 From: toad3k at gmail.com (David McBride) Date: Mon, 7 Mar 2016 13:27:31 -0500 Subject: [Haskell-beginners] Showing Types In-Reply-To: References: Message-ID: You can use the Data.Typeable module import Data.Typeable :t typeOf True typeOf True :: TypeRep :t show (typeOf True) show (typeOf True) :: String typeOf 1 == typeOf 1 True >typeOf 1 == typeOf True False But it works on concrete types, not functions. Sorry. let len = sum . map (const 1) typeOf len :17:1: No instance for (Typeable b0) arising from a use of ?typeOf? In the expression: typeOf len In an equation for ?it?: it = typeOf len On Mon, Mar 7, 2016 at 1:06 PM, D?niel Arat? wrote: > How does GHCi show types? > > Is there a magic function (showType :: a -> String) that does that? Or > is this feature buried somewhere deep in the compiler? > > Can I show, compare and reason about types in a Haskell program? > > This would be cool: > > ```haskell > test = do > let len = sum . map (const 1) > when (isInfixOf "Integer" (showType len)) $ putStrLn "restrictive type > inferred; maybe try turning off monomorphism restriction" > ``` > _______________________________________________ > 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 rpglover64 at gmail.com Tue Mar 8 15:09:21 2016 From: rpglover64 at gmail.com (Alex Rozenshteyn) Date: Tue, 8 Mar 2016 10:09:21 -0500 Subject: [Haskell-beginners] Showing Types In-Reply-To: References: Message-ID: > But it works on concrete types, not functions. Isn't the problem type variables, not functions? Prelude Data.Typeable> :set -XScopedTypeVariables Prelude Data.Typeable> let fun x = case x of {Just (i::Int) -> i + 1; Nothing -> 0} Prelude Data.Typeable> :t fun fun :: Maybe Int -> Int Prelude Data.Typeable> typeOf fun Maybe Int -> Int -------------- next part -------------- An HTML attachment was scrubbed... URL: From rpglover64 at gmail.com Tue Mar 8 15:26:21 2016 From: rpglover64 at gmail.com (Alex Rozenshteyn) Date: Tue, 8 Mar 2016 10:26:21 -0500 Subject: [Haskell-beginners] Showing Types In-Reply-To: References: Message-ID: And you also run into trouble with typeOf Nothing. On Tue, Mar 8, 2016 at 10:09 AM, Alex Rozenshteyn wrote: > > But it works on concrete types, not functions. > > Isn't the problem type variables, not functions? > > Prelude Data.Typeable> :set -XScopedTypeVariables > Prelude Data.Typeable> let fun x = case x of {Just (i::Int) -> i + 1; > Nothing -> 0} > Prelude Data.Typeable> :t fun > fun :: Maybe Int -> Int > Prelude Data.Typeable> typeOf fun > Maybe Int -> Int > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From frantisek.kocun at gmail.com Fri Mar 11 15:34:23 2016 From: frantisek.kocun at gmail.com (frantisek kocun) Date: Fri, 11 Mar 2016 16:34:23 +0100 Subject: [Haskell-beginners] Getting a specified number of lines from stdin In-Reply-To: <6B6F0C1D-7CEA-46E4-9E1B-C3C78709BCCB@yahoo.com> References: <6B6F0C1D-7CEA-46E4-9E1B-C3C78709BCCB@yahoo.com> Message-ID: Here is the answer http://stackoverflow.com/questions/34910992/iterate-io-actions-and-laziness You need to write recursive function, not to use iterage or to liftM (take 5) $ sequence $ repeat (unsafeInterleaveIO getLine) On Sun, Mar 6, 2016 at 11:38 AM, Nicolaas du Preez wrote: > Good day All, > > Why does > > liftM (take 5) $ sequence $ repeat getLine > > not stop at reading only 5 lines from stdin but keeps on reading more? > > What I?m really trying to achieve is to get input from the user until > an empty line is read with the code below. But this doesn?t work > as I expected, similar to the above. > > liftM (takeWhile (/= "")) $ sequence $ repeat getLine > > > Regards, > Nicolaas du Preez > > _______________________________________________ > 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 rein.henrichs at gmail.com Fri Mar 11 21:48:40 2016 From: rein.henrichs at gmail.com (Rein Henrichs) Date: Fri, 11 Mar 2016 21:48:40 +0000 Subject: [Haskell-beginners] Getting a specified number of lines from stdin In-Reply-To: References: <6B6F0C1D-7CEA-46E4-9E1B-C3C78709BCCB@yahoo.com> Message-ID: That is an unnecessary use of unsafeInterleaveIO. The solution is actually quite simple: getLines n = replicateM n getLine -------------- next part -------------- An HTML attachment was scrubbed... URL: From rein.henrichs at gmail.com Fri Mar 11 21:50:06 2016 From: rein.henrichs at gmail.com (Rein Henrichs) Date: Fri, 11 Mar 2016 21:50:06 +0000 Subject: [Haskell-beginners] Getting a specified number of lines from stdin In-Reply-To: References: <6B6F0C1D-7CEA-46E4-9E1B-C3C78709BCCB@yahoo.com> Message-ID: Note that replicateM n k = sequence (replicate n k), so this solution is equivalent to Henk-Jan van Tuyl's original solution. On Fri, Mar 11, 2016 at 1:48 PM Rein Henrichs wrote: > That is an unnecessary use of unsafeInterleaveIO. The solution is actually > quite simple: > > getLines n = replicateM n getLine > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sgf.dma at gmail.com Tue Mar 15 10:23:00 2016 From: sgf.dma at gmail.com (Dmitriy Matrosov) Date: Tue, 15 Mar 2016 13:23:00 +0300 Subject: [Haskell-beginners] Multiplicaton of singletons Message-ID: > {-# LANGUAGE DataKinds, KindSignatures, TypeFamilies, UndecidableInstances #-} Hi. I've reading "Part I: Dependent Types in Haskell" by Hiromi ISHII at schoolofhaskell [1] and i can't understand why my multiplication for singletons (that was exercise) does not not work: > data Nat = Z | S Nat > > type family Plus (a :: Nat) (b :: Nat) :: Nat where > Plus 'Z b = b > Plus ('S a1) b = 'S (Plus a1 b) > > type family Mult (a :: Nat) (b :: Nat) :: Nat where > Mult 'Z b = 'Z > Mult ('S 'Z) b = b > Mult ('S a1) b = Plus (Mult a1 b) b > > data SNat :: Nat -> * where > SZ :: SNat 'Z > SN :: SNat n -> SNat ('S n) > > plusN :: SNat n -> SNat m -> SNat (Plus n m) > plusN SZ y = y > plusN (SN x) y = SN (plusN x y) > > multN :: SNat n -> SNat m -> SNat (Mult n m) > multN SZ y = SZ > multN (SN SZ) y = y > multN (SN x) y = plusN (multN x y) y The last line (multN) does not type-check with error: 1.lhs:31:25: Could not deduce (Mult ('S n1) m ~ Plus (Mult n1 m) m) from the context (n ~ 'S n1) bound by a pattern with constructor SN :: forall (n :: Nat). SNat n -> SNat ('S n), in an equation for ?multN? at 1.lhs:31:10-13 Expected type: SNat (Mult n m) Actual type: SNat (Plus (Mult n1 m) m) Relevant bindings include y :: SNat m (bound at 1.lhs:31:17) x :: SNat n1 (bound at 1.lhs:31:13) multN :: SNat n -> SNat m -> SNat (Mult n m) (bound at 1.lhs:29:3) In the expression: plusN (multN x y) y In an equation for ?multN?: multN (SN x) y = plusN (multN x y) y Though, when (n ~ 'S n1) i get `SNat (Mult ('S n1) m)` and by definition of Mult this is `SNat (Plus (Mult n1 m) m)` . On the other hand, when i check the type of expression, i get `SNat (Plus (Mult n1 m) m)` by definition of plusN. I.e. exactly the same type. [1]: https://www.schoolofhaskell.com/user/konn/prove-your-haskell-for-great-safety/dependent-types-in-haskell -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Wed Mar 16 02:17:58 2016 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Tue, 15 Mar 2016 19:17:58 -0700 Subject: [Haskell-beginners] lookAhead Message-ID: I'm working with "lookAhead" in Parsec. My goal is to simplify error messages and make them more relevant. I'm parsing strings that represent musical score text markings that convey nuances of playback expression. I worked long and hard to devise a concise syntax that has sufficient expressive power --- must be concise because there is little room in these score for text markings, especially if there are a lot of them. The result is that it looks a little cryptic. 1;%2|> <%4| <<5:4 <<5:4a etc. My first parser worked, but would give error messages like "Unexpected ';', expected digit, ';', '%', '<<', '|', .... etc., basically giving me no clue what the parser was thinking. The first challenge is that it's hard to identify the particular type of mark from the first few characters. For instance, a mark like this "1;%2|>" --- what gives it away is the ">" at the very end. That means it's a "right-facing warp" and that defines what to expect in the other characters. So it would be great if my parser first identified this as a "right-facing warp" and then when parsing the internals it can give messages that make sense in context. So I tried this, with lookAhead rightWarp = do try (lookAhead (do many1 (noneOf "<>") char '>' eof)) ... parse internals ... char '>' eof The problem is that I want to put a message in here somewhere so that if this whole 'rightWarp' parser fails, it will say "expected right warp". But I have found with experiment that the parser considers the point of failure to be in different places inside the lookAhead. For instance if I give an input string that has too many characters at the end, the failure point will be the 'eof' inside the lookAhead. If I put a message anywhere else, the parser will just say "expected end of input". On the other hand, if there is no '>' character, then the failure point will be "char '>'" and the message will be "expected >". What I was hoping was that there was some single place I could put a message that would say "expected right warp" no matter where inside rightWarp the failure point occurs. Any ideas? Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: From sgf.dma at gmail.com Wed Mar 16 10:08:44 2016 From: sgf.dma at gmail.com (Dmitriy Matrosov) Date: Wed, 16 Mar 2016 13:08:44 +0300 Subject: [Haskell-beginners] Multiplicaton of singletons In-Reply-To: References: Message-ID: On Tue, Mar 15, 2016 at 1:23 PM, Dmitriy Matrosov wrote: > > {-# LANGUAGE DataKinds, KindSignatures, TypeFamilies, > UndecidableInstances #-} > > Hi. > > I've reading "Part I: Dependent Types in Haskell" by Hiromi ISHII at > schoolofhaskell [1] and i can't understand why my multiplication for > singletons (that was exercise) does not not work: > > > data Nat = Z | S Nat > > > > type family Plus (a :: Nat) (b :: Nat) :: Nat where > > Plus 'Z b = b > > Plus ('S a1) b = 'S (Plus a1 b) > > > > type family Mult (a :: Nat) (b :: Nat) :: Nat where > > Mult 'Z b = 'Z > > Mult ('S 'Z) b = b > > Mult ('S a1) b = Plus (Mult a1 b) b > > > > data SNat :: Nat -> * where > > SZ :: SNat 'Z > > SN :: SNat n -> SNat ('S n) > > > > plusN :: SNat n -> SNat m -> SNat (Plus n m) > > plusN SZ y = y > > plusN (SN x) y = SN (plusN x y) > > > > multN :: SNat n -> SNat m -> SNat (Mult n m) > > multN SZ y = SZ > > multN (SN SZ) y = y > > multN (SN x) y = plusN (multN x y) y > > The last line (multN) does not type-check with error: > > 1.lhs:31:25: > Could not deduce (Mult ('S n1) m ~ Plus (Mult n1 m) m) > from the context (n ~ 'S n1) > bound by a pattern with constructor > SN :: forall (n :: Nat). SNat n -> SNat ('S n), > in an equation for ?multN? > at 1.lhs:31:10-13 > Expected type: SNat (Mult n m) > Actual type: SNat (Plus (Mult n1 m) m) > Relevant bindings include > y :: SNat m (bound at 1.lhs:31:17) > x :: SNat n1 (bound at 1.lhs:31:13) > multN :: SNat n -> SNat m -> SNat (Mult n m) (bound at 1.lhs:29:3) > In the expression: plusN (multN x y) y > In an equation for ?multN?: multN (SN x) y = plusN (multN x y) y > > Though, when (n ~ 'S n1) i get `SNat (Mult ('S n1) m)` and by definition of > Mult this is `SNat (Plus (Mult n1 m) m)` . On the other hand, when i check > the > type of expression, i get `SNat (Plus (Mult n1 m) m)` by definition of > plusN. > I.e. exactly the same type. > > > [1]: > https://www.schoolofhaskell.com/user/konn/prove-your-haskell-for-great-safety/dependent-types-in-haskell > > Aah, it seems, the reason is wrong (my) definition of Mult: 2nd and 3rd type family branches are not compatible: `Mult ('S 'Z) b` and `Mult ('S a1) b` are not apart (hm.. probably; not sure what "arbitrary type-family simplifications" means in [2], 6.2.1) and their RHS-es are not the same "under the substitution induced by the unification" ([2], 6.2.1). And because 2nd branch is not needed at all, all works fine with such Mult: > type family Mult (a :: Nat) (b :: Nat) :: Nat where > Mult 'Z b = 'Z > Mult ('S a1) b = Plus (Mult a1 b) b [2]: https://wiki.haskell.org/GHC/Type_families#Closed_family_simplification -------------- next part -------------- An HTML attachment was scrubbed... URL: From frederic-emmanuel.picca at synchrotron-soleil.fr Sat Mar 19 11:47:47 2016 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Sat, 19 Mar 2016 11:47:47 +0000 Subject: [Haskell-beginners] haskell + python numpy Message-ID: Hello, I would like to use some python code in order to do my computation with haskell. The idea is to use python and all it's numrical stack in some places, until I find the time to replace the python code by some haskell code. what I will do is read the data from hdf5 with bindings-hdf5 in haskell obtain a Storable for all my data images then I would like to create a python object which will use these data in order to generate in return another array. get back this array and put it into another hdf5 file. Indeed I want to do this with the pipes library. I would like to know if someone have some code examples for this kind of use case. interfacing haskell with python numpy object back and forth. thanks for your help Frederic From mike_k_houghton at yahoo.co.uk Sat Mar 19 13:19:36 2016 From: mike_k_houghton at yahoo.co.uk (Mike Houghton) Date: Sat, 19 Mar 2016 13:19:36 +0000 Subject: [Haskell-beginners] Parsing In-Reply-To: <20160306101719.GA7364@casa.casa> References: <20160306093019.GA6926@casa.casa> <07C761EA-42E0-490F-898D-031F52B94EC4@yahoo.co.uk> <20160306101719.GA7364@casa.casa> Message-ID: Hi, Just to recap I wanted to parse name:value pairs where some pairs are mandatory and some are not. eg //these are mandatory location : /user/local target : /x/y //these are optional copyTo : /a/b trace : bla blah ,,, undo : etc etc so I made data Item = Item (Name, Value) deriving (Show) where Name, Value are strings and made a parser for it. -- KeyWordItemParser kwip :: String -> Parser Item kwip keyWord = do spaces name <- string keyWord spaces char ':' spaces val <- itemValue spaces return $ Item (name, val) I made the mandatory of fixed order and hence easy to parse. For the optional I ended up defining a fixed order in which they can appear if indeed they do appear. So, for example, ?copyTo' has to come before ?trace? This allowed code like many $ kwip ?copyTo" many $ kwip ?trace" many $ kwip ?undo" which of course may result in duplicates that are later flagged as errors in post parsing validation. This validation step was needed anyway for other checking so a bit more was sort of ok. Pragmatically speaking It works ok but I?m not really happy with it. I?d really like to not have to enforce order. What I have been considering but have not yet been able to articulate in Haskell is, for parsing the optionals in any order, is to create a list of parsers and apply whilst removing parsers from the list. i.e. in pseudo code? Try to parse A : w B : x C : y D : z in any order parserList = [kwip A, kwip B, kwip C, kwip D] parse list text = do parserList empty? then done try a parser from parserList until one works - if none work then done (or error) if one worked accumulate result remove succesful parser from parserList then call again Any advice on how to write this in Haskell would be appreciated. Many thanks Mike > On 6 Mar 2016, at 10:17, Francesco Ariis wrote: > > On Sun, Mar 06, 2016 at 09:54:34AM +0000, Mike Houghton wrote: >> Hi Francesco, >> Quick response! Thanks. >> >> I see, so would it reduce to something like? >> many itemValue >> >> and originally I was thinking the data structure that it would parse >> into would be >> >> data Module = Module {? some record structure?} >> >> but now it would be roughly like? >> >> type Entry = (String, String) >> >> data Module = Module [Entry] >> >> Thanks > > Yes, it would lead to some kind of (YourType, String) association list. > If you are more interested in a datatype with records I see two > ways of achieving it: > > a. a function `[(YrType, String)] -> RecordsData` (not so > pretty but doable, also you can check for well-formedness here) > (Using a sum type YrType is in my opinion better than plain > Strings as it catches some more errors at compile time). > > b. directly via parsing, using `optionMaybe` and glue. > Depending on how your input is structured this may or may not be > more hairy (can name and source appear after an optional tag? > What about duplicated tags? etc.). > In its simplest form you can use a succinct applicative-style, > but the castle crumbles if want more. > > > See which fits better (I suspect a.), play with it and report > back; parsing has never been an elegant business! > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From bergey at alum.mit.edu Sat Mar 19 13:58:32 2016 From: bergey at alum.mit.edu (Daniel Bergey) Date: Sat, 19 Mar 2016 09:58:32 -0400 Subject: [Haskell-beginners] haskell + python numpy In-Reply-To: References: Message-ID: <874mc2lgc7.fsf@chladni.i-did-not-set--mail-host-address--so-tickle-me> I've seen a couple of blog posts (with code) about calling Python from Haskell. I haven't tried any of this code myself, and I can't recall seeing anything specifically about Numpy types. circa 2010: https://john-millikin.com/articles/ride-the-snake/ 2014: http://www.lunaryorn.com/2014/04/15/calling-python-from-haskell.html 2014-2015: https://github.com/Russell91/pyfi bergey On 2016-03-19 at 07:47, PICCA Frederic-Emmanuel wrote: > Hello, > > I would like to use some python code in order to do my computation with haskell. > The idea is to use python and all it's numrical stack in some places, until I find the time to replace the python code by some haskell code. > > what I will do is > > read the data from hdf5 with bindings-hdf5 in haskell > obtain a Storable for all my data images > then I would like to create a python object which will use these data in order to generate in return another array. > > get back this array and put it into another hdf5 file. > > Indeed I want to do this with the pipes library. > > I would like to know if someone have some code examples for this kind of use case. > > interfacing haskell with python numpy object back and forth. > > thanks for your help > > Frederic > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From miroslav.karpis at gmail.com Sun Mar 20 07:02:07 2016 From: miroslav.karpis at gmail.com (Miro Karpis) Date: Sun, 20 Mar 2016 08:02:07 +0100 Subject: [Haskell-beginners] better way: contains one of a string from list in a string Message-ID: Hi, I needed a function that returns True/False if a list of strings are in a given string. I made one function below (works fine),..but I was wondering whether there is a shorter way? -- |Returns True if one of given strings are contained in given string contains :: [String] -> String -> Bool contains elements seach_elem | trueListCount == 0 = False | otherwise = True where isInStringList = [isInfixOf elem seach_elem | elem <- elements] onlyTrueList = [elem | elem <- isInStringList, elem == True] trueListCount = length onlyTrueList Cheers, -m -------------- next part -------------- An HTML attachment was scrubbed... URL: From maydwell at gmail.com Sun Mar 20 07:11:24 2016 From: maydwell at gmail.com (Lyndon Maydwell) Date: Sun, 20 Mar 2016 18:11:24 +1100 Subject: [Haskell-beginners] better way: contains one of a string from list in a string In-Reply-To: References: Message-ID: You can get that one quite easily using 'any'. E.g. [Prelude Data.List] ? let contains xs x = any (`isInfixOf` x) xs contains :: (Eq a, Foldable t) => t [a] -> [a] -> Bool [Prelude Data.List] ? contains (words "a b c d efg") "refgood" True it :: Bool [Prelude Data.List] ? contains (words "a b c d efg") "ref" False it :: Bool On Sun, Mar 20, 2016 at 6:02 PM, Miro Karpis wrote: > Hi, > > I needed a function that returns True/False if a list of strings are in a > given string. I made one function below (works fine),..but I was wondering > whether there is a shorter way? > > > -- |Returns True if one of given strings are contained in given string > contains :: [String] -> String -> Bool > contains elements seach_elem > | trueListCount == 0 = False > | otherwise = True > where > isInStringList = [isInfixOf elem seach_elem | elem <- elements] > onlyTrueList = [elem | elem <- isInStringList, elem == True] > trueListCount = length onlyTrueList > > > Cheers, > -m > > _______________________________________________ > 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 newhoggy at gmail.com Sun Mar 20 10:19:50 2016 From: newhoggy at gmail.com (John Ky) Date: Sun, 20 Mar 2016 10:19:50 +0000 Subject: [Haskell-beginners] How to call popCnt64#? Message-ID: Hello Haskellers, Does anyone know how to call popCnt64# from the GHC.Prim module? This was my failed attempt: ?> popCnt64# 1 :14:11: Couldn't match kind ?*? with ?#? When matching types a0 :: * Word# :: # Expected type: Integer -> Word# Actual type: Integer -> a0 In the first argument of ?popCnt64#?, namely ?1? In the expression: popCnt64# 1 In an equation for ?it?: it = popCnt64# 1 -John -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael at snoyman.com Sun Mar 20 14:12:42 2016 From: michael at snoyman.com (Michael Snoyman) Date: Sun, 20 Mar 2016 16:12:42 +0200 Subject: [Haskell-beginners] How to call popCnt64#? In-Reply-To: References: Message-ID: Here's an example: {-# LANGUAGE MagicHash #-} import GHC.Prim import GHC.Types import Data.Word main :: IO () main = do let word = 5 :: Word res = case word of W# w -> W# (popCnt64# w) print res On Sun, Mar 20, 2016 at 12:19 PM, John Ky wrote: > Hello Haskellers, > > Does anyone know how to call popCnt64# from the GHC.Prim module? > > This was my failed attempt: > > ?> popCnt64# 1 > > > :14:11: > Couldn't match kind ?*? with ?#? > When matching types > a0 :: * > Word# :: # > Expected type: Integer -> Word# > Actual type: Integer -> a0 > In the first argument of ?popCnt64#?, namely ?1? > In the expression: popCnt64# 1 > In an equation for ?it?: it = popCnt64# 1 > > -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: From genton.antoine at gmail.com Sun Mar 20 15:21:11 2016 From: genton.antoine at gmail.com (Antoine Genton) Date: Sun, 20 Mar 2016 11:21:11 -0400 Subject: [Haskell-beginners] Using Cassava with medium sized files (~50MB) Message-ID: Hello, I tried to load a ~50MB csv file in memory with cassava but found that my program was incredibly slow. After doing some profiling, I realized that it used an enormous amount of memory in the heap: 24,626,540,552 bytes allocated in the heap 6,946,460,688 bytes copied during GC 2,000,644,712 bytes copied maximum residency (14 sample(s)) 319,728,944 bytes maximum slop 3718 MB total memory in use (0MB lost due to fragmentation) ... %GC time 84.0% (94.3% elapsed) Seeing that, I have the feeling that my program lacks strictness and accumulates thunks in memory. I tried two versions, on using Data.Csv, and one using Data.Csv.Streaming. Both are giving the same result. What am I doing wrong? Here are the two sources: 1/ import Data.Csv import Data.ByteString.Lazy as BL import qualified Data.Vector as V main :: IO () main = do csv <- BL.readFile "tt.csv" let !res = case decode NoHeader csv of Right q -> q :: V.Vector(V.Vector(ByteString)) print $ res V.! 0 -------------------------------- 2/ import Data.Csv.Streaming import Data.ByteString.Lazy as BL import qualified Data.Vector as V import Data.Foldable main :: IO () main = do csv <- BL.readFile "tt.csv" let !a = decode NoHeader csv :: Records(V.Vector(ByteString)) let !xx = V.fromList $ [V.fromList([])] :: V.Vector(V.Vector(ByteString)) let !res = Data.Foldable.foldr' V.cons xx a print $ res V.! 0 The goal of the program is ultimately to have the csv loaded in memory as a Vector of Vector of ByteString for further processing later on. Thank you for your help, Antoine -------------- next part -------------- An HTML attachment was scrubbed... URL: From newhoggy at gmail.com Mon Mar 21 22:30:17 2016 From: newhoggy at gmail.com (John Ky) Date: Mon, 21 Mar 2016 22:30:17 +0000 Subject: [Haskell-beginners] How to call popCnt64#? In-Reply-To: References: Message-ID: Hi Michael, Yes, that did the trick. Thanks! -John On Mon, 21 Mar 2016 at 01:13 Michael Snoyman wrote: > Here's an example: > > {-# LANGUAGE MagicHash #-} > import GHC.Prim > import GHC.Types > import Data.Word > > main :: IO () > main = do > let word = 5 :: Word > res = > case word of > W# w -> W# (popCnt64# w) > print res > > > On Sun, Mar 20, 2016 at 12:19 PM, John Ky wrote: > >> Hello Haskellers, >> >> Does anyone know how to call popCnt64# from the GHC.Prim module? >> >> This was my failed attempt: >> >> ?> popCnt64# 1 >> >> >> :14:11: >> Couldn't match kind ?*? with ?#? >> When matching types >> a0 :: * >> Word# :: # >> Expected type: Integer -> Word# >> Actual type: Integer -> a0 >> In the first argument of ?popCnt64#?, namely ?1? >> In the expression: popCnt64# 1 >> In an equation for ?it?: it = popCnt64# 1 >> >> -John >> >> >> _______________________________________________ >> 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 marcin.jan.mrotek at gmail.com Tue Mar 22 07:25:15 2016 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Tue, 22 Mar 2016 08:25:15 +0100 Subject: [Haskell-beginners] How to call popCnt64#? In-Reply-To: References: Message-ID: Hi, In general, the problem is that GHCi is attempting to call `show` on the results of expressions you type in, but `show` (like any other polymorphic function; though you can look into "levity polymorphism" if you want to know more) can only accept values of types of kind * (boxed, lifted) - so it can print Word, but not Word#. If you wanted to stay in GHCi, you can do it like: Prelude> import GHC.Prim Prelude GHC.Prim> import GHC.Types Prelude GHC.Prim GHC.Types> :set -XMagicHash Prelude GHC.Prim GHC.Types> :t W# W# :: Word# -> Word Prelude GHC.Prim GHC.Types> :t popCnt64# popCnt64# :: Word# -> Word# Prelude GHC.Prim GHC.Types> let foo = (1 :: Word) Prelude GHC.Prim GHC.Types> :set -XBangPatterns Prelude GHC.Prim GHC.Types> let !(W# w) = foo in W# (popCnt64# w) 1 Best regards, Marcin Mrotek -------------- next part -------------- An HTML attachment was scrubbed... URL: From 50295 at web.de Tue Mar 22 10:43:46 2016 From: 50295 at web.de (Olumide) Date: Tue, 22 Mar 2016 10:43:46 +0000 Subject: [Haskell-beginners] Need help groking the statement: expression1 in term:expression2 Message-ID: <56F121E2.2010008@web.de> Hello List, I'd appreciate help understanding the second line of following block of code (from LYH, first line added for completeness), http://learnyouahaskell.com/input-and-output#randomness randoms' :: (RandomGen g, Random a) => g -> [a] randoms' gen = let (value, newGen) = random gen in value:randoms' newGen The part I'm really struggling with is random gen in value:randoms' newGen Thanks, - Olumide From 50295 at web.de Tue Mar 22 10:52:41 2016 From: 50295 at web.de (Olumide) Date: Tue, 22 Mar 2016 10:52:41 +0000 Subject: [Haskell-beginners] Do IO actions *have* to be glued by the do syntax? Message-ID: <56F123F9.1050805@web.de> Hello List, Do IO actions *have* to be glued by the do syntax? Many, if not all, the examples that I've come across in LYH seem to suggest so. And if so, why? BTW, if possible I'd appreciate an explanation that does not resort to monads. I haven't studied them yet and I'm sure I'd struggle to understand any explanation that resorts to monads. Thanks, - Olumide From lqymgt at gmail.com Tue Mar 22 10:57:56 2016 From: lqymgt at gmail.com (Quanyang Liu) Date: Tue, 22 Mar 2016 18:57:56 +0800 Subject: [Haskell-beginners] Need help groking the statement: expression1 in term:expression2 In-Reply-To: <56F121E2.2010008@web.de> (Olumide's message of "Tue, 22 Mar 2016 10:43:46 +0000") References: <56F121E2.2010008@web.de> Message-ID: <87egb2ixu3.fsf@gmail.com> On Tue, Mar 22 2016 at 18:43:46 +0800, Olumide wrote: > Hello List, > > I'd appreciate help understanding the second line of following block > of code (from LYH, first line added for completeness), > > http://learnyouahaskell.com/input-and-output#randomness > randoms' :: (RandomGen g, Random a) => g -> [a] > randoms' gen = let (value, newGen) = random gen in value:randoms' newGen > It's equivalent to the following: randoms' gen = let (value, newGen) = random gen in value:(randoms' newGen) > The part I'm really struggling with is random gen in value:randoms' newGen > > Thanks, > > - Olumide -- Thanks, Quanyang From lqymgt at gmail.com Tue Mar 22 11:06:21 2016 From: lqymgt at gmail.com (Quanyang Liu) Date: Tue, 22 Mar 2016 19:06:21 +0800 Subject: [Haskell-beginners] Do IO actions *have* to be glued by the do syntax? In-Reply-To: <56F123F9.1050805@web.de> (Olumide's message of "Tue, 22 Mar 2016 10:52:41 +0000") References: <56F123F9.1050805@web.de> Message-ID: <87a8lqixg2.fsf@gmail.com> On Tue, Mar 22 2016 at 18:52:41 +0800, Olumide wrote: > Hello List, > > Do IO actions *have* to be glued by the do syntax? Many, if not all, > the examples that I've come across in LYH seem to suggest so. And if > so, why? > > BTW, if possible I'd appreciate an explanation that does not resort to > monads. I haven't studied them yet and I'm sure I'd struggle to > understand any explanation that resorts to monads. > I think you should google that first... do blocks are just sugar... > Thanks, > > - Olumide -- Thanks, Quanyang From dani at dpwright.com Tue Mar 22 11:26:00 2016 From: dani at dpwright.com (Daniel Wright) Date: Tue, 22 Mar 2016 20:26:00 +0900 Subject: [Haskell-beginners] Do IO actions *have* to be glued by the do syntax? In-Reply-To: <56F123F9.1050805@web.de> References: <56F123F9.1050805@web.de> Message-ID: <70B029B6-60B1-4B5D-91AA-9D38596C31B6@dpwright.com> Hello Olumide, The simple answer is "no", do syntax is an entirely optional piece of syntactic sugar that is just there to make the code easier to read in some cases. But, IO actions do have to be glued together by something, and that something is the >>= operator (pronounced "bind"). >>= takes an IO action on the left, (let's use getLine, which reads a line from the user, for our example) and a function on the right which takes the result of that action and returns the next IO action to perform. For example: > getLine >>= (\line -> putStrLn line) Here we can see the getLine action on the left. The result of that is passed, through the mechanism provided by >>=, to the function on the right, which is a lambda function taking that line as a parameter and calling the action "putStrLn" to print it back out again. This is equivalent to the following do notation: > do > line <- getLine > putStrLn line What if you want to string together more than two actions, though? For example, say we wanted to get two lines and concatenation them in the output, like so: > do > line1 <- getLine > line2 <- getLine > putStrLn (line1 ++ line2) Since >>= can only take two parameters, what do we do? Well, since the result of >>= is itself an IO action, we can use it again in the function on the right! Like this: > getLine >>= (\line1 -> (getLine >>= (\line2 -> putStrLn (line1 ++ line2)))) Now, this may be starting to look a little bit like lisp with all the parentheses! In fact, because of the associativity of the >>= operator, the brackets are all optional, but they may be helpful for you to see what's going on. Without the brackets, it looks like this: > getLine >>= \line1 -> getLine >>= \line2 -> putStrLn (line1 ++ line2) Which, if you were to lay it out a little differently, looks like this: > getLine >>= \line1 -> > getLine >>= \line2 -> > putStrLn (line1 ++ line2) ...Starting to look a little more like the do syntax version above, isn't it? What if you don't care about the value of the parameter? Well, you could ignore it using the _ syntax like this: > getLine >>= \_ -> putStrLn "42" But Haskell actually provides an operator to save you the effort, called >>, so you can do: > getLine >> putStrLn "42" Do notation is a purely syntactic transformation that emits code using these operators. Incidentally, the function on the right doesn't have to be a lambda function! Any function taking a value of whatever type is returned by the action on the left will do, and in the case of getLine/putStrLn they match! So the first example could be rewritten: > getLine >>= putStrLn Which many would argue looks nicer than the equivalent do notation. Hope that helps, sorry if it was a little verbose! -Dani. PS- I know you said not to mention monads, but if you followed everything above you're 90% of the way there anyway -- a monad is just a type class providing the >>= operator, and the "return" function, which takes a value and turns it into an action returning that value (at least in terms of the IO monad). > On Mar 22, 2016, at 19:52, Olumide <50295 at web.de> wrote: > > Hello List, > > Do IO actions *have* to be glued by the do syntax? Many, if not all, the examples that I've come across in LYH seem to suggest so. And if so, why? > > BTW, if possible I'd appreciate an explanation that does not resort to monads. I haven't studied them yet and I'm sure I'd struggle to understand any explanation that resorts to monads. > > Thanks, > > - Olumide > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From 50295 at web.de Tue Mar 22 11:36:53 2016 From: 50295 at web.de (Olumide) Date: Tue, 22 Mar 2016 11:36:53 +0000 Subject: [Haskell-beginners] Do IO actions *have* to be glued by the do syntax? In-Reply-To: <87a8lqixg2.fsf@gmail.com> References: <56F123F9.1050805@web.de> <87a8lqixg2.fsf@gmail.com> Message-ID: <56F12E55.2040202@web.de> Quanyang, do bocks are *not* sugar, and please refer to Daniel's answer for an example of how to answer a beginner's question. - Olumide On 22/03/2016 11:06, Quanyang Liu wrote: > On Tue, Mar 22 2016 at 18:52:41 +0800, Olumide wrote: >> Hello List, >> >> Do IO actions *have* to be glued by the do syntax? Many, if not all, >> the examples that I've come across in LYH seem to suggest so. And if >> so, why? >> >> BTW, if possible I'd appreciate an explanation that does not resort to >> monads. I haven't studied them yet and I'm sure I'd struggle to >> understand any explanation that resorts to monads. >> > > I think you should google that first... do blocks are just sugar... > >> Thanks, >> >> - Olumide > From sumit.sahrawat.apm13 at iitbhu.ac.in Tue Mar 22 11:38:10 2016 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 22 Mar 2016 17:08:10 +0530 Subject: [Haskell-beginners] Need help groking the statement: expression1 in term:expression2 In-Reply-To: <56F121E2.2010008@web.de> References: <56F121E2.2010008@web.de> Message-ID: On 22-Mar-2016 4:14 pm, "Olumide" <50295 at web.de> wrote: > randoms' :: (RandomGen g, Random a) => g -> [a] > randoms' gen = let (value, newGen) = random gen in value:randoms' newGen "random gen" returns a pair, whose first element is a random value, and the second element is a new generator. The cons (:) operator takes two values, one is an element, and the other is a list. It returns a new list with the provided arguments as head and tail. Ultimately, randoms' gen returns a list whose first element is a random value, and the rest of the list is the result of calling randoms' on the newly produced generator. Recursively, it generates an infinite lazy list of random elements. Hope this helps :) Regards, Sumit -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at vlkk.cz Tue Mar 22 11:41:02 2016 From: martin at vlkk.cz (Martin Vlk) Date: Tue, 22 Mar 2016 12:41:02 +0100 Subject: [Haskell-beginners] Do IO actions *have* to be glued by the do syntax? In-Reply-To: <56F12E55.2040202@web.de> References: <56F123F9.1050805@web.de> <87a8lqixg2.fsf@gmail.com> <56F12E55.2040202@web.de> Message-ID: <1458646862.2849307.556282290.2AE66E85@webmail.messagingengine.com> Hi Olumide, Yes, do blocks are syntactic sugar. Yes you are right in that answers here should be .. a bit friendlier. But also in my opinion your last post is a bit.. arrogant sounding... M. Dne ?t, 22. b?ezen 2016 v 12:36 h u?ivatel Olumide napsal: > Quanyang, > > do bocks are *not* sugar, and please refer to Daniel's answer for an > example of how to answer a beginner's question. > > - Olumide > > On 22/03/2016 11:06, Quanyang Liu wrote: > > On Tue, Mar 22 2016 at 18:52:41 +0800, Olumide wrote: > >> Hello List, > >> > >> Do IO actions *have* to be glued by the do syntax? Many, if not all, > >> the examples that I've come across in LYH seem to suggest so. And if > >> so, why? > >> > >> BTW, if possible I'd appreciate an explanation that does not resort to > >> monads. I haven't studied them yet and I'm sure I'd struggle to > >> understand any explanation that resorts to monads. > >> > > > > I think you should google that first... do blocks are just sugar... > > > >> Thanks, > >> > >> - Olumide > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From sumit.sahrawat.apm13 at iitbhu.ac.in Tue Mar 22 11:46:40 2016 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 22 Mar 2016 17:16:40 +0530 Subject: [Haskell-beginners] Do IO actions *have* to be glued by the do syntax? In-Reply-To: <56F12E55.2040202@web.de> References: <56F123F9.1050805@web.de> <87a8lqixg2.fsf@gmail.com> <56F12E55.2040202@web.de> Message-ID: Olumide, do blocks are indeed syntactic sugar. They are a piece of syntax that converts to a specific type of expressions, namely those using the bind (>>=) operator. It is really helpful, when learning to be able to come up with answers in your own. Learning Haskell has always involved combining many different perspectives on the same topic, told differently in different places. It would only help you if you took the time and dug further for answers. It's really satisfying too! Also, if you haven't, search for the Leavenworth guide. It takes this very question in one of the miscellaneous discussions. Be nice, be respectful. Have fun learning Haskell :) On 22-Mar-2016 5:07 pm, "Olumide" <50295 at web.de> wrote: > Quanyang, > > do bocks are *not* sugar, and please refer to Daniel's answer for an > example of how to answer a beginner's question. > > - Olumide > > On 22/03/2016 11:06, Quanyang Liu wrote: > >> On Tue, Mar 22 2016 at 18:52:41 +0800, Olumide wrote: >> >>> Hello List, >>> >>> Do IO actions *have* to be glued by the do syntax? Many, if not all, >>> the examples that I've come across in LYH seem to suggest so. And if >>> so, why? >>> >>> BTW, if possible I'd appreciate an explanation that does not resort to >>> monads. I haven't studied them yet and I'm sure I'd struggle to >>> understand any explanation that resorts to monads. >>> >>> >> I think you should google that first... do blocks are just sugar... >> >> Thanks, >>> >>> - Olumide >>> >> >> > _______________________________________________ > 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 50295 at web.de Tue Mar 22 11:46:00 2016 From: 50295 at web.de (Olumide) Date: Tue, 22 Mar 2016 11:46:00 +0000 Subject: [Haskell-beginners] Do IO actions *have* to be glued by the do syntax? In-Reply-To: <56F12E55.2040202@web.de> References: <56F123F9.1050805@web.de> <87a8lqixg2.fsf@gmail.com> <56F12E55.2040202@web.de> Message-ID: <56F13078.7080509@web.de> Can I also add that this sort of elitist, unhelpful quip of a pseudo-answer is the reason that I've largely avoided asking Haskell beginner questions on stackoverflow. Haskell is a wonderful language with a steep learning curve and I believe that it is the intention of this group grow the user base of the language by create a place where beginners will not be afraid to ask questions. And hasty ill-thought, poorly worded answers like Quanyang's won't help the language get there sooner. - Olumide On 22/03/2016 11:36, Olumide wrote: > Quanyang, > > do bocks are *not* sugar, and please refer to Daniel's answer for an > example of how to answer a beginner's question. > > - Olumide > > On 22/03/2016 11:06, Quanyang Liu wrote: >> On Tue, Mar 22 2016 at 18:52:41 +0800, Olumide wrote: >>> Hello List, >>> >>> Do IO actions *have* to be glued by the do syntax? Many, if not all, >>> the examples that I've come across in LYH seem to suggest so. And if >>> so, why? >>> >>> BTW, if possible I'd appreciate an explanation that does not resort to >>> monads. I haven't studied them yet and I'm sure I'd struggle to >>> understand any explanation that resorts to monads. >>> >> >> I think you should google that first... do blocks are just sugar... >> >>> Thanks, >>> >>> - Olumide >> > From sumit.sahrawat.apm13 at iitbhu.ac.in Tue Mar 22 11:47:43 2016 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 22 Mar 2016 17:17:43 +0530 Subject: [Haskell-beginners] Do IO actions *have* to be glued by the do syntax? In-Reply-To: References: <56F123F9.1050805@web.de> <87a8lqixg2.fsf@gmail.com> <56F12E55.2040202@web.de> Message-ID: Sorry, autocorrect changed learnhaskell to something else. On 22-Mar-2016 5:16 pm, "Sumit Sahrawat, Maths & Computing, IIT (BHU)" < sumit.sahrawat.apm13 at iitbhu.ac.in> wrote: > Olumide, do blocks are indeed syntactic sugar. They are a piece of syntax > that converts to a specific type of expressions, namely those using the > bind (>>=) operator. > > It is really helpful, when learning to be able to come up with answers in > your own. Learning Haskell has always involved combining many different > perspectives on the same topic, told differently in different places. It > would only help you if you took the time and dug further for answers. It's > really satisfying too! > > Also, if you haven't, search for the Leavenworth guide. It takes this very > question in one of the miscellaneous discussions. > > Be nice, be respectful. Have fun learning Haskell :) > On 22-Mar-2016 5:07 pm, "Olumide" <50295 at web.de> wrote: > >> Quanyang, >> >> do bocks are *not* sugar, and please refer to Daniel's answer for an >> example of how to answer a beginner's question. >> >> - Olumide >> >> On 22/03/2016 11:06, Quanyang Liu wrote: >> >>> On Tue, Mar 22 2016 at 18:52:41 +0800, Olumide wrote: >>> >>>> Hello List, >>>> >>>> Do IO actions *have* to be glued by the do syntax? Many, if not all, >>>> the examples that I've come across in LYH seem to suggest so. And if >>>> so, why? >>>> >>>> BTW, if possible I'd appreciate an explanation that does not resort to >>>> monads. I haven't studied them yet and I'm sure I'd struggle to >>>> understand any explanation that resorts to monads. >>>> >>>> >>> I think you should google that first... do blocks are just sugar... >>> >>> Thanks, >>>> >>>> - Olumide >>>> >>> >>> >> _______________________________________________ >> 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 50295 at web.de Tue Mar 22 11:56:21 2016 From: 50295 at web.de (Olumide) Date: Tue, 22 Mar 2016 11:56:21 +0000 Subject: [Haskell-beginners] Do IO actions *have* to be glued by the do syntax? In-Reply-To: References: <56F123F9.1050805@web.de> <87a8lqixg2.fsf@gmail.com> <56F12E55.2040202@web.de> Message-ID: <56F132E5.8010005@web.de> Sumit, I do, and did, look up other resources but none emphasized that IO actions have to be bound, and that's why I asked here. I'm sure it will become clearer when I reach the chapter on monads. @Martin: I realize that I am equally responsible for the culture of the list and will also try to be friendlier ... - Olumide On 22/03/2016 11:46, Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: > Olumide, do blocks are indeed syntactic sugar. They are a piece of > syntax that converts to a specific type of expressions, namely those > using the bind (>>=) operator. > > It is really helpful, when learning to be able to come up with answers > in your own. Learning Haskell has always involved combining many > different perspectives on the same topic, told differently in different > places. It would only help you if you took the time and dug further for > answers. It's really satisfying too! > > Also, if you haven't, search for the Leavenworth guide. It takes this > very question in one of the miscellaneous discussions. > > Be nice, be respectful. Have fun learning Haskell :) > > On 22-Mar-2016 5:07 pm, "Olumide" <50295 at web.de > > wrote: > > Quanyang, > > do bocks are *not* sugar, and please refer to Daniel's answer for an > example of how to answer a beginner's question. > > - Olumide > > On 22/03/2016 11:06, Quanyang Liu wrote: > > On Tue, Mar 22 2016 at 18:52:41 +0800, Olumide wrote: > > Hello List, > > Do IO actions *have* to be glued by the do syntax? Many, if > not all, > the examples that I've come across in LYH seem to suggest > so. And if > so, why? > > BTW, if possible I'd appreciate an explanation that does not > resort to > monads. I haven't studied them yet and I'm sure I'd struggle to > understand any explanation that resorts to monads. > > > I think you should google that first... do blocks are just sugar... > > Thanks, > > - Olumide > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > From lqymgt at gmail.com Tue Mar 22 12:06:14 2016 From: lqymgt at gmail.com (Quanyang Liu) Date: Tue, 22 Mar 2016 20:06:14 +0800 Subject: [Haskell-beginners] Do IO actions *have* to be glued by the do syntax? In-Reply-To: <56F13078.7080509@web.de> (Olumide's message of "Tue, 22 Mar 2016 11:46:00 +0000") References: <56F123F9.1050805@web.de> <87a8lqixg2.fsf@gmail.com> <56F12E55.2040202@web.de> <56F13078.7080509@web.de> Message-ID: <87y49ahg3t.fsf@gmail.com> Hi Olumide, I didn't mean quip... If that offended you, I apologize. But if you learn to find the answer out yourself, it will be more efficient, since you don't need to wait for others... For your question, a single query with 'haskell do' as keyword should be enough. On Tue, Mar 22 2016 at 19:46:00 +0800, Olumide wrote: > Can I also add that this sort of elitist, unhelpful quip of a > pseudo-answer is the reason that I've largely avoided asking Haskell > beginner questions on stackoverflow. > > Haskell is a wonderful language with a steep learning curve and I > believe that it is the intention of this group grow the user base of > the language by create a place where beginners will not be afraid to > ask questions. And hasty ill-thought, poorly worded answers like > Quanyang's won't help the language get there sooner. > > - Olumide -- Thanks, Quanyang From 50295 at web.de Tue Mar 22 12:20:45 2016 From: 50295 at web.de (Olumide) Date: Tue, 22 Mar 2016 12:20:45 +0000 Subject: [Haskell-beginners] Do IO actions *have* to be glued by the do syntax? In-Reply-To: <87y49ahg3t.fsf@gmail.com> References: <56F123F9.1050805@web.de> <87a8lqixg2.fsf@gmail.com> <56F12E55.2040202@web.de> <56F13078.7080509@web.de> <87y49ahg3t.fsf@gmail.com> Message-ID: <56F1389D.6040900@web.de> Quanyang, Thanks for your apology. I apologize too. I do try to find out answers by myself but was unsuccessful in this case probably because the answer lay in a topic/chapter of the book (Monads) that I am yet to read. (I am reading LYH chapter-by-chapter.) Sometimes our best attempts to find an answer will _fail_ ... and that's why this mailing list exists. We should give each other the benefit of the doubt and assume that someone that's asked a question has made some sort of effort to understand before asking. Regards, - Olumide On 22/03/2016 12:06, Quanyang Liu wrote: > Hi Olumide, > > I didn't mean quip... If that offended you, I apologize. > > But if you learn to find the answer out yourself, it will be more > efficient, since you don't need to wait for others... > > For your question, a single query with 'haskell do' as keyword should be > enough. > > On Tue, Mar 22 2016 at 19:46:00 +0800, Olumide wrote: >> Can I also add that this sort of elitist, unhelpful quip of a >> pseudo-answer is the reason that I've largely avoided asking Haskell >> beginner questions on stackoverflow. >> >> Haskell is a wonderful language with a steep learning curve and I >> believe that it is the intention of this group grow the user base of >> the language by create a place where beginners will not be afraid to >> ask questions. And hasty ill-thought, poorly worded answers like >> Quanyang's won't help the language get there sooner. >> >> - Olumide > From andrew.bernard at gmail.com Tue Mar 22 12:40:44 2016 From: andrew.bernard at gmail.com (Andrew Bernard) Date: Tue, 22 Mar 2016 23:40:44 +1100 Subject: [Haskell-beginners] Do IO actions *have* to be glued by the do syntax? In-Reply-To: References: <56F123F9.1050805@web.de> <87a8lqixg2.fsf@gmail.com> <56F12E55.2040202@web.de> Message-ID: Hello Sumit, What is the Leavenworth guide? Googling for ?leavenworth guide haskell? provides no hint at all. Well, it does give a lot of travel guides! Andrew On 22/03/2016, 22:46, "Beginners on behalf of Sumit Sahrawat, Maths & Computing, IIT (BHU)" wrote: Also, if you haven't, search for the Leavenworth guide. It takes this very question in one of the miscellaneous discussions. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Tue Mar 22 14:02:57 2016 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 22 Mar 2016 19:32:57 +0530 Subject: [Haskell-beginners] Do IO actions *have* to be glued by the do syntax? In-Reply-To: References: <56F123F9.1050805@web.de> <87a8lqixg2.fsf@gmail.com> <56F12E55.2040202@web.de> Message-ID: Is talking about the learnhaskell guide. The autocorrect showed its magic there :) It's a huge brr Chris Allen, who's currently writing a huge book about Haskell. Regards, Sumit -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Tue Mar 22 14:04:35 2016 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 22 Mar 2016 19:34:35 +0530 Subject: [Haskell-beginners] Do IO actions *have* to be glued by the do syntax? In-Reply-To: References: <56F123F9.1050805@web.de> <87a8lqixg2.fsf@gmail.com> <56F12E55.2040202@web.de> Message-ID: Again, I meant 'guide by'. On 22-Mar-2016 7:32 pm, "Sumit Sahrawat, Maths & Computing, IIT (BHU)" < sumit.sahrawat.apm13 at iitbhu.ac.in> wrote: > Is talking about the learnhaskell guide. The autocorrect showed its magic > there :) > > It's a huge brr Chris Allen, who's currently writing a huge book about > Haskell. > > Regards, > Sumit > -------------- next part -------------- An HTML attachment was scrubbed... URL: From frederic-emmanuel.picca at synchrotron-soleil.fr Tue Mar 22 16:34:30 2016 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Tue, 22 Mar 2016 16:34:30 +0000 Subject: [Haskell-beginners] haskell + python numpy In-Reply-To: <874mc2lgc7.fsf@chladni.i-did-not-set--mail-host-address--so-tickle-me> References: , <874mc2lgc7.fsf@chladni.i-did-not-set--mail-host-address--so-tickle-me> Message-ID: Hello, thanks for the pointer, I will see if one of these package can be usefull for me :) Cheers Frederic From frederic-emmanuel.picca at synchrotron-soleil.fr Tue Mar 22 16:37:04 2016 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Tue, 22 Mar 2016 16:37:04 +0000 Subject: [Haskell-beginners] pipe and IO Message-ID: Hello, Still playing with the Pipe module here the code I try to write getDataFrameHkl3D' :: DataFrameHkl3DH5SixsUhv -> Int -> IO DataFrameHkl3D getDataFrameHkl3D' d i = do positions <- get_position (h5mu d) i return $ DataFrameHkl3D { df_n = i , df_image = positions } getDataFrameHkl3D :: DataFrameHkl3DH5SixsUhv -> Producer DataFrameHkl3D IO () getDataFrameHkl3D d = do n <- lift $ hkl_h5_len (h5mu d) forM_ [0..n] $ \i -> yield $ getDataFrameHkl3D' d i but when I compile it I get this error message src/hkl3d.hs:274:3: Couldn't match type `IO DataFrameHkl3D' with `DataFrameHkl3D' Expected type: Proxy X () () DataFrameHkl3D IO () Actual type: Proxy X () () (IO DataFrameHkl3D) IO () In a stmt of a 'do' block: forM_ [0 .. n] $ \ i -> yield $ getDataFrameHkl3D' d i In the expression: do { n <- lift $ hkl_h5_len (h5mu d); forM_ [0 .. n] $ \ i -> yield $ getDataFrameHkl3D' d i } In an equation for `getDataFrameHkl3D': getDataFrameHkl3D d = do { n <- lift $ hkl_h5_len (h5mu d); forM_ [0 .. n] $ \ i -> yield $ getDataFrameHkl3D' d i } I do not know how to fix my code... Frederic From toad3k at gmail.com Tue Mar 22 17:08:53 2016 From: toad3k at gmail.com (David McBride) Date: Tue, 22 Mar 2016 13:08:53 -0400 Subject: [Haskell-beginners] pipe and IO In-Reply-To: References: Message-ID: Yield in your producer is of type DataFrameHkI3D -> Producer DataFrameHkl3D IO () But you are putting an (IO DataFrameHkI3D) in as an argument. You should be able to do something like this: getDataFrameHkl3D :: DataFrameHkl3DH5SixsUhv -> Producer DataFrameHkl3D IO () getDataFrameHkl3D d = do n <- lift $ hkl_h5_len (h5mu d) frames <- forM [0..n] $ \i -> lift (getDataFrameHkl3D' d i) -- :: Producer DataFrameHkl3D IO [DataFrameHkl3D] forM_ frames yield I have a feeling it may be more efficient to yield immediately on each loop as such: getDataFrameHkl3D :: DataFrameHkl3DH5SixsUhv -> Producer DataFrameHkl3D IO () getDataFrameHkl3D d = do n <- lift $ hkl_h5_len (h5mu d) forM_ [0..n] (\i -> lift (getDataFrameHkl3D' d i) >>= yield) You may also substitutde liftIO for lift, if you wish. On Tue, Mar 22, 2016 at 12:37 PM, PICCA Frederic-Emmanuel < frederic-emmanuel.picca at synchrotron-soleil.fr> wrote: > Hello, > > Still playing with the Pipe module > > here the code I try to write > > getDataFrameHkl3D' :: DataFrameHkl3DH5SixsUhv -> Int -> IO DataFrameHkl3D > getDataFrameHkl3D' d i = do > positions <- get_position (h5mu d) i > return $ DataFrameHkl3D { df_n = i > , df_image = positions > } > > getDataFrameHkl3D :: DataFrameHkl3DH5SixsUhv -> Producer DataFrameHkl3D IO > () > getDataFrameHkl3D d = do > n <- lift $ hkl_h5_len (h5mu d) > forM_ [0..n] $ \i -> yield $ getDataFrameHkl3D' d i > > > but when I compile it I get this error message > > src/hkl3d.hs:274:3: > Couldn't match type `IO DataFrameHkl3D' with `DataFrameHkl3D' > Expected type: Proxy X () () DataFrameHkl3D IO () > Actual type: Proxy X () () (IO DataFrameHkl3D) IO () > In a stmt of a 'do' block: > forM_ [0 .. n] $ \ i -> yield $ getDataFrameHkl3D' d i > In the expression: > do { n <- lift $ hkl_h5_len (h5mu d); > forM_ [0 .. n] $ \ i -> yield $ getDataFrameHkl3D' d i } > In an equation for `getDataFrameHkl3D': > getDataFrameHkl3D d > = do { n <- lift $ hkl_h5_len (h5mu d); > forM_ [0 .. n] $ \ i -> yield $ getDataFrameHkl3D' d i } > > I do not know how to fix my code... > > Frederic > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From frederic-emmanuel.picca at synchrotron-soleil.fr Tue Mar 22 17:12:22 2016 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Tue, 22 Mar 2016 17:12:22 +0000 Subject: [Haskell-beginners] pipe and IO In-Reply-To: References: , Message-ID: > getDataFrameHkl3D :: DataFrameHkl3DH5SixsUhv -> Producer DataFrameHkl3D IO () > getDataFrameHkl3D d = do > n <- lift $ hkl_h5_len (h5mu d) > forM_ [0..n] (\i -> lift (getDataFrameHkl3D' d i) >>= yield) Yes I prefer this one because the getDataFrameHkl3D' will take plenty of memory (big images) thanks a lot Frederic From newhoggy at gmail.com Tue Mar 22 23:03:10 2016 From: newhoggy at gmail.com (John Ky) Date: Tue, 22 Mar 2016 23:03:10 +0000 Subject: [Haskell-beginners] How to call popCnt64#? In-Reply-To: References: Message-ID: Hi Marcin, That explanation helps. Thanks! -John On Tue, 22 Mar 2016 at 18:25 Marcin Mrotek wrote: > Hi, > > In general, the problem is that GHCi is attempting to call `show` on the > results of expressions you type in, but `show` (like any other polymorphic > function; though you can look into "levity polymorphism" if you want to > know more) can only accept values of types of kind * (boxed, lifted) - so > it can print Word, but not Word#. > > If you wanted to stay in GHCi, you can do it like: > > Prelude> import GHC.Prim > Prelude GHC.Prim> import GHC.Types > Prelude GHC.Prim GHC.Types> :set -XMagicHash > Prelude GHC.Prim GHC.Types> :t W# > W# :: Word# -> Word > Prelude GHC.Prim GHC.Types> :t popCnt64# > popCnt64# :: Word# -> Word# > Prelude GHC.Prim GHC.Types> let foo = (1 :: Word) > Prelude GHC.Prim GHC.Types> :set -XBangPatterns > Prelude GHC.Prim GHC.Types> let !(W# w) = foo in W# (popCnt64# w) > 1 > > Best regards, > Marcin Mrotek > _______________________________________________ > 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 newhoggy at gmail.com Tue Mar 22 23:10:09 2016 From: newhoggy at gmail.com (John Ky) Date: Tue, 22 Mar 2016 23:10:09 +0000 Subject: [Haskell-beginners] let x = x in x (GHC.Prim) Message-ID: Hello Haskellers, I'm trying to write a faster popCount function for x86 systems. I tried cloning the ghc-prim package and repurposing it for my own needs, but it isn't working as hoped. In particular, popCnt64# was implemented in GHC.Prim as: popCnt64# = let x = x in x Which shouldn't terminate. Yet when I call it, it magically finds the C implementation in hs_popcnt64 and returns the correct value. My cloned project doesn't behave that way. Instead it doesn't terminate as I would expect. Anyone know what's happening here, if there is a way to make this work or tell me if I'm going about this completely the wrong way? Cheers, -John -------------- next part -------------- An HTML attachment was scrubbed... URL: From rahulmutt at gmail.com Wed Mar 23 01:07:13 2016 From: rahulmutt at gmail.com (rahulmutt at gmail.com) Date: Wed, 23 Mar 2016 06:37:13 +0530 Subject: [Haskell-beginners] let x = x in x (GHC.Prim) In-Reply-To: References: Message-ID: <20160323010713.5902417.30655.15037@gmail.com> An HTML attachment was scrubbed... URL: From sylvain at haskus.fr Wed Mar 23 01:10:21 2016 From: sylvain at haskus.fr (Sylvain Henry) Date: Wed, 23 Mar 2016 02:10:21 +0100 Subject: [Haskell-beginners] let x = x in x (GHC.Prim) In-Reply-To: <20160323010713.5902417.30655.15037@gmail.com> References: <20160323010713.5902417.30655.15037@gmail.com> Message-ID: <56F1ECFD.50403@haskus.fr> Hi, You can also test your primop with a foreign primop. See here for an example of assembly code (calling cpuid): https://github.com/hsyl20/ViperVM/blob/master/src/lib/ViperVM/Arch/X86_64/cpuid.c And here for the Haskell part with the foreign primop that calls the assembly code: https://github.com/hsyl20/ViperVM/blob/master/src/lib/ViperVM/Arch/X86_64/Cpuid.hs#L56 Cheers, Sylvain On 23/03/2016 02:07, rahulmutt at gmail.com wrote: > Hi John, > > ghc-prim is just a stub package generated for the purpose of > documentation. All primops are defined in a low level language called > Cmm in GHC. If you want to make it even faster, you'll need to learn > Cmm and update the definition in GHC. If you want to a specialized > implementation for x86 systems, you may need to modify the NCG (Native > Code Generator) which requires a knowledge of assembly language. > > Hope that helps! > Rahul Muttineni > > Sent from my BlackBerry 10 smartphone. > *From: *John Ky > *Sent: *Wednesday 23 March 2016 4:40 AM > *To: *The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > *Reply To: *The Haskell-Beginners Mailing List - Discussion of > primarily beginner-level topics related to Haskell > *Subject: *[Haskell-beginners] let x = x in x (GHC.Prim) > > > Hello Haskellers, > > I'm trying to write a faster popCount function for x86 systems. > > I tried cloning the ghc-prim package and repurposing it for my own > needs, but it isn't working as hoped. > > In particular, popCnt64# was implemented in GHC.Prim as: > > popCnt64# = let x = x in x > > Which shouldn't terminate. Yet when I call it, it magically finds the > C implementation in hs_popcnt64 and returns the correct value. > > My cloned project doesn't behave that way. Instead it doesn't > terminate as I would expect. > > Anyone know what's happening here, if there is a way to make this work > or tell me if I'm going about this completely the wrong way? > > 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: From jungkkr at gmail.com Wed Mar 23 05:19:23 2016 From: jungkkr at gmail.com (Jung Kim) Date: Wed, 23 Mar 2016 13:19:23 +0800 Subject: [Haskell-beginners] the flag -N2 requires the program to be built with -threaded Message-ID: I am currently reading an article[1] where the author uses Haskell to explain her idea. The problem is I don't understand Haskell and am not familiar with Haskell concept like MVar, IVar, etc. (I can get the code compile, and have several years programming experiences.) When testing the code, it throws the error messages "the flag -N2 requires the program to be built with -threaded"; however I can't find thread related flag with ghc command by `ghc --help`. How can I fix this problem? Environment I use: Debian stretch/sid, kernel 4.0.0-2-rt-686-pae, GHC version 7.10.3. The code is exactly the same as described in the section 'Nondeterminism with MVars' of article; and the makefile content is all: ghc -O mvar.hs ghc -o mvar mvar.o run: ./execute # while true; do ./mvar +RTS -N2; done clean: rm mvar Thanks [1]. http://composition.al/blog/2013/09/22/some-example-mvar-ivar-and-lvar-programs-in-haskell/ From sumit.sahrawat.apm13 at iitbhu.ac.in Wed Mar 23 06:25:25 2016 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Wed, 23 Mar 2016 11:55:25 +0530 Subject: [Haskell-beginners] the flag -N2 requires the program to be built with -threaded In-Reply-To: References: Message-ID: As there are a lot of options, ghc has a `--show-options` flag which shows them all. The `-threaded` flag is to be passed to ghc. I think the second command in the `all` block is redundant, as `ghc -O mvar.hs` should produce a binary named mvar. This should work: all: ghc -O -threaded mvar.hs Regards, Sumit On 23 March 2016 at 10:49, Jung Kim wrote: > I am currently reading an article[1] where the author uses Haskell to > explain her idea. The problem is I don't understand Haskell and am not > familiar with Haskell concept like MVar, IVar, etc. (I can get the > code compile, and have several years programming experiences.) > > When testing the code, it throws the error messages "the flag -N2 > requires the program to be built with -threaded"; however I can't find > thread related flag with ghc command by `ghc --help`. How can I fix > this problem? > > Environment I use: Debian stretch/sid, kernel 4.0.0-2-rt-686-pae, GHC > version 7.10.3. > > The code is exactly the same as described in the section > 'Nondeterminism with MVars' of article; and the makefile content is > > all: > ghc -O mvar.hs > ghc -o mvar mvar.o > run: > ./execute # while true; do ./mvar +RTS -N2; done > clean: > rm mvar > > Thanks > > [1]. > http://composition.al/blog/2013/09/22/some-example-mvar-ivar-and-lvar-programs-in-haskell/ > _______________________________________________ > 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 jungkkr at gmail.com Wed Mar 23 12:34:41 2016 From: jungkkr at gmail.com (Jung Kim) Date: Wed, 23 Mar 2016 20:34:41 +0800 Subject: [Haskell-beginners] the flag -N2 requires the program to be built with -threaded In-Reply-To: References: Message-ID: I changed to the suggested solution and that fixes the problem. Thank you very much! On 23 March 2016 at 14:25, Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: > As there are a lot of options, ghc has a `--show-options` flag which shows > them all. The `-threaded` flag is to be passed to ghc. > I think the second command in the `all` block is redundant, as `ghc -O > mvar.hs` should produce a binary named mvar. > > This should work: > > all: > ghc -O -threaded mvar.hs > > Regards, > Sumit > > On 23 March 2016 at 10:49, Jung Kim wrote: >> >> I am currently reading an article[1] where the author uses Haskell to >> explain her idea. The problem is I don't understand Haskell and am not >> familiar with Haskell concept like MVar, IVar, etc. (I can get the >> code compile, and have several years programming experiences.) >> >> When testing the code, it throws the error messages "the flag -N2 >> requires the program to be built with -threaded"; however I can't find >> thread related flag with ghc command by `ghc --help`. How can I fix >> this problem? >> >> Environment I use: Debian stretch/sid, kernel 4.0.0-2-rt-686-pae, GHC >> version 7.10.3. >> >> The code is exactly the same as described in the section >> 'Nondeterminism with MVars' of article; and the makefile content is >> >> all: >> ghc -O mvar.hs >> ghc -o mvar mvar.o >> run: >> ./execute # while true; do ./mvar +RTS -N2; done >> clean: >> rm mvar >> >> Thanks >> >> [1]. >> http://composition.al/blog/2013/09/22/some-example-mvar-ivar-and-lvar-programs-in-haskell/ >> _______________________________________________ >> 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 takenobu.hs at gmail.com Wed Mar 23 14:20:09 2016 From: takenobu.hs at gmail.com (Takenobu Tani) Date: Wed, 23 Mar 2016 23:20:09 +0900 Subject: [Haskell-beginners] let x = x in x (GHC.Prim) In-Reply-To: <56F1ECFD.50403@haskus.fr> References: <20160323010713.5902417.30655.15037@gmail.com> <56F1ECFD.50403@haskus.fr> Message-ID: Hi John, > popCnt64# = let x = x in x It represents "bottom, or undefined, or infinite loop" [1]. (Almost primitives can't be represented with Haskell language.) In your case, It's good to use FFI call [2] like as Sylvain's nice code. If you dig GHC compiler's primitives, followings [3][4] may be useful. [1] https://www.fpcomplete.com/blog/2015/02/primitive-haskell [2] https://downloads.haskell.org/~ghc/master/users-guide/ffi-chap.html#primitive-imports [3] https://ghc.haskell.org/trac/ghc/wiki/Commentary/PrimOps [4] http://www.well-typed.com/blog/2014/06/understanding-the-realworld/ Cheers, Takenobu 2016-03-23 10:10 GMT+09:00 Sylvain Henry : > Hi, > > You can also test your primop with a foreign primop. > > See here for an example of assembly code (calling cpuid): > > https://github.com/hsyl20/ViperVM/blob/master/src/lib/ViperVM/Arch/X86_64/cpuid.c > > And here for the Haskell part with the foreign primop that calls the > assembly code: > > https://github.com/hsyl20/ViperVM/blob/master/src/lib/ViperVM/Arch/X86_64/Cpuid.hs#L56 > > Cheers, > Sylvain > > > On 23/03/2016 02:07, rahulmutt at gmail.com wrote: > > Hi John, > > ghc-prim is just a stub package generated for the purpose of > documentation. All primops are defined in a low level language called Cmm > in GHC. If you want to make it even faster, you'll need to learn Cmm and > update the definition in GHC. If you want to a specialized implementation > for x86 systems, you may need to modify the NCG (Native Code Generator) > which requires a knowledge of assembly language. > > Hope that helps! > Rahul Muttineni > > Sent from my BlackBerry 10 smartphone. > *From: *John Ky > *Sent: *Wednesday 23 March 2016 4:40 AM > *To: *The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > *Reply To: *The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > *Subject: *[Haskell-beginners] let x = x in x (GHC.Prim) > > Hello Haskellers, > > I'm trying to write a faster popCount function for x86 systems. > > I tried cloning the ghc-prim package and repurposing it for my own needs, > but it isn't working as hoped. > > In particular, popCnt64# was implemented in GHC.Prim as: > > popCnt64# = let x = x in x > > Which shouldn't terminate. Yet when I call it, it magically finds the C > implementation in hs_popcnt64 and returns the correct value. > > My cloned project doesn't behave that way. Instead it doesn't terminate > as I would expect. > > Anyone know what's happening here, if there is a way to make this work or > tell me if I'm going about this completely the wrong way? > > Cheers, > > -John > > > > > _______________________________________________ > 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 newhoggy at gmail.com Wed Mar 23 21:28:23 2016 From: newhoggy at gmail.com (John Ky) Date: Wed, 23 Mar 2016 21:28:23 +0000 Subject: [Haskell-beginners] let x = x in x (GHC.Prim) In-Reply-To: <20160323010713.5902417.30655.15037@gmail.com> References: <20160323010713.5902417.30655.15037@gmail.com> Message-ID: Hi Rahul, I see mention of the popcount instruction in nativeGen/X86/CodeGen.hs. In particular it looks like it only activates if sse4_2 is activated? Maybe all I need to do is activate this somehow? Cheers, -John On Wed, 23 Mar 2016 at 12:07 wrote: > Hi John, > > ghc-prim is just a stub package generated for the purpose of > documentation. All primops are defined in a low level language called Cmm > in GHC. If you want to make it even faster, you'll need to learn Cmm and > update the definition in GHC. If you want to a specialized implementation > for x86 systems, you may need to modify the NCG (Native Code Generator) > which requires a knowledge of assembly language. > > Hope that helps! > Rahul Muttineni > > Sent from my BlackBerry 10 smartphone. > *From: *John Ky > *Sent: *Wednesday 23 March 2016 4:40 AM > *To: *The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > *Reply To: *The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > *Subject: *[Haskell-beginners] let x = x in x (GHC.Prim) > > Hello Haskellers, > > I'm trying to write a faster popCount function for x86 systems. > > I tried cloning the ghc-prim package and repurposing it for my own needs, > but it isn't working as hoped. > > In particular, popCnt64# was implemented in GHC.Prim as: > > popCnt64# = let x = x in x > > Which shouldn't terminate. Yet when I call it, it magically finds the C > implementation in hs_popcnt64 and returns the correct value. > > My cloned project doesn't behave that way. Instead it doesn't terminate > as I would expect. > > Anyone know what's happening here, if there is a way to make this work or > tell me if I'm going about this completely the wrong way? > > 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: From newhoggy at gmail.com Wed Mar 23 21:36:58 2016 From: newhoggy at gmail.com (John Ky) Date: Wed, 23 Mar 2016 21:36:58 +0000 Subject: [Haskell-beginners] let x = x in x (GHC.Prim) In-Reply-To: References: <20160323010713.5902417.30655.15037@gmail.com> Message-ID: Hi Rahul, The reason I thought that maybe GHC didn't call the CPU instruction was due to my benchmarking, which showed that the built-in popCount was slower than the pure Haskell Broadword implementation: main = defaultMain [ env setupEnv (\bv -> bgroup "Rank" [ bench "PopCnt1 Broadword - Once" (nf (map (\n -> getCount (PC1BW.popCount1 (DVS.take n bv)))) [0, 1000..100000]) , bench "PopCnt1 GHC - Once" (nf (map (\n -> getCount (PC1GHC.popCount1 (DVS.take n bv)))) [0, 1000..100000]) ] ) ] Benchmarking results follow: benchmarking Rank/PopCnt1 Broadword - Once time 18.49 ms (17.89 ms .. 19.08 ms) 0.994 R? (0.989 R? .. 0.998 R?) mean 19.62 ms (19.22 ms .. 20.04 ms) std dev 1.026 ms (846.2 ?s .. 1.315 ms) variance introduced by outliers: 21% (moderately inflated) benchmarking Rank/PopCnt1 GHC - Once time 36.80 ms (36.25 ms .. 37.57 ms) 0.998 R? (0.996 R? .. 1.000 R?) mean 37.14 ms (36.72 ms .. 37.97 ms) std dev 1.100 ms (650.6 ?s .. 1.680 ms) This makes the built-in nearly two times slower than the pure Haskell. That's how I got into the ghc-prim code. This is the broadword implementation I was using: popCount1 x0 = ((x3 * 0x0101010101010101) .>. 56) where x1 = x0 - ((x0 .&. 0xaaaaaaaaaaaaaaaa) .>. 1) x2 = (x1 .&. 0x3333333333333333) + ((x1 .>. 2) .&. 0x3333333333333333) x3 = (x2 + (x2 .>. 4)) .&. 0x0f0f0f0f0f0f0f0f Maybe all I need to do is compile with some flags or switch the backend or something? Any ideas? Cheers, -John On Thu, 24 Mar 2016 at 08:28 John Ky wrote: > Hi Rahul, > > I see mention of the popcount instruction in nativeGen/X86/CodeGen.hs. In > particular it looks like it only activates if sse4_2 is activated? Maybe > all I need to do is activate this somehow? > > Cheers, > > -John > > On Wed, 23 Mar 2016 at 12:07 wrote: > >> Hi John, >> >> ghc-prim is just a stub package generated for the purpose of >> documentation. All primops are defined in a low level language called Cmm >> in GHC. If you want to make it even faster, you'll need to learn Cmm and >> update the definition in GHC. If you want to a specialized implementation >> for x86 systems, you may need to modify the NCG (Native Code Generator) >> which requires a knowledge of assembly language. >> >> Hope that helps! >> Rahul Muttineni >> >> Sent from my BlackBerry 10 smartphone. >> *From: *John Ky >> *Sent: *Wednesday 23 March 2016 4:40 AM >> *To: *The Haskell-Beginners Mailing List - Discussion of primarily >> beginner-level topics related to Haskell >> *Reply To: *The Haskell-Beginners Mailing List - Discussion of primarily >> beginner-level topics related to Haskell >> *Subject: *[Haskell-beginners] let x = x in x (GHC.Prim) >> >> Hello Haskellers, >> >> I'm trying to write a faster popCount function for x86 systems. >> >> I tried cloning the ghc-prim package and repurposing it for my own needs, >> but it isn't working as hoped. >> >> In particular, popCnt64# was implemented in GHC.Prim as: >> >> popCnt64# = let x = x in x >> >> Which shouldn't terminate. Yet when I call it, it magically finds the C >> implementation in hs_popcnt64 and returns the correct value. >> >> My cloned project doesn't behave that way. Instead it doesn't terminate >> as I would expect. >> >> Anyone know what's happening here, if there is a way to make this work or >> tell me if I'm going about this completely the wrong way? >> >> 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: From newhoggy at gmail.com Wed Mar 23 21:41:06 2016 From: newhoggy at gmail.com (John Ky) Date: Wed, 23 Mar 2016 21:41:06 +0000 Subject: [Haskell-beginners] let x = x in x (GHC.Prim) In-Reply-To: References: <20160323010713.5902417.30655.15037@gmail.com> Message-ID: OMG. Yes! I just needed to add the -msse4.2 flag to GHC: benchmarking Rank/PopCnt1 Broadword - Once time 18.45 ms (18.25 ms .. 18.67 ms) 0.999 R? (0.997 R? .. 0.999 R?) mean 18.19 ms (17.99 ms .. 18.38 ms) std dev 508.6 ?s (398.6 ?s .. 623.8 ?s) benchmarking Rank/PopCnt1 GHC - Once time 11.82 ms (11.65 ms .. 11.97 ms) 0.999 R? (0.998 R? .. 0.999 R?) mean 11.85 ms (11.74 ms .. 11.96 ms) std dev 283.5 ?s (229.6 ?s .. 362.8 ?s) Thanks so much for your help! Cheers, -John On Thu, 24 Mar 2016 at 08:36 John Ky wrote: > Hi Rahul, > > The reason I thought that maybe GHC didn't call the CPU instruction was > due to my benchmarking, which showed that the built-in popCount was slower > than the pure Haskell Broadword implementation: > > main = defaultMain > [ env setupEnv (\bv -> bgroup "Rank" > [ bench "PopCnt1 Broadword - Once" (nf (map (\n -> getCount > (PC1BW.popCount1 (DVS.take n bv)))) [0, 1000..100000]) > , bench "PopCnt1 GHC - Once" (nf (map (\n -> getCount > (PC1GHC.popCount1 (DVS.take n bv)))) [0, 1000..100000]) > ] ) > ] > > Benchmarking results follow: > > benchmarking Rank/PopCnt1 Broadword - Once > time 18.49 ms (17.89 ms .. 19.08 ms) > 0.994 R? (0.989 R? .. 0.998 R?) > mean 19.62 ms (19.22 ms .. 20.04 ms) > std dev 1.026 ms (846.2 ?s .. 1.315 ms) > variance introduced by outliers: 21% (moderately inflated) > > benchmarking Rank/PopCnt1 GHC - Once > time 36.80 ms (36.25 ms .. 37.57 ms) > 0.998 R? (0.996 R? .. 1.000 R?) > mean 37.14 ms (36.72 ms .. 37.97 ms) > std dev 1.100 ms (650.6 ?s .. 1.680 ms) > > This makes the built-in nearly two times slower than the pure Haskell. > That's how I got into the ghc-prim code. > > This is the broadword implementation I was using: > > popCount1 x0 = ((x3 * 0x0101010101010101) .>. 56) > where > x1 = x0 - ((x0 .&. 0xaaaaaaaaaaaaaaaa) .>. 1) > x2 = (x1 .&. 0x3333333333333333) + ((x1 .>. 2) .&. > 0x3333333333333333) > x3 = (x2 + (x2 .>. 4)) .&. 0x0f0f0f0f0f0f0f0f > > Maybe all I need to do is compile with some flags or switch the backend or > something? Any ideas? > > Cheers, > > -John > > > On Thu, 24 Mar 2016 at 08:28 John Ky wrote: > >> Hi Rahul, >> >> I see mention of the popcount instruction in nativeGen/X86/CodeGen.hs. >> In particular it looks like it only activates if sse4_2 is activated? >> Maybe all I need to do is activate this somehow? >> >> Cheers, >> >> -John >> >> On Wed, 23 Mar 2016 at 12:07 wrote: >> >>> Hi John, >>> >>> ghc-prim is just a stub package generated for the purpose of >>> documentation. All primops are defined in a low level language called Cmm >>> in GHC. If you want to make it even faster, you'll need to learn Cmm and >>> update the definition in GHC. If you want to a specialized implementation >>> for x86 systems, you may need to modify the NCG (Native Code Generator) >>> which requires a knowledge of assembly language. >>> >>> Hope that helps! >>> Rahul Muttineni >>> >>> Sent from my BlackBerry 10 smartphone. >>> *From: *John Ky >>> *Sent: *Wednesday 23 March 2016 4:40 AM >>> *To: *The Haskell-Beginners Mailing List - Discussion of primarily >>> beginner-level topics related to Haskell >>> *Reply To: *The Haskell-Beginners Mailing List - Discussion of >>> primarily beginner-level topics related to Haskell >>> *Subject: *[Haskell-beginners] let x = x in x (GHC.Prim) >>> >>> Hello Haskellers, >>> >>> I'm trying to write a faster popCount function for x86 systems. >>> >>> I tried cloning the ghc-prim package and repurposing it for my own >>> needs, but it isn't working as hoped. >>> >>> In particular, popCnt64# was implemented in GHC.Prim as: >>> >>> popCnt64# = let x = x in x >>> >>> Which shouldn't terminate. Yet when I call it, it magically finds the C >>> implementation in hs_popcnt64 and returns the correct value. >>> >>> My cloned project doesn't behave that way. Instead it doesn't terminate >>> as I would expect. >>> >>> Anyone know what's happening here, if there is a way to make this work >>> or tell me if I'm going about this completely the wrong way? >>> >>> 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: From frederic-emmanuel.picca at synchrotron-soleil.fr Sat Mar 26 18:59:38 2016 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Sat, 26 Mar 2016 18:59:38 +0000 Subject: [Haskell-beginners] bracket or how to release ressources. Message-ID: Hello, I try to write a sort of withxxx method whcih release a file withH5File :: FilePath -> (HId_t -> IO r) -> IO r withH5File name = bracket (withCString name acquire) h5f_close where acquire file = h5f_open file h5f_ACC_RDONLY h5p_DEFAULT In my case h5f_open return a HId_t value (HId_t Int) If something went wrong the returned value is negativ. In that case I do not need to h5f_close the file but instead return an error My question is how should I write the bracket part when the finaliser (h5f_close) depends on the result of the acquire part. thanks for your help Frederic From rein.henrichs at gmail.com Sat Mar 26 19:40:18 2016 From: rein.henrichs at gmail.com (Rein Henrichs) Date: Sat, 26 Mar 2016 19:40:18 +0000 Subject: [Haskell-beginners] bracket or how to release ressources. In-Reply-To: References: Message-ID: If your finalization step depends on the result of your action, bracket is not an appropriate choice. It is for resources that are known at the time they are acquired. On Sat, Mar 26, 2016 at 11:59 AM PICCA Frederic-Emmanuel < frederic-emmanuel.picca at synchrotron-soleil.fr> wrote: > Hello, I try to write a sort of withxxx method whcih release a file > > withH5File :: FilePath -> (HId_t -> IO r) -> IO r > withH5File name = bracket (withCString name acquire) h5f_close > where > acquire file = h5f_open file h5f_ACC_RDONLY h5p_DEFAULT > > In my case h5f_open return a HId_t value (HId_t Int) > If something went wrong the returned value is negativ. > In that case I do not need to h5f_close the file but instead return an > error > > My question is how should I write the bracket part when the finaliser > (h5f_close) depends on the result of the acquire part. > > thanks for your help > > Frederic > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From frederic-emmanuel.picca at synchrotron-soleil.fr Sun Mar 27 07:33:27 2016 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Sun, 27 Mar 2016 07:33:27 +0000 Subject: [Haskell-beginners] bracket or how to release ressources. In-Reply-To: References: , Message-ID: Looking at the haskellforall I found something which should be interesting in my case A type dedicated to this sort of problem. the Resource Monad. I will investigate :) thanks Frederic [1] http://www.haskellforall.com/2013/06/the-resource-applicative.html From frederic-emmanuel.picca at synchrotron-soleil.fr Tue Mar 29 16:45:59 2016 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Tue, 29 Mar 2016 16:45:59 +0000 Subject: [Haskell-beginners] bracket or how to release ressources. In-Reply-To: References: , , Message-ID: Hello, I end up with this sort of code using Maybe. withDataspace :: HId_t -> (Maybe HId_t -> IO r) -> IO r withDataspace hid f = bracket acquire release f where acquire = do space_id@(HId_t status) <- h5d_get_space hid return $ if status < 0 then Nothing else (Just space_id) release (Just shid) = h5s_close shid release Nothing = return (HErr_t (-1)) From sgf.dma at gmail.com Wed Mar 30 08:53:40 2016 From: sgf.dma at gmail.com (Dmitriy Matrosov) Date: Wed, 30 Mar 2016 11:53:40 +0300 Subject: [Haskell-beginners] Type constraints of type family arguments Message-ID: > {-# LANGUAGE DataKinds, KindSignatures, PolyKinds, TypeFamilies, GADTs, StandaloneDeriving #-} Hi. I've tried to implement type-level list myself (as an exercise, not looking into existing libraries): Here are two variants of singletons: > data SList1 :: [*] -> * where > SNil1 :: SList1 '[] > SCons1 :: a -> SList1 t -> SList1 ('(:) a t) > > data SList2 (a :: *) (t :: [*]) :: * where > SNil2 :: SList2 a '[] > SCons2 :: a -> SList2 a t -> SList2 a ('(:) a t) > deriving instance Show a => Show (SList2 a b) and `map` for type lists: > type family MapF (b :: r) (t :: [k]) :: [r] where > MapF b '[] = '[] > MapF b ('(:) a t) = ('(:) b (MapF b t)) Then i can write `map` on second singleton variant: > mapF2 :: (a -> b) -> SList2 a t -> SList2 b (MapF b t) > mapF2 f SNil2 = SNil2 > mapF2 f (SCons2 x xs) = SCons2 (f x) (mapF2 f xs) but it does not type-check on first: mapF1 :: (a -> b) -> SList1 t -> SList1 (MapF b t) mapF1 f SNil1 = SNil1 mapF1 f (SCons1 x xs) = SCons1 (f x) (mapF1 f xs) because (as i understand) ghc can't deduce from type-signature, that list element type `a` should match type `a` of first map function's argument: Could not deduce (a1 ~ a) from the context (t ~ (a1 : t1)) bound by a pattern with constructor SCons1 :: forall a (t :: [*]). a -> SList1 t -> SList1 (a : t), in an equation for ?mapF1? at 1.lhs:37:12-22 ?a1? is a rigid type variable bound by a pattern with constructor SCons1 :: forall a (t :: [*]). a -> SList1 t -> SList1 (a : t), in an equation for ?mapF1? at 1.lhs:37:12 ?a? is a rigid type variable bound by the type signature for mapF1 :: (a -> b) -> SList1 t -> SList1 (MapF b t) at 1.lhs:35:12 Relevant bindings include x :: a1 (bound at 1.lhs:37:19) f :: a -> b (bound at 1.lhs:37:9) mapF1 :: (a -> b) -> SList1 t -> SList1 (MapF b t) (bound at 1.lhs:36:3) In the first argument of ?f?, namely ?x? In the first argument of ?SCons1?, namely ?(f x)? Then i try to bind these types using different type family definition: > type family MapF' (a :: k) (b :: r) (t :: [k]) :: [r] where > MapF' a b '[] = '[] > MapF' a b ('(:) a t) = ('(:) b (MapF' a b t)) but ghc still can't deduce type equality: mapF1' :: (a -> b) -> SList1 t -> SList1 (MapF' a b t) mapF1' f SNil1 = SNil1 mapF1' f (SCons1 x xs) = SCons1 (f x) (mapF1' f xs) Could not deduce (a1 ~ a) from the context (t ~ (a1 : t1)) bound by a pattern with constructor SCons1 :: forall a (t :: [*]). a -> SList1 t -> SList1 (a : t), in an equation for ?mapF1'? at 1.lhs:72:13-23 ?a1? is a rigid type variable bound by a pattern with constructor SCons1 :: forall a (t :: [*]). a -> SList1 t -> SList1 (a : t), in an equation for ?mapF1'? at 1.lhs:72:13 ?a? is a rigid type variable bound by the type signature for mapF1' :: (a -> b) -> SList1 t -> SList1 (MapF' a b t) at 1.lhs:70:13 Relevant bindings include x :: a1 (bound at 1.lhs:72:20) f :: a -> b (bound at 1.lhs:72:10) mapF1' :: (a -> b) -> SList1 t -> SList1 (MapF' a b t) (bound at 1.lhs:71:3) In the first argument of ?f?, namely ?x? In the first argument of ?SCons1?, namely ?(f x)? And i noticed that `MapF'` type family does not enforce constraint on list element type: *Main> :t undefined :: SList1 (MapF' Int Char ('(:) Int '[])) undefined :: SList1 (MapF' Int Char ('(:) Int '[])) :: SList1 '[Char] but this should (shouldn't it?) be an error *Main> :t undefined :: SList1 (MapF' Float Char ('(:) Int '[])) undefined :: SList1 (MapF' Float Char ('(:) Int '[])) :: SList1 (MapF' Float Char '[Int]) only constraint on its kind: *Main> :t undefined :: SList1 (MapF' ('Just Int) Char ('(:) Int '[])) The third argument of ?MapF'? should have kind ?[Maybe *]?, but ?(:) Int '[]? has kind ?[*]? In an expression type signature: SList1 (MapF' (Just Int) Char ((:) Int '[])) In the expression: undefined :: SList1 (MapF' (Just Int) Char ((:) Int '[])) Is there a way to restrict list element type to match the type of first MapF' type family's argument? And is there a way to write `map` on SList1? -------------- next part -------------- An HTML attachment was scrubbed... URL: