From voldermort at hotmail.com Tue Sep 2 07:27:25 2014 From: voldermort at hotmail.com (Jeremy) Date: Tue, 2 Sep 2014 07:27:25 +0000 (UTC) Subject: [Haskell-beginners] Stackage latest snapshot Message-ID: I would like to point my cabal file to the latest Stackage snapshot. I seem to recall that there is a link which will automatically resolve to this, but I can no longer find it. Does this link still exist? Is there a good reason for not doing so? I understand that this will introduce a little instability, but I'm OK dealing with that in return for not getting stuck on the same package versions forever. From jcb at iteris.com Tue Sep 2 18:19:23 2014 From: jcb at iteris.com (Jeff C. Britton) Date: Tue, 2 Sep 2014 18:19:23 +0000 Subject: [Haskell-beginners] Haskeline and forkIO In-Reply-To: <87ppfkbt6k.fsf@pmade.com> References: <4129696F7B970B4FA7C343A1587763E711B479A3@greyhound.iteris.com> <4129696F7B970B4FA7C343A1587763E711B47C7E@greyhound.iteris.com> <87ppfkbt6k.fsf@pmade.com> Message-ID: <4129696F7B970B4FA7C343A1587763E711B47EAF@greyhound.iteris.com> Thanks Peter, That suggestion works. I will have to continue learning more about Monads. --Jeff -----Original Message----- From: Beginners [mailto:beginners-bounces at haskell.org] On Behalf Of Peter Jones Sent: Thursday, August 28, 2014 7:11 AM To: beginners at haskell.org Subject: Re: [Haskell-beginners] Haskeline and forkIO "Jeff C. Britton" writes: > loop :: InputT IO () > loop = do > maybeLine <- getInputLine "Enter a file to compress> " > case maybeLine of > Nothing -> return () -- user entered EOF > Just "" -> return () -- treat no name as "want to quit" > Just path -> do > return (runWorker path) > loop The other issue you're having is because `runWorker path` is an `IO ()` value but at the point where you use it in the code the type system wants an `InputT IO ()`. To try to satisfy the type system you used `return` to build a `InputT IO (IO ())` value, but that doesn't actually work (as you've noticed). Since `InputT` is a transformer you have an extra layer to work through and so need to *lift* your `IO ()` value into the `InputT IO` layer. Try this: -- Add this import import Control.Monad.IO.Class loop :: InputT IO () loop = do maybeLine <- getInputLine "Enter a file to compress> " case maybeLine of Nothing -> return () -- user entered EOF Just "" -> return () -- treat no name as "want to quit" Just path -> do liftIO (runWorker path) loop You can think of `liftIO` as having this signature (in this context): liftIO :: IO () -> InputT IO () -- Peter Jones, Founder, Devalot.com Defending the honor of good code _______________________________________________ Beginners mailing list Beginners at haskell.org http://www.haskell.org/mailman/listinfo/beginners From sgf.dma at gmail.com Tue Sep 2 19:32:35 2014 From: sgf.dma at gmail.com (Dmitriy Matrosov) Date: Tue, 02 Sep 2014 23:32:35 +0400 Subject: [Haskell-beginners] Check constructor's field numeric value at compile time Message-ID: <54061B53.7060106@gmail.com> Hi. I have a type data Interval = Seconds Float | MicroSeconds Int The Float field of data constructor Seconds should be >= 1, and Int field of constructor MicroSeconds should be in the range from 0 to 1000000. How can i write this constraints so they're checked at compile time, not at runtime? -- Dmitriy Matrosov From alexandrelucchesi at gmail.com Tue Sep 2 20:58:24 2014 From: alexandrelucchesi at gmail.com (Alexandre Lucchesi) Date: Tue, 2 Sep 2014 17:58:24 -0300 Subject: [Haskell-beginners] Check constructor's field numeric value at compile time In-Reply-To: <54061B53.7060106@gmail.com> References: <54061B53.7060106@gmail.com> Message-ID: You can't do that within the data type declaration. In order to add such constraints you should define "constructor functions" and apply the validation there, i.e.: newSecondsInterval :: Float -> Maybe Interval newSecondsInterval n | n >= 1 = Just $ Seconds n | otherwise = Nothing Note that the "Maybe" type is only a way to handle the case where the supplied value is invalid. Also, in order to provide encapsulation and ensure no one is going to create a new "Interval" by using "Seconds" and "MicroSeconds", you should hide these value constructors in the export list of your module. On Tue, Sep 2, 2014 at 4:32 PM, Dmitriy Matrosov wrote: > Hi. > > I have a type > > data Interval = Seconds Float > | MicroSeconds Int > > The Float field of data constructor Seconds should be >= 1, and Int field > of constructor MicroSeconds should be in the range from 0 to 1000000. > > How can i write this constraints so they're checked at compile time, not > at runtime? > > -- > Dmitriy Matrosov > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -- alexandre lucchesi *Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away!* -------------- next part -------------- An HTML attachment was scrubbed... URL: From julian.birch at gmail.com Tue Sep 2 22:02:48 2014 From: julian.birch at gmail.com (Julian Birch) Date: Tue, 2 Sep 2014 23:02:48 +0100 Subject: [Haskell-beginners] Check constructor's field numeric value at compile time In-Reply-To: References: <54061B53.7060106@gmail.com> Message-ID: Also, if you want your mind blown, check out Idris. On Tuesday, September 2, 2014, Alexandre Lucchesi < alexandrelucchesi at gmail.com> wrote: > You can't do that within the data type declaration. > > In order to add such constraints you should define "constructor functions" > and apply the validation there, i.e.: > > newSecondsInterval :: Float -> Maybe Interval > newSecondsInterval n > | n >= 1 = Just $ Seconds n > | otherwise = Nothing > > Note that the "Maybe" type is only a way to handle the case where the > supplied value is invalid. Also, in order to provide encapsulation and > ensure no one is going to create a new "Interval" by using "Seconds" and > "MicroSeconds", you should hide these value constructors in the export list > of your module. > > > On Tue, Sep 2, 2014 at 4:32 PM, Dmitriy Matrosov > wrote: > >> Hi. >> >> I have a type >> >> data Interval = Seconds Float >> | MicroSeconds Int >> >> The Float field of data constructor Seconds should be >= 1, and Int field >> of constructor MicroSeconds should be in the range from 0 to 1000000. >> >> How can i write this constraints so they're checked at compile time, not >> at runtime? >> >> -- >> Dmitriy Matrosov >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> >> http://www.haskell.org/mailman/listinfo/beginners >> > > > > -- > alexandre lucchesi > > *Perfection is achieved, not when there is nothing more to add, but when > there is nothing left to take away!* > -- Sent from an iPhone, please excuse brevity and typos. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Wed Sep 3 03:04:10 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Wed, 3 Sep 2014 10:04:10 +0700 Subject: [Haskell-beginners] Check constructor's field numeric value at compile time In-Reply-To: References: <54061B53.7060106@gmail.com> Message-ID: On Wed, Sep 3, 2014 at 3:58 AM, Alexandre Lucchesi < alexandrelucchesi at gmail.com> wrote: > In order to add such constraints you should define "constructor functions" > and apply the validation there, i.e.: To OP: Yes, the searchable term is "smart constructors". However, it has been used at least once on this list to mean something different, so look out. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexandrelucchesi at gmail.com Wed Sep 3 03:07:10 2014 From: alexandrelucchesi at gmail.com (Alexandre Lucchesi) Date: Wed, 3 Sep 2014 00:07:10 -0300 Subject: [Haskell-beginners] Check constructor's field numeric value at compile time In-Reply-To: References: <54061B53.7060106@gmail.com> Message-ID: Hmm.. Nice to know about that! Thank you. :) On Wed, Sep 3, 2014 at 12:04 AM, Kim-Ee Yeoh wrote: > > On Wed, Sep 3, 2014 at 3:58 AM, Alexandre Lucchesi < > alexandrelucchesi at gmail.com> wrote: > >> In order to add such constraints you should define "constructor >> functions" and apply the validation there, i.e.: > > > To OP: Yes, the searchable term is "smart constructors". However, it has > been used at least once on this list to mean something different, so look > out. > > -- Kim-Ee > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -- alexandre lucchesi *Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away!* -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Wed Sep 3 03:07:31 2014 From: allbery.b at gmail.com (Brandon Allbery) Date: Tue, 2 Sep 2014 23:07:31 -0400 Subject: [Haskell-beginners] Check constructor's field numeric value at compile time In-Reply-To: References: <54061B53.7060106@gmail.com> Message-ID: On Tue, Sep 2, 2014 at 11:04 PM, Kim-Ee Yeoh wrote: > > On Wed, Sep 3, 2014 at 3:58 AM, Alexandre Lucchesi < > alexandrelucchesi at gmail.com> wrote: > >> In order to add such constraints you should define "constructor >> functions" and apply the validation there, i.e.: > > > To OP: Yes, the searchable term is "smart constructors". However, it has > been used at least once on this list to mean something different, so look > out. > Also note that this will not actually check at compile time; to do that you need type level stuff that ghc is still finding its way through. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Wed Sep 3 03:07:53 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Wed, 3 Sep 2014 10:07:53 +0700 Subject: [Haskell-beginners] Check constructor's field numeric value at compile time In-Reply-To: <54061B53.7060106@gmail.com> References: <54061B53.7060106@gmail.com> Message-ID: On Wed, Sep 3, 2014 at 2:32 AM, Dmitriy Matrosov wrote: > How can i write this constraints so they're checked at compile time, not > at runtime? Smart constructors won't check them at compile time but it does the next best thing, which is validate at the earliest possible moment. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael at snoyman.com Wed Sep 3 04:50:09 2014 From: michael at snoyman.com (Michael Snoyman) Date: Wed, 3 Sep 2014 07:50:09 +0300 Subject: [Haskell-beginners] Stackage latest snapshot In-Reply-To: References: Message-ID: On Tue, Sep 2, 2014 at 10:27 AM, Jeremy wrote: > I would like to point my cabal file to the latest Stackage snapshot. I seem > to recall that there is a link which will automatically resolve to this, > but > I can no longer find it. > > Does this link still exist? Is there a good reason for not doing so? I > understand that this will introduce a little instability, but I'm OK > dealing > with that in return for not getting stuck on the same package versions > forever. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > The preparing your system for Stackage page[1] has those auto-updated links available (e.g., GHC 7.8 exclusive is [2]). You already identified the downside with this: you may magically be upgraded to a new version of a package. If you really want to do this, you can, but my recommendation is to manually decide to upgrade your Stackage snapshot consciously instead of letter an arbitrary Jenkins build server make the decision for you. Michael [1] https://github.com/fpco/stackage/wiki/Preparing-your-system-to-use-Stackage [2] http://www.stackage.org/alias/fpcomplete/unstable-ghc78-exclusive -------------- next part -------------- An HTML attachment was scrubbed... URL: From voldermort at hotmail.com Wed Sep 3 07:52:24 2014 From: voldermort at hotmail.com (Peter) Date: Wed, 3 Sep 2014 07:52:24 +0000 (UTC) Subject: [Haskell-beginners] Stackage latest snapshot References: Message-ID: Michael Snoyman snoyman.com> writes: > The preparing your system for Stackage page[1] has those auto-updated links available (e.g., GHC 7.8 exclusive is [2]). Thank you. I read the page at least 3 times, but missed that because the links redirected to the latest snapshot, and the Stackage server only has static snapshot links. Perhaps it should be made clearer that these links will redirect to the current snapshot, and add them to http://www.stackage.org/snapshots as well? > You already identified the downside with this: you may magically be upgraded to a new version of a package. If you really want to do this, you can, but my recommendation is to manually decide to upgrade your Stackage snapshot consciously instead of letter an arbitrary Jenkins build server make the decision for you. I'm using Stackage as a QA'd Hackage. It sounds like you see it more as a server-side cabal freeze. From michael at snoyman.com Wed Sep 3 08:02:55 2014 From: michael at snoyman.com (Michael Snoyman) Date: Wed, 3 Sep 2014 11:02:55 +0300 Subject: [Haskell-beginners] Stackage latest snapshot In-Reply-To: References: Message-ID: On Wed, Sep 3, 2014 at 10:52 AM, Peter wrote: > Michael Snoyman snoyman.com> writes: > > > The preparing your system for Stackage page[1] has those auto-updated > links available (e.g., GHC 7.8 exclusive is [2]). > > Thank you. I read the page at least 3 times, but missed that because the > links redirected to the latest snapshot, and the Stackage server only has > static snapshot links. Perhaps it should be made clearer that these links > will redirect to the current snapshot, and add them to > http://www.stackage.org/snapshots as well? > > That would be a good idea if I wanted people to directly use those URLs, which I think is generally a bad idea. The lack of explicitness about the presence of a redirect there is a feature, not a bug ;). > > You already identified the downside with this: you may magically be > upgraded to a new version of a package. If you really want to do this, you > can, but my recommendation is to manually decide to upgrade your Stackage > snapshot consciously instead of letter an arbitrary Jenkins build server > make the decision for you. > > I'm using Stackage as a QA'd Hackage. It sounds like you see it more as a > server-side cabal freeze. > > I'm not sure what distinction you're going for in this. Imagine the following sequence of events: * You set up your system to use Stackage, with September 1's snapshot being active at the time. * You install foo-1.1, with bar-1.1 depending on it. * A new Stackage snapshot comes out, providing foo-1.2. * You now try to install something depending on foo, and depending on the alignment of the stars, cabal will either download a new foo or use the already installed one. In other words, the usage you seem to be implying is highly non-deterministic, which I'd be very careful about using. Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: From voldermort at hotmail.com Wed Sep 3 08:37:47 2014 From: voldermort at hotmail.com (Peter) Date: Wed, 3 Sep 2014 08:37:47 +0000 (UTC) Subject: [Haskell-beginners] Stackage latest snapshot References: Message-ID: Michael Snoyman snoyman.com> writes: > > You already identified the downside with this: you may magically be > upgraded to a new version of a package. If you really want to do this, you > can, but my recommendation is to manually decide to upgrade your Stackage > snapshot consciously instead of letter an arbitrary Jenkins build server > make the decision for you. > I'm using Stackage as a QA'd Hackage. It sounds like you see it more as a > server-side cabal freeze. > > > I'm not sure what distinction you're going for in this. Imagine the following sequence of events: > > * You set up your system to use Stackage, with September 1's snapshot being active at the time. > > * You install foo-1.1, with bar-1.1 depending on it. > > * A new Stackage snapshot comes out, providing foo-1.2. > > * You now try to install something depending on foo, and depending on the alignment of the stars, cabal will either download a new foo or use the already installed one. > > In other words, the usage you seem to be implying is highly non-deterministic, which I'd be very careful about using. There are 3 levels of stability: 1. Hackage, where any package may fail to compile, even by itself. 2. Stackage latest, where at any one time, all packages will compile together. New packages won't get in until they meet this stability criteria. 3. Stackage snapshot, where all packages will compile together, and never change. All of these have legitimate uses. I prefer developing with 2, to avoid being stuck with the same package versions until I change the snapshot, and I'm prepared to fix up the example you gave manually if need be. I guess it's similar to the difference between yum, which automatically updates the package list on a fairly frequent basis, and apt-get, which requires an explicit update. I personally prefer yum's approach (as do Red Hat / Fedora), but I haven't seen any Debian folks calling to change apt. From kc1956 at gmail.com Wed Sep 3 13:01:18 2014 From: kc1956 at gmail.com (KC) Date: Wed, 3 Sep 2014 06:01:18 -0700 Subject: [Haskell-beginners] Does Haskell work on Free BSD? Message-ID: Does Haskell work on Free BSD? If not which is the better Linux to use? -- -- Sent from an expensive device which will be obsolete in a few months! :D Casey -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Wed Sep 3 13:12:01 2014 From: mwm at mired.org (Mike Meyer) Date: Wed, 3 Sep 2014 08:12:01 -0500 Subject: [Haskell-beginners] Does Haskell work on Free BSD? In-Reply-To: References: Message-ID: Haskell works fine on FreeBSD. Both ghc and hugs are available from the package system. Or you can install the Haskell Platform (hs-haskell-platform) from it. There are also a variety of Haskell software packages for development as well as end users. On Wed, Sep 3, 2014 at 8:01 AM, KC wrote: > Does Haskell work on Free BSD? > > If not which is the better Linux to use? > > -- > > -- > > Sent from an expensive device which will be obsolete in a few months! :D > Casey > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mlists at pmade.com Wed Sep 3 16:24:55 2014 From: mlists at pmade.com (Peter Jones) Date: Wed, 03 Sep 2014 10:24:55 -0600 Subject: [Haskell-beginners] Haskeline and forkIO References: <4129696F7B970B4FA7C343A1587763E711B479A3@greyhound.iteris.com> <4129696F7B970B4FA7C343A1587763E711B47C7E@greyhound.iteris.com> <87ppfkbt6k.fsf@pmade.com> <4129696F7B970B4FA7C343A1587763E711B47EAF@greyhound.iteris.com> Message-ID: <87egvs7ju0.fsf@pmade.com> "Jeff C. Britton" writes: > That suggestion works. > I will have to continue learning more about Monads. I should have also mentioned that if you enable GHC warnings it should tell you that having the `return` before `loop` is discarding the value given to it. > -----Original Message----- > From: Beginners [mailto:beginners-bounces at haskell.org] > Sent: Thursday, August 28, 2014 7:11 AM > To: beginners at haskell.org > Subject: Re: [Haskell-beginners] Haskeline and forkIO > > "Jeff C. Britton" writes: >> loop :: InputT IO () >> loop = do >> maybeLine <- getInputLine "Enter a file to compress> " >> case maybeLine of >> Nothing -> return () -- user entered EOF >> Just "" -> return () -- treat no name as "want to quit" >> Just path -> do >> return (runWorker path) >> loop > > The other issue you're having is because `runWorker path` is an `IO > ()` value but at the point where you use it in the code the type > system wants an `InputT IO ()`. To try to satisfy the type system you > used `return` to build a `InputT IO (IO ())` value, but that doesn't > actually work (as you've noticed). Since `InputT` is a transformer > you have an extra layer to work through and so need to *lift* your `IO > ()` value into the `InputT IO` layer. Try this: > > -- Add this import > import Control.Monad.IO.Class > > loop :: InputT IO () > loop = do > maybeLine <- getInputLine "Enter a file to compress> " > case maybeLine of > Nothing -> return () -- user entered EOF > Just "" -> return () -- treat no name as "want to quit" > Just path -> do > liftIO (runWorker path) > loop > > > You can think of `liftIO` as having this signature (in this context): > > liftIO :: IO () -> InputT IO () -- Peter Jones, Founder, Devalot.com Defending the honor of good code From neeraj2608 at gmail.com Wed Sep 3 16:51:50 2014 From: neeraj2608 at gmail.com (Neeraj Rao) Date: Wed, 3 Sep 2014 12:51:50 -0400 Subject: [Haskell-beginners] Haskeline and forkIO In-Reply-To: <87egvs7ju0.fsf@pmade.com> References: <4129696F7B970B4FA7C343A1587763E711B479A3@greyhound.iteris.com> <4129696F7B970B4FA7C343A1587763E711B47C7E@greyhound.iteris.com> <87ppfkbt6k.fsf@pmade.com> <4129696F7B970B4FA7C343A1587763E711B47EAF@greyhound.iteris.com> <87egvs7ju0.fsf@pmade.com> Message-ID: As a Haskell beginner, I would also like to recommend HLint as a very useful tool to catch these kinds of things. On Sep 3, 2014 12:25 PM, "Peter Jones" wrote: > "Jeff C. Britton" writes: > > That suggestion works. > > I will have to continue learning more about Monads. > > I should have also mentioned that if you enable GHC warnings it should > tell you that having the `return` before `loop` is discarding the value > given to it. > > > -----Original Message----- > > From: Beginners [mailto:beginners-bounces at haskell.org] > > Sent: Thursday, August 28, 2014 7:11 AM > > To: beginners at haskell.org > > Subject: Re: [Haskell-beginners] Haskeline and forkIO > > > > "Jeff C. Britton" writes: > >> loop :: InputT IO () > >> loop = do > >> maybeLine <- getInputLine "Enter a file to compress> " > >> case maybeLine of > >> Nothing -> return () -- user entered EOF > >> Just "" -> return () -- treat no name as "want to quit" > >> Just path -> do > >> return (runWorker path) > >> loop > > > > The other issue you're having is because `runWorker path` is an `IO > > ()` value but at the point where you use it in the code the type > > system wants an `InputT IO ()`. To try to satisfy the type system you > > used `return` to build a `InputT IO (IO ())` value, but that doesn't > > actually work (as you've noticed). Since `InputT` is a transformer > > you have an extra layer to work through and so need to *lift* your `IO > > ()` value into the `InputT IO` layer. Try this: > > > > -- Add this import > > import Control.Monad.IO.Class > > > > loop :: InputT IO () > > loop = do > > maybeLine <- getInputLine "Enter a file to compress> " > > case maybeLine of > > Nothing -> return () -- user entered EOF > > Just "" -> return () -- treat no name as "want to quit" > > Just path -> do > > liftIO (runWorker path) > > loop > > > > > > You can think of `liftIO` as having this signature (in this context): > > > > liftIO :: IO () -> InputT IO () > > -- > Peter Jones, Founder, Devalot.com > Defending the honor of good code > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Sun Sep 7 12:14:22 2014 From: martin.drautzburg at web.de (martin) Date: Sun, 07 Sep 2014 14:14:22 +0200 Subject: [Haskell-beginners] Continuations vs. Values Message-ID: <540C4C1E.1010204@web.de> Hello all, in the continuation monad, I can turn a value into a Cont by means of return. Conversely I can convert a Cont into a value by passing id as the continuation. This dualism of Cont and plain values is well known. The bind operator kind of(!) takes a value a and produces a new value b. This is all wrapped in Cont stuff, so the result of bind is not really a plain a, but a Cont which takes a function from b -> r. But this is just the same dualism as above. Most Cont examples I've seen could much more easily be implemented with just values or calling functions on values. Then again there is "a poor man's concurrency" which I don't get at all. In between there is a huge gap of (my) understanding. Can someone help me cross this gap? There must be certain things I can do with Conts which I cannot do easily with values and functions. From johnw at newartisans.com Sun Sep 7 12:57:09 2014 From: johnw at newartisans.com (John Wiegley) Date: Sun, 07 Sep 2014 14:57:09 +0200 Subject: [Haskell-beginners] Continuations vs. Values In-Reply-To: <540C4C1E.1010204@web.de> (martin's message of "Sun, 07 Sep 2014 14:14:22 +0200") References: <540C4C1E.1010204@web.de> Message-ID: >>>>> martin writes: > Can someone help me cross this gap? There must be certain things I can do > with Conts which I cannot do easily with values and functions. Any function can be turned into a function accepting a continuation: f :: a -> b f_cont :: a -> (b -> c) -> c The Cont construction abstracts this pattern into its own type: f_Cont :: a -> Cont c b The advantage is that we now have a Functor instance over 'b', rather than over 'c' (for Functor (->) applied to f_cont). I cover Cont is more detail here, with a reference to green threading at the very bottom: https://www.fpcomplete.com/user/jwiegley/understanding-continuations John From dav.vire+haskell at gmail.com Mon Sep 8 14:31:54 2014 From: dav.vire+haskell at gmail.com (David Virebayre) Date: Mon, 8 Sep 2014 16:31:54 +0200 Subject: [Haskell-beginners] Check constructor's field numeric value at compile time In-Reply-To: References: <54061B53.7060106@gmail.com> Message-ID: 2014-09-03 5:07 GMT+02:00 Kim-Ee Yeoh : > > On Wed, Sep 3, 2014 at 2:32 AM, Dmitriy Matrosov > wrote: > >> How can i write this constraints so they're checked at compile time, not >> at runtime? > > > Smart constructors won't check them at compile time but it does the next > best thing, which is validate at the earliest possible moment. > In between compile time and runtime, you probably could use refinements types; see LiquidHaskell (http://goto.ucsd.edu:8090/index.html, https://github.com/ucsd-progsys/liquidhaskell/ ) David. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rdesfo at zoho.com Mon Sep 8 18:03:49 2014 From: rdesfo at zoho.com (ryan) Date: Mon, 08 Sep 2014 14:03:49 -0400 Subject: [Haskell-beginners] hpc doctest Message-ID: <540DEF85.4040407@zoho.com> Hello, Are there any known issues with doctest and hpc? Cabal test runs correctly, but hpc doesn't seem to see anything. I have tried to make some of the test fail on purpose so see it hpc would pick it up, since there is additional output from cabal test when there is a failure, but it doesn't help. -- -- test file -- module Doctests where import Test.DocTest main :: IO () main = doctest ["-isrc", "src/Ch1.hs"] -- -- command line -- $ cabal test Building DiscreteMathematicsUsingAComputer-0.1.0.0... Preprocessing library DiscreteMathematicsUsingAComputer-0.1.0.0... In-place registering DiscreteMathematicsUsingAComputer-0.1.0.0... Preprocessing test suite 'doctests' for DiscreteMathematicsUsingAComputer-0.1.0.0... Warning: output was redirected with -o, but no output will be generated because there is no Main module. Running 1 test suites... Test suite doctests: RUNNING... Test suite doctests: PASS Test suite logged to: dist/test/DiscreteMathematicsUsingAComputer-0.1.0.0-doctests.log Writing: hpc_index.html Writing: hpc_index_fun.html Writing: hpc_index_alt.html Writing: hpc_index_exp.html Test coverage report written to dist/hpc/html/doctests/hpc_index.html 1 of 1 test suites (1 of 1 test cases) passed. Writing: hpc_index.html Writing: hpc_index_fun.html Writing: hpc_index_alt.html Writing: hpc_index_exp.html Package coverage report written to dist/hpc/html/DiscreteMathematicsUsingAComputer-0.1.0.0/hpc_index.html Ryan From gale at sefer.org Tue Sep 9 18:53:56 2014 From: gale at sefer.org (Yitzchak Gale) Date: Tue, 9 Sep 2014 21:53:56 +0300 Subject: [Haskell-beginners] [Haskell-cafe] 2014 haskell cabal update hangs on mac In-Reply-To: <1397DF7E-BDB9-46F8-B7D8-4887681F91C2@dc.uba.ar> References: <59D8EF48-B854-407B-A067-C87DCDF1C9B7@gmail.com> <1397DF7E-BDB9-46F8-B7D8-4887681F91C2@dc.uba.ar> Message-ID: Daniel Gor?n wrote: > I had the same problem. It turned out to be that for some unknown reason I ended up with: > > /Library/Haskell/ghc-7.8.3-x86_64/bin/cabal -> cabal.wrap > /Library/Haskell/ghc-7.8.3-x86_64/bin/cabal.real -> cabal.wrap > /Library/Haskell/ghc-7.8.3-x86_64/bin/cabal.wrap > > where cabal.wrap is a shell script that checks if a new cabal.config > should be created and then calls? cabal.real. Replacing cabal.real with a binary version of cabal solves it. > > I don?t know why this happened, I suspect that it might occur if you had ghc 7.8.2 already installed... I believe this is a bug in the scripts activate-hs and uninstall-hs provided by the Haskell Platform installer for Mac OS X. I have reported it here: https://github.com/haskell/haskell-platform/issues/147 -Yitz From martin.drautzburg at web.de Wed Sep 10 18:06:26 2014 From: martin.drautzburg at web.de (martin) Date: Wed, 10 Sep 2014 20:06:26 +0200 Subject: [Haskell-beginners] How to add a "method" to a record Message-ID: <54109322.1070901@web.de> Hello all if I have a record like data Foo pl = Foo { label :: String, payload :: pl } how can I create a similar type where I can populate label so it is not a plain string, but a function which operates on payload? Something like label (Foo pl) = show pl From toad3k at gmail.com Wed Sep 10 18:16:02 2014 From: toad3k at gmail.com (David McBride) Date: Wed, 10 Sep 2014 14:16:02 -0400 Subject: [Haskell-beginners] How to add a "method" to a record In-Reply-To: <54109322.1070901@web.de> References: <54109322.1070901@web.de> Message-ID: Is this what you are looking for? data Foo pl = Foo { label :: pl -> String, payload :: pl } On Wed, Sep 10, 2014 at 2:06 PM, martin wrote: > Hello all > > if I have a record like > > data Foo pl = Foo { > label :: String, > payload :: pl > } > > how can I create a similar type where I can populate label so it is not a > plain string, but a function which operates on > payload? Something like > > label (Foo pl) = show pl > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From julian.birch at gmail.com Wed Sep 10 18:30:16 2014 From: julian.birch at gmail.com (Julian Birch) Date: Wed, 10 Sep 2014 19:30:16 +0100 Subject: [Haskell-beginners] How to add a "method" to a record In-Reply-To: References: <54109322.1070901@web.de> Message-ID: Bear in mind you can just create functions at the top level that operate on your data structure. You only need the function to be a member of the record if the function itself changes, which is relatively rare. Say you need a Foo and a Bar, and they both have labels, implemented in different ways, then you can use a typeclass to achieve your goals. On Wednesday, September 10, 2014, David McBride wrote: > Is this what you are looking for? > > data Foo pl = Foo { > label :: pl -> String, > payload :: pl > } > > On Wed, Sep 10, 2014 at 2:06 PM, martin > wrote: > >> Hello all >> >> if I have a record like >> >> data Foo pl = Foo { >> label :: String, >> payload :: pl >> } >> >> how can I create a similar type where I can populate label so it is not a >> plain string, but a function which operates on >> payload? Something like >> >> label (Foo pl) = show pl >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> >> http://www.haskell.org/mailman/listinfo/beginners >> > > -- Sent from an iPhone, please excuse brevity and typos. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cma at bitemyapp.com Wed Sep 10 18:49:56 2014 From: cma at bitemyapp.com (Christopher Allen) Date: Wed, 10 Sep 2014 13:49:56 -0500 Subject: [Haskell-beginners] How to add a "method" to a record In-Reply-To: References: <54109322.1070901@web.de> Message-ID: I'd agree with Julian Birch, except to say that you shouldn't make a typeclass unless overloading is really needed and you can define laws on the behavior thereof. A fairly major (IMO) inconvenience with embedding functions in records that have non-function data they operate on is that you won't have a Show instance. Also, you'll be forced to extract the method and then apply it. In doing so, to make things nicer you'll probably pull out an "extract and apply" function. At that point, you're better off lifting the varying implementations into top-level functions and making a wrapper that decides which runs where based on the *data* in the record. That is, including enough information in the record to decide which function applied. And this is without having broached whether or not you plan to be able to serialize your data or not. On Wed, Sep 10, 2014 at 1:30 PM, Julian Birch wrote: > Bear in mind you can just create functions at the top level that operate > on your data structure. You only need the function to be a member of the > record if the function itself changes, which is relatively rare. > > Say you need a Foo and a Bar, and they both have labels, implemented in > different ways, then you can use a typeclass to achieve your goals. > > > On Wednesday, September 10, 2014, David McBride wrote: > >> Is this what you are looking for? >> >> data Foo pl = Foo { >> label :: pl -> String, >> payload :: pl >> } >> >> On Wed, Sep 10, 2014 at 2:06 PM, martin wrote: >> >>> Hello all >>> >>> if I have a record like >>> >>> data Foo pl = Foo { >>> label :: String, >>> payload :: pl >>> } >>> >>> how can I create a similar type where I can populate label so it is not >>> a plain string, but a function which operates on >>> payload? Something like >>> >>> label (Foo pl) = show pl >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://www.haskell.org/mailman/listinfo/beginners >>> >> >> > > -- > Sent from an iPhone, please excuse brevity and typos. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From corentin.dupont at gmail.com Wed Sep 10 18:50:18 2014 From: corentin.dupont at gmail.com (Corentin Dupont) Date: Wed, 10 Sep 2014 20:50:18 +0200 Subject: [Haskell-beginners] How to add a "method" to a record In-Reply-To: References: <54109322.1070901@web.de> Message-ID: If the field "label" can be deduced from "payload", I recommend not to include it in your structure, because that would be redundant. Here how you could write it: data Foo pl = Foo { payload :: pl} labelInt :: Foo Int -> String labelInt (Foo a) = "Int payload:" ++ (show a) labelString :: Foo String -> String labelString (Foo a) = "String payload" ++ a You are obliged to define two separate label function, because "Foo Int" and "Foo String" are two completly separate types. Alternatively, if you want only one label function, use a type sum and pattern match on it: data T = TS String | TI Int data Foo2 = Foo2 { payload2 :: T} label :: Foo2 -> String label (Foo2 (TI a)) = "Int payload:" ++ (show a) label (Foo2 (TS a)) = "String payload:" ++ a On Wed, Sep 10, 2014 at 8:30 PM, Julian Birch wrote: > Bear in mind you can just create functions at the top level that operate > on your data structure. You only need the function to be a member of the > record if the function itself changes, which is relatively rare. > > Say you need a Foo and a Bar, and they both have labels, implemented in > different ways, then you can use a typeclass to achieve your goals. > > > On Wednesday, September 10, 2014, David McBride wrote: > >> Is this what you are looking for? >> >> data Foo pl = Foo { >> label :: pl -> String, >> payload :: pl >> } >> >> On Wed, Sep 10, 2014 at 2:06 PM, martin wrote: >> >>> Hello all >>> >>> if I have a record like >>> >>> data Foo pl = Foo { >>> label :: String, >>> payload :: pl >>> } >>> >>> how can I create a similar type where I can populate label so it is not >>> a plain string, but a function which operates on >>> payload? Something like >>> >>> label (Foo pl) = show pl >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://www.haskell.org/mailman/listinfo/beginners >>> >> >> > > -- > Sent from an iPhone, please excuse brevity and typos. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Fri Sep 12 17:05:11 2014 From: martin.drautzburg at web.de (martin) Date: Fri, 12 Sep 2014 19:05:11 +0200 Subject: [Haskell-beginners] How to add a "method" to a record In-Reply-To: References: <54109322.1070901@web.de> Message-ID: <541327C7.6040104@web.de> Am 09/10/2014 08:50 PM, schrieb Corentin Dupont: > If the field "label" can be deduced from "payload", I recommend not to include it in your structure, because that would > be redundant. > > Here how you could write it: > > data Foo pl = Foo { payload :: pl} > > labelInt :: Foo Int -> String > labelInt (Foo a) = "Int payload:" ++ (show a) > > labelString :: Foo String -> String > labelString (Foo a) = "String payload" ++ a > > You are obliged to define two separate label function, because "Foo Int" and "Foo String" are two completly separate types. This is exactly my problem: Someone will use this type an define the type of pl. How can I know what type she'll use? What I'd like to express is that whoever creates a concrete type should also provide the proper label function. > > On Wed, Sep 10, 2014 at 2:06 PM, martin wrote: > > Hello all > > if I have a record like > > data Foo pl = Foo { > label :: String, > payload :: pl > } > > how can I create a similar type where I can populate label so it is not a plain string, but a function which > operates on > payload? Something like > > label (Foo pl) = show pl > From jcb at iteris.com Tue Sep 16 02:01:30 2014 From: jcb at iteris.com (Jeff C. Britton) Date: Tue, 16 Sep 2014 02:01:30 +0000 Subject: [Haskell-beginners] ghci and randomRs Message-ID: <4129696F7B970B4FA7C343A1587763E711B564F3@greyhound.iteris.com> I am trying to use randomRs at the ghci prompt like so Prelude System.Random> take 10 $ (randomRs (1, 6) newStdGen) but I get the following error :16:12: Could not deduce (RandomGen (IO StdGen)) arising from a use of `randomRs' from the context (Random a, Num a) bound by the inferred type of it :: (Random a, Num a) => [a] at :16:1-37 In the second argument of `($)', namely `(randomRs (1, 6) newStdGen)' In the expression: take 10 $ (randomRs (1, 6) newStdGen) In an equation for `it': it = take 10 $ (randomRs (1, 6) newStdGen) I have tried a variety of options, like wrapping it in a "do" or adding type annotations. Nothing seems to work. -----Original Message----- From: Beginners [mailto:beginners-bounces at haskell.org] On Behalf Of martin Sent: Friday, September 12, 2014 10:05 AM To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell Subject: Re: [Haskell-beginners] How to add a "method" to a record Am 09/10/2014 08:50 PM, schrieb Corentin Dupont: > If the field "label" can be deduced from "payload", I recommend not to > include it in your structure, because that would be redundant. > > Here how you could write it: > > data Foo pl = Foo { payload :: pl} > > labelInt :: Foo Int -> String > labelInt (Foo a) = "Int payload:" ++ (show a) > > labelString :: Foo String -> String > labelString (Foo a) = "String payload" ++ a > > You are obliged to define two separate label function, because "Foo Int" and "Foo String" are two completly separate types. This is exactly my problem: Someone will use this type an define the type of pl. How can I know what type she'll use? What I'd like to express is that whoever creates a concrete type should also provide the proper label function. > > On Wed, Sep 10, 2014 at 2:06 PM, martin wrote: > > Hello all > > if I have a record like > > data Foo pl = Foo { > label :: String, > payload :: pl > } > > how can I create a similar type where I can populate label so it is not a plain string, but a function which > operates on > payload? Something like > > label (Foo pl) = show pl > _______________________________________________ Beginners mailing list Beginners at haskell.org http://www.haskell.org/mailman/listinfo/beginners From allbery.b at gmail.com Tue Sep 16 02:05:52 2014 From: allbery.b at gmail.com (Brandon Allbery) Date: Mon, 15 Sep 2014 22:05:52 -0400 Subject: [Haskell-beginners] ghci and randomRs In-Reply-To: <4129696F7B970B4FA7C343A1587763E711B564F3@greyhound.iteris.com> References: <4129696F7B970B4FA7C343A1587763E711B564F3@greyhound.iteris.com> Message-ID: On Mon, Sep 15, 2014 at 10:01 PM, Jeff C. Britton wrote: > Prelude System.Random> take 10 $ (randomRs (1, 6) newStdGen) I think you need to read http://www.vex.net/~trebla/haskell/IO.xhtml. You're trying to operate directly on an IO "program" (newStdGen) as if it were a value. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Tue Sep 16 02:27:02 2014 From: toad3k at gmail.com (David McBride) Date: Mon, 15 Sep 2014 22:27:02 -0400 Subject: [Haskell-beginners] ghci and randomRs In-Reply-To: <4129696F7B970B4FA7C343A1587763E711B564F3@greyhound.iteris.com> References: <4129696F7B970B4FA7C343A1587763E711B564F3@greyhound.iteris.com> Message-ID: The simple answer is with do notation: main = do g <- newStdGen print $ randomRs (1,2) g Or without do notation, something like: newStdGen >>= print . take 10 . randomRs (1,2) On Mon, Sep 15, 2014 at 10:01 PM, Jeff C. Britton wrote: > I am trying to use randomRs at the ghci prompt like so > > Prelude System.Random> take 10 $ (randomRs (1, 6) newStdGen) > > but I get the following error > :16:12: > Could not deduce (RandomGen (IO StdGen)) > arising from a use of `randomRs' > from the context (Random a, Num a) > bound by the inferred type of it :: (Random a, Num a) => [a] > at :16:1-37 > In the second argument of `($)', namely > `(randomRs (1, 6) newStdGen)' > In the expression: take 10 $ (randomRs (1, 6) newStdGen) > In an equation for `it': it = take 10 $ (randomRs (1, 6) newStdGen) > > > I have tried a variety of options, like wrapping it in a "do" or adding > type annotations. > Nothing seems to work. > > > > -----Original Message----- > From: Beginners [mailto:beginners-bounces at haskell.org] On Behalf Of martin > Sent: Friday, September 12, 2014 10:05 AM > To: The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > Subject: Re: [Haskell-beginners] How to add a "method" to a record > > Am 09/10/2014 08:50 PM, schrieb Corentin Dupont: > > If the field "label" can be deduced from "payload", I recommend not to > > include it in your structure, because that would be redundant. > > > > Here how you could write it: > > > > data Foo pl = Foo { payload :: pl} > > > > labelInt :: Foo Int -> String > > labelInt (Foo a) = "Int payload:" ++ (show a) > > > > labelString :: Foo String -> String > > labelString (Foo a) = "String payload" ++ a > > > > You are obliged to define two separate label function, because "Foo Int" > and "Foo String" are two completly separate types. > > This is exactly my problem: Someone will use this type an define the type > of pl. How can I know what type she'll use? > What I'd like to express is that whoever creates a concrete type should > also provide the proper label function. > > > > > On Wed, Sep 10, 2014 at 2:06 PM, martin < > martin.drautzburg at web.de> wrote: > > > > Hello all > > > > if I have a record like > > > > data Foo pl = Foo { > > label :: String, > > payload :: pl > > } > > > > how can I create a similar type where I can populate label > so it is not a plain string, but a function which > > operates on > > payload? Something like > > > > label (Foo pl) = show pl > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jcb at iteris.com Tue Sep 16 17:43:04 2014 From: jcb at iteris.com (Jeff C. Britton) Date: Tue, 16 Sep 2014 17:43:04 +0000 Subject: [Haskell-beginners] ghci and randomRs In-Reply-To: References: <4129696F7B970B4FA7C343A1587763E711B564F3@greyhound.iteris.com> Message-ID: <4129696F7B970B4FA7C343A1587763E711B5751B@greyhound.iteris.com> Ok, I got it now. I was misunderstanding how the REPL was interacting with the IO Monad. I had once tried do { g <- newStdGen; take 10 $ randomRs (1,6) g } but I actually needed this do { g <- newStdGen; return . take 10 $ randomRs (1,6) g } Thanks, Jeff From: Beginners [mailto:beginners-bounces at haskell.org] On Behalf Of David McBride Sent: Monday, September 15, 2014 7:27 PM To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell Subject: Re: [Haskell-beginners] ghci and randomRs The simple answer is with do notation: main = do g <- newStdGen print $ randomRs (1,2) g Or without do notation, something like: newStdGen >>= print . take 10 . randomRs (1,2) On Mon, Sep 15, 2014 at 10:01 PM, Jeff C. Britton > wrote: I am trying to use randomRs at the ghci prompt like so Prelude System.Random> take 10 $ (randomRs (1, 6) newStdGen) but I get the following error :16:12: Could not deduce (RandomGen (IO StdGen)) arising from a use of `randomRs' from the context (Random a, Num a) bound by the inferred type of it :: (Random a, Num a) => [a] at :16:1-37 In the second argument of `($)', namely `(randomRs (1, 6) newStdGen)' In the expression: take 10 $ (randomRs (1, 6) newStdGen) In an equation for `it': it = take 10 $ (randomRs (1, 6) newStdGen) I have tried a variety of options, like wrapping it in a "do" or adding type annotations. Nothing seems to work. -----Original Message----- From: Beginners [mailto:beginners-bounces at haskell.org] On Behalf Of martin Sent: Friday, September 12, 2014 10:05 AM To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell Subject: Re: [Haskell-beginners] How to add a "method" to a record Am 09/10/2014 08:50 PM, schrieb Corentin Dupont: > If the field "label" can be deduced from "payload", I recommend not to > include it in your structure, because that would be redundant. > > Here how you could write it: > > data Foo pl = Foo { payload :: pl} > > labelInt :: Foo Int -> String > labelInt (Foo a) = "Int payload:" ++ (show a) > > labelString :: Foo String -> String > labelString (Foo a) = "String payload" ++ a > > You are obliged to define two separate label function, because "Foo Int" and "Foo String" are two completly separate types. This is exactly my problem: Someone will use this type an define the type of pl. How can I know what type she'll use? What I'd like to express is that whoever creates a concrete type should also provide the proper label function. > > On Wed, Sep 10, 2014 at 2:06 PM, martin > wrote: > > Hello all > > if I have a record like > > data Foo pl = Foo { > label :: String, > payload :: pl > } > > how can I create a similar type where I can populate label so it is not a plain string, but a function which > operates on > payload? Something like > > label (Foo pl) = show pl > _______________________________________________ Beginners mailing list Beginners at haskell.org http://www.haskell.org/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://www.haskell.org/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Tue Sep 16 19:05:49 2014 From: fa-ml at ariis.it (Francesco Ariis) Date: Tue, 16 Sep 2014 21:05:49 +0200 Subject: [Haskell-beginners] ghci and randomRs In-Reply-To: <4129696F7B970B4FA7C343A1587763E711B5751B@greyhound.iteris.com> References: <4129696F7B970B4FA7C343A1587763E711B564F3@greyhound.iteris.com> <4129696F7B970B4FA7C343A1587763E711B5751B@greyhound.iteris.com> Message-ID: <20140916190549.GA14803@x60s.casa> On Tue, Sep 16, 2014 at 05:43:04PM +0000, Jeff C. Britton wrote: > Ok, I got it now. I was misunderstanding how the REPL was interacting with the IO Monad. > I had once tried > do { g <- newStdGen; take 10 $ randomRs (1,6) g } > > but I actually needed this > do { g <- newStdGen; return . take 10 $ randomRs (1,6) g } > > Thanks, > Jeff I am sure you have already figured it out, but in case you didn't, this works too: ?> :m +System.Random ?> g <- newStdGen ?> take 10 $ randomRs (1,6) g [3,3,5,1,6,6,3,3,1,6] ?> (and keeps IO actions apart from pure code) From exitconsole at gmail.com Tue Sep 16 21:11:02 2014 From: exitconsole at gmail.com (=?UTF-8?B?RMOhbmllbCBBcmF0w7M=?=) Date: Tue, 16 Sep 2014 23:11:02 +0200 Subject: [Haskell-beginners] What am I reinventing here Message-ID: Hey guys, I was working through 99 Haskell Problems a while back and while refactoring my solution to Problem 9 I couldn't help feeling I was reinventing something basic. My thinking was, this problem can be generalized to letting a function recursively process arbitrary chunks of a given data structure in several passes until the whole data is consumed while some function is extracting some information in an accumulator. So I wrote a mini-typeclass like so: class Exhaustible e where isEmpty :: e -> Bool instance Exhaustible [a] where isEmpty = null exhaust :: Exhaustible e => (e -> (b, e)) -> (a -> b -> a) -> a -> e -> a exhaust f g z xs | isEmpty xs = z | otherwise = let (val, rest) = f xs in exhaust f g (g z val) rest Now the solution to Problem 9 is easy to define in terms of "exhaust". Then I thought, "Why am I treating empty as a special value again?", and wrote this instead: stabilize :: Eq a => (a -> (b, a)) -> (c -> b -> c) -> c -> a -> (c, a) stabilize f g z d | d == d' = (z', d') | otherwise = stabilize f g z' d' where (val, d') = f d z' = g z val This looks both really useful and extremely basic to me, so I'm wondering what the standard way to do the same thing might be. I looked at Foldable + foldr but the idea there seems to be to process a data structure _one_ element at a time. So my question is, is there an official implementation for this combinator I called "stabilize"? Also, any tips on improving the definitions and comments on how situations like Problem 9 should be approached are welcome. Daniel From raabe at froglogic.com Tue Sep 16 22:02:13 2014 From: raabe at froglogic.com (Frerich Raabe) Date: Wed, 17 Sep 2014 00:02:13 +0200 Subject: [Haskell-beginners] What am I reinventing here In-Reply-To: References: Message-ID: <19acfad4798068f14dd0db1eac89ea4b@roundcube.froglogic.com> On 2014-09-16 23:11, D?niel Arat? wrote: Then I thought, "Why am I treating empty as a special value again?", > and wrote this instead: > > stabilize :: Eq a => (a -> (b, a)) -> (c -> b -> c) -> c -> a -> (c, a) > stabilize f g z d > | d == d' = (z', d') > | otherwise = stabilize f g z' d' > where (val, d') = f d > z' = g z val > > This looks both really useful and extremely basic to me, so I'm > wondering what the standard way to do the same thing might be. I think you reinvented the 'unfoldr' function here: unfoldr :: (b -> Maybe (a, b)) -> b -> [a] It applies the given function to the second argument until the function returns Nothing, which correponds to your "d == d'" guard. You could use it to solve Problem 9 like pack :: Eq a => [a] -> [[a]] pack = unfoldr (\xs -> if null xs then Nothing else Just (span (== head xs) xs)) I think this looks like it does two things at once: > I looked at Foldable + foldr but the idea there seems to be to process a > data structure _one_ element at a time. It's true that a fold processes a data structure one element at a time, but you also have access to the accumulator, i.e. you can consider what you processed so far. I think you could solve Problem 9 using a foldr like pack :: Eq a => [a] -> [[a]] pack = foldr go [] where go x acc@(a:as) = if x == head a then (x:a):as else [x]:acc go x _ = [[x]] - Frerich From jcb at iteris.com Tue Sep 16 23:55:16 2014 From: jcb at iteris.com (Jeff C. Britton) Date: Tue, 16 Sep 2014 23:55:16 +0000 Subject: [Haskell-beginners] ghci and randomRs In-Reply-To: <20140916190549.GA14803@x60s.casa> References: <4129696F7B970B4FA7C343A1587763E711B564F3@greyhound.iteris.com> <4129696F7B970B4FA7C343A1587763E711B5751B@greyhound.iteris.com> <20140916190549.GA14803@x60s.casa> Message-ID: <4129696F7B970B4FA7C343A1587763E711B57589@greyhound.iteris.com> Thanks Francesco. This actually helped me. --Jeff -----Original Message----- From: Beginners [mailto:beginners-bounces at haskell.org] On Behalf Of Francesco Ariis Sent: Tuesday, September 16, 2014 12:06 PM To: beginners at haskell.org Subject: Re: [Haskell-beginners] ghci and randomRs On Tue, Sep 16, 2014 at 05:43:04PM +0000, Jeff C. Britton wrote: > Ok, I got it now. I was misunderstanding how the REPL was interacting with the IO Monad. > I had once tried > do { g <- newStdGen; take 10 $ randomRs (1,6) g } > > but I actually needed this > do { g <- newStdGen; return . take 10 $ randomRs (1,6) g } > > Thanks, > Jeff I am sure you have already figured it out, but in case you didn't, this works too: ?> :m +System.Random ?> g <- newStdGen ?> take 10 $ randomRs (1,6) g [3,3,5,1,6,6,3,3,1,6] ?> (and keeps IO actions apart from pure code) _______________________________________________ Beginners mailing list Beginners at haskell.org http://www.haskell.org/mailman/listinfo/beginners From dontdieych at gmail.com Wed Sep 17 09:17:00 2014 From: dontdieych at gmail.com (Dontdie YCH) Date: Wed, 17 Sep 2014 18:17:00 +0900 Subject: [Haskell-beginners] How can I replace content of tag in xml file with haxml. Message-ID: I'm trying to replace `CurrentURI` tag's contents using HaXml. from, ``` 0 AAAAAAAAAAAA ``` to, ``` 0 BBBBBBBBBBBBBB ``` I had look around, hxt, xml-light, and haxml. I found `onContents` function from `Text.XML.HaXml.Wrappers` module and It looks like way to go. ``` ?: xml <- readFile "SetAVTransportURI.xml" :: IO String ?: let doc = xmlParse "dumb" xml ?: doc Document (Prolog (Just (XMLDecl "1.0" Nothing Nothing)) [] Nothing []) [] (Elem (N "s:Envelope") [(N "xmlns:s",http://schemas.xmlsoap.org/soap/envelope/),(N "s:encodingStyle",http://schemas.xmlsoap.org/soap/encoding/)] [CString False "\n " file dumb at line 2 col 125,CElem (Elem (N "s:Body") [] [CString False "\n " file dumb at line 3 col 11,CElem (Elem (N "u:SetAVTransportURI") [(N "xmlns:u",urn:schemas-upnp-org:service:AVTransport:1)] [CString False "\n " file dumb at line 4 col 79,CElem (Elem (N "InstanceID") [] [CString False "0\n " file dumb at line 5 col 19]) file dumb at line 5 col 7,CString False "\n " file dumb at line 6 col 20,CElem (Elem (N "CurrentURI") [] [CString False "\n" file dumb at line 7 col 19,CMisc (Comment " #EXTM3U ") file dumb at line 8 col 1,CMisc (Comment " #EXTINF:5850,\52628\49437\53945\49440\50689\54868 \47609\47329\44284\44053 140909 HDTV x264 720p AC3 \50864\47532\47568 \45433\51020 - nature boy ") file dumb at line 9 col 1,CMisc (Comment " http://192.168.219.2:8200/MediaItems/587.mkv ") file dumb at line 10 col 1,CMisc (Comment " #EXTM3U ") file dumb at line 11 col 1,CMisc (Comment " #EXTINF:6411,The.Adventures.of.Tintin.2011.1080p.BluRay.x264.YIFY ") file dumb at line 12 col 1,CString False "http://192.168.219.2:8200/MediaItems/165.mp4\n " file dumb at line 13 col 1]) file dumb at line 7 col 7,CString False "\n " file dumb at line 14 col 20,CElem (Elem (N "CurrentURIMetaData") [] []) file dumb at line 15 col 7,CString False "\n " file dumb at line 15 col 28]) file dumb at line 4 col 5,CString False "\n " file dumb at line 16 col 27]) file dumb at line 3 col 3,CString False "\n" file dumb at line 17 col 12]) [Comment "\nOrignal header from captured packets.\n\nPOST /smp_18_ HTTP/1.1\nHost: 192.168.219.6:7676\nSOAPAction: \"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\"\nAccept-Language: en-us;q=1, en;q=0.5\nAccept-Encoding: gzip\nContent-Type: text/xml; charset=\"utf-8\"\nUser-Agent: gupnp-av-cp GUPnP/0.20.12 DLNADOC/1.50\nConnection: Keep-Alive\nContent-Length: 1405\n"] ?: onContent (Text.XML.HaXml.Combinators.deep $ tag "CurrentURI") doc -- this result is not what I want. Document (Prolog (Just (XMLDecl "1.0" Nothing Nothing)) [] Nothing []) [] (Elem (N "CurrentURI") [] [CString False "\n" file dumb at line 7 col 19,CMisc (Comment " #EXTM3U ") file dumb at line 8 col 1,CMisc (Comment " #EXTINF:5850,\52628\49437\53945\49440\50689\54868 \47609\47329\44284\44053 140909 HDTV x264 720p AC3 \50864\47532\47568 \45433\51020 - nature boy ") file dumb at line 9 col 1,CMisc (Comment " http://192.168.219.2:8200/MediaItems/587.mkv ") file dumb at line 10 col 1,CMisc (Comment " #EXTM3U ") file dumb at line 11 col 1,CMisc (Comment " #EXTINF:6411,The.Adventures.of.Tintin.2011.1080p.BluRay.x264.YIFY ") file dumb at line 12 col 1,CString False "http://192.168.219.2:8200/MediaItems/165.mp4\n " file dumb at line 13 col 1]) [Comment "\nOrignal header from captured packets.\n\nPOST /smp_18_ HTTP/1.1\nHost: 192.168.219.6:7676\nSOAPAction: \"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\"\nAccept-Language: en-us;q=1, en;q=0.5\nAccept-Encoding: gzip\nContent-Type: text/xml; charset=\"utf-8\"\nUser-Agent: gupnp-av-cp GUPnP/0.20.12 DLNADOC/1.50\nConnection: Keep-Alive\nContent-Length: 1405\n"] ?: ``` How can I write filter to replace `CurrentURI` tag? 1. find 'CurrentURI' tag 2. replace content with some string 3. return modified whole document not just specific tag Or, Where can I found tutorial or example for haxml? Yes, I'm reading now haxml document. But needs some overview document. Any advice would be appreciated. Thanks. From tjarhad at gmail.com Thu Sep 18 22:23:50 2014 From: tjarhad at gmail.com (Tushar Jarhad) Date: Fri, 19 Sep 2014 03:53:50 +0530 Subject: [Haskell-beginners] Parse Json tweets using Aeson Message-ID: {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DeriveGeneric #-} import Data.Aeson import GHC.Generics import qualified Data.ByteString.Lazy as B data Tweet = Tweet { id_str :: String, text :: String }deriving Generic instance FromJSON Tweet main = do input <- B.readFile "1.json" let mm = decode input :: Maybe Tweet case mm of Nothing -> print "error parsing JSON" Just m -> (putStrLn.greet) m greet m = (show.id_str) m This program is fine if 1.json file has 1 tweet if 1.json file has multiple tweets then it fails so how we can parse multiple tweets -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdorman at ironicdesign.com Fri Sep 19 08:40:55 2014 From: mdorman at ironicdesign.com (Michael Alan Dorman) Date: Fri, 19 Sep 2014 04:40:55 -0400 Subject: [Haskell-beginners] Parse Json tweets using Aeson In-Reply-To: (Tushar Jarhad's message of "Fri, 19 Sep 2014 03:53:50 +0530") References: Message-ID: <87oaucuhns.fsf@ironicdesign.com> Tushar Jarhad writes: > let mm = decode input :: Maybe Tweet You have told the program you expect one tweet---anything else is, by definition, an error. The program takes you at your word. So if you want it to parse multiple tweets, tell it that you expect a *list* of tweets. > let mm = decode input :: Maybe [Tweet] Or are you saying that your file simply has multiple tweets appended one after another? If so, that file does not represent a valid JSON structure. I feel sure there's a way to run the parse incrementally---taking a complete data structure at a time---but I don't know it offhand. Mike. From mdorman at ironicdesign.com Fri Sep 19 08:51:24 2014 From: mdorman at ironicdesign.com (Michael Alan Dorman) Date: Fri, 19 Sep 2014 04:51:24 -0400 Subject: [Haskell-beginners] Parse Json tweets using Aeson In-Reply-To: <87oaucuhns.fsf@ironicdesign.com> (Michael Alan Dorman's message of "Fri, 19 Sep 2014 04:40:55 -0400") References: <87oaucuhns.fsf@ironicdesign.com> Message-ID: <87k350uh6b.fsf@ironicdesign.com> Michael Alan Dorman writes: > I feel sure there's a way to run the parse incrementally---taking a > complete data structure at a time---but I don't know it offhand. Since I felt like I *should* know this offhand, I decided to figure it out. It's very easy---Aeson provides an Attoparsec parser, so you can, in fact, do parsing-with-leftovers with virtually zero effort: import Data.Aeson import Data.Attoparsec.ByteString import Data.ByteString var :: ByteString var = "{\"Some\" : \"Text\"}Leftover" main = print $ parse json var This produces a value representing the simple Object, as well as leftovers---so you could, presumably, do a fold to pull out as many JSON items as can be parsed, even if the overall file isn't a valid JSON structure in itself. Mike. From james at jtoll.com Sat Sep 20 01:48:36 2014 From: james at jtoll.com (James Toll) Date: Fri, 19 Sep 2014 20:48:36 -0500 Subject: [Haskell-beginners] Patch source, then pickup compile Message-ID: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> Hi, I?m trying to install Hakyll within a cabal sandbox. The issue I?m running into is that the current version of Pandoc doesn?t build because of this bug: https://github.com/jgm/pandoc/issues/1590 The bug is a simple fix, and is fixed on github, but not in the version on hackage. I?d like to use ?cabal get? to download the source, manually fix the source, then compile. The question I have is how do I pick up the installation process after fixing the source? So far this is what I?ve done: $ mkdir hakyll $ cabal update $ cd hakyll $ cabal sandbox init --sandbox . $ cabal install -j hakyll [this is the spot where pandoc fails to install] $ cabal get pandoc-1.13.1 $ cd pandoc-1.13.1/ [patch the source] At this point I need to resume the compilation and installation process. How do I do that? Do I move back up to the parent directory and then issue the 'cabal install -j hakyll? command again? Thanks, James From allbery.b at gmail.com Sat Sep 20 01:54:29 2014 From: allbery.b at gmail.com (Brandon Allbery) Date: Fri, 19 Sep 2014 21:54:29 -0400 Subject: [Haskell-beginners] Patch source, then pickup compile In-Reply-To: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> References: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> Message-ID: On Fri, Sep 19, 2014 at 9:48 PM, James Toll wrote: > At this point I need to resume the compilation and installation process. > How do I do that? Do I move back up to the parent directory and then issue > the 'cabal install -j hakyll? command again? "cabal install -j" without a package name should install the package in the current directory as it is. Specifying a package name will cause that package to be downloaded from Hackage, which in this case you don't want. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at jtoll.com Sat Sep 20 02:03:26 2014 From: james at jtoll.com (James Toll) Date: Fri, 19 Sep 2014 21:03:26 -0500 Subject: [Haskell-beginners] Patch source, then pickup compile In-Reply-To: References: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> Message-ID: <03C825EB-E697-4F67-A7B5-A054E8A93A56@jtoll.com> On Sep 19, 2014, at 8:54 PM, Brandon Allbery wrote: > On Fri, Sep 19, 2014 at 9:48 PM, James Toll wrote: > At this point I need to resume the compilation and installation process. How do I do that? Do I move back up to the parent directory and then issue the 'cabal install -j hakyll? command again? > > "cabal install -j" without a package name should install the package in the current directory as it is. Specifying a package name will cause that package to be downloaded from Hackage, which in this case you don't want. Thank you for your suggestion. I think you're saying that I should ?cabal install -j? from within the pandoc-1.13.1 directory to build pandoc. But then I will still need to build hakyll, so do I cd up to the hakyll parent directory and cabal install -j from there as well? Thanks, James From allbery.b at gmail.com Sat Sep 20 02:06:13 2014 From: allbery.b at gmail.com (Brandon Allbery) Date: Fri, 19 Sep 2014 22:06:13 -0400 Subject: [Haskell-beginners] Patch source, then pickup compile In-Reply-To: <03C825EB-E697-4F67-A7B5-A054E8A93A56@jtoll.com> References: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> <03C825EB-E697-4F67-A7B5-A054E8A93A56@jtoll.com> Message-ID: On Fri, Sep 19, 2014 at 10:03 PM, James Toll wrote: > Thank you for your suggestion. I think you're saying that I should ?cabal > install -j? from within the pandoc-1.13.1 directory to build pandoc. But > then I will still need to build hakyll, so do I cd up to the hakyll parent > directory and cabal install -j from there as well? Just "cabal install -j hakyll" as usual. It'll see the installed pandoc and, as long as the version is compatible, not reinstall it. It should give you a warning if it's incompatible. In that case, you'll need to ask the hakyll folks and possibly have to install whatever package requires it manually in the same way you are installing pandoc, but in this case you would just be editing the cabal file to fix the version. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at jtoll.com Sat Sep 20 04:01:57 2014 From: james at jtoll.com (James Toll) Date: Fri, 19 Sep 2014 23:01:57 -0500 Subject: [Haskell-beginners] Patch source, then pickup compile In-Reply-To: References: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> <03C825EB-E697-4F67-A7B5-A054E8A93A56@jtoll.com> Message-ID: <383C4CFD-D581-408C-BB03-4EF49C843AEF@jtoll.com> On Sep 19, 2014, at 9:06 PM, Brandon Allbery wrote: > On Fri, Sep 19, 2014 at 10:03 PM, James Toll wrote: > Thank you for your suggestion. I think you're saying that I should ?cabal install -j? from within the pandoc-1.13.1 directory to build pandoc. But then I will still need to build hakyll, so do I cd up to the hakyll parent directory and cabal install -j from there as well? > > Just "cabal install -j hakyll" as usual. It'll see the installed pandoc and, as long as the version is compatible, not reinstall it. It should give you a warning if it's incompatible. In that case, you'll need to ask the hakyll folks and possibly have to install whatever package requires it manually in the same way you are installing pandoc, but in this case you would just be editing the cabal file to fix the version. Unfortunately this isn?t working. The pandoc build appears to work with the patched source, but then the hakyll build fails. If I?m reading this properly, it appears that pandoc is not getting installed in the sandbox. Then it appears that hakyll is not finding the successful pandoc build (probably because it wasn?t installed to the sandbox) and is trying to build pandoc again, using un-patched code and failing with the same original error. Here is the output, truncated a bit during the pandoc build. Any suggestions on how to fix this? Thanks. James [james ~/src/haskell/sandboxes/hakyll]$ cd pandoc-1.13.1/ [james ~/src/haskell/sandboxes/hakyll/pandoc-1.13.1]$ cabal install -j Resolving dependencies... In order, the following will be installed: pandoc-1.13.1 -network-uri (reinstall) Warning: Note that reinstalls are always dangerous. Continuing anyway... Configuring pandoc-1.13.1... Building pandoc-1.13.1... Installed pandoc-1.13.1 Updating documentation index /Users/james/Library/Haskell/share/doc/index.html [james ~/src/haskell/sandboxes/hakyll/pandoc-1.13.1]$ cd .. [james ~/src/haskell/sandboxes/hakyll]$ cabal install -j hakyll Resolving dependencies... Notice: installing into a sandbox located at /Users/james/src/haskell/sandboxes/hakyll Configuring pandoc-1.13.1... Building pandoc-1.13.1... Failed to install pandoc-1.13.1 Build log ( /Users/james/src/haskell/sandboxes/hakyll/logs/pandoc-1.13.1.log ): [1 of 1] Compiling Main ( /var/folders/jl/h90f3bxs7hxb389cvjdc6k5w0000gn/T/pandoc-1.13.1-84931/pandoc-1.13.1/dist/dist-sandbox-8fe59d82/setup/setup.hs, /var/folders/jl/h90f3bxs7hxb389cvjdc6k5w0000gn/T/pandoc-1.13.1-84931/pandoc-1.13.1/dist/dist-sandbox-8fe59d82/setup/Main.o ) Linking /var/folders/jl/h90f3bxs7hxb389cvjdc6k5w0000gn/T/pandoc-1.13.1-84931/pandoc-1.13.1/dist/dist-sandbox-8fe59d82/setup/setup ... Configuring pandoc-1.13.1... Building pandoc-1.13.1... Preprocessing library pandoc-1.13.1... [ 1 of 67] Compiling Text.Pandoc.Asciify etc . . . [19 of 67] Compiling Text.Pandoc.Shared ( src/Text/Pandoc/Shared.hs, dist/dist-sandbox-8fe59d82/build/Text/Pandoc/Shared.o ) src/Text/Pandoc/Shared.hs:808:55: Not in scope: ?toChunks? cabal: Error: some packages failed to install: hakyll-4.5.5.0 depends on pandoc-1.13.1 which failed to install. pandoc-1.13.1 failed during the building phase. The exception was: ExitFailure 1 pandoc-citeproc-0.4.0.1 depends on pandoc-1.13.1 which failed to install. From allbery.b at gmail.com Sat Sep 20 04:05:45 2014 From: allbery.b at gmail.com (Brandon Allbery) Date: Sat, 20 Sep 2014 00:05:45 -0400 Subject: [Haskell-beginners] Patch source, then pickup compile In-Reply-To: <383C4CFD-D581-408C-BB03-4EF49C843AEF@jtoll.com> References: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> <03C825EB-E697-4F67-A7B5-A054E8A93A56@jtoll.com> <383C4CFD-D581-408C-BB03-4EF49C843AEF@jtoll.com> Message-ID: On Sat, Sep 20, 2014 at 12:01 AM, James Toll wrote: > [james ~/src/haskell/sandboxes/hakyll/pandoc-1.13.1]$ cabal install -j > Resolving dependencies... > In order, the following will be installed: > This sounds like it did not indeed install in the sandbox (compare the notice after "Resolving dependencies" in the hakyll install). Unfortunately I don't know what follows from here; it sounds like a cabal bug to me, but maybe being in the patched pandoc source directory keeps it from seeing the sandbox, in which case maybe there's an option to point to a specific sandbox for installs? (I still don't have a working Haskell install on my new machine, and am not sure at this point when I'll be able to get to it, sigh.) -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at jtoll.com Sat Sep 20 05:04:35 2014 From: james at jtoll.com (James Toll) Date: Sat, 20 Sep 2014 00:04:35 -0500 Subject: [Haskell-beginners] Patch source, then pickup compile In-Reply-To: References: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> <03C825EB-E697-4F67-A7B5-A054E8A93A56@jtoll.com> <383C4CFD-D581-408C-BB03-4EF49C843AEF@jtoll.com> Message-ID: <778FC1FC-25AA-4276-A03D-10EBF03D5B7B@jtoll.com> On Sep 19, 2014, at 11:05 PM, Brandon Allbery wrote: > On Sat, Sep 20, 2014 at 12:01 AM, James Toll wrote: > [james ~/src/haskell/sandboxes/hakyll/pandoc-1.13.1]$ cabal install -j > Resolving dependencies... > In order, the following will be installed: > > This sounds like it did not indeed install in the sandbox (compare the notice after "Resolving dependencies" in the hakyll install). Unfortunately I don't know what follows from here; it sounds like a cabal bug to me, but maybe being in the patched pandoc source directory keeps it from seeing the sandbox, in which case maybe there's an option to point to a specific sandbox for installs? (I still don't have a working Haskell install on my new machine, and am not sure at this point when I'll be able to get to it, sigh.) Thank you for the help. I wonder if I need to set this up as a shared sandbox so that pandoc gets installed to the sandbox in the parent directory. Kind of like the first example from the ?Advanced usage? section of: http://coldwa.st/e/blog/2013-08-20-Cabal-sandbox.html Anyway, thank you for pointing me in the right direction. James From james at jtoll.com Sat Sep 20 06:06:09 2014 From: james at jtoll.com (James Toll) Date: Sat, 20 Sep 2014 01:06:09 -0500 Subject: [Haskell-beginners] Patch source, then pickup compile In-Reply-To: <778FC1FC-25AA-4276-A03D-10EBF03D5B7B@jtoll.com> References: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> <03C825EB-E697-4F67-A7B5-A054E8A93A56@jtoll.com> <383C4CFD-D581-408C-BB03-4EF49C843AEF@jtoll.com> <778FC1FC-25AA-4276-A03D-10EBF03D5B7B@jtoll.com> Message-ID: <52BCCC1F-E5B2-4A26-8D1D-982E29D9103B@jtoll.com> On Sep 20, 2014, at 12:04 AM, James Toll wrote: > On Sep 19, 2014, at 11:05 PM, Brandon Allbery wrote: > >> On Sat, Sep 20, 2014 at 12:01 AM, James Toll wrote: >> [james ~/src/haskell/sandboxes/hakyll/pandoc-1.13.1]$ cabal install -j >> Resolving dependencies... >> In order, the following will be installed: >> >> This sounds like it did not indeed install in the sandbox (compare the notice after "Resolving dependencies" in the hakyll install). Unfortunately I don't know what follows from here; it sounds like a cabal bug to me, but maybe being in the patched pandoc source directory keeps it from seeing the sandbox, in which case maybe there's an option to point to a specific sandbox for installs? (I still don't have a working Haskell install on my new machine, and am not sure at this point when I'll be able to get to it, sigh.) > > > Thank you for the help. I wonder if I need to set this up as a shared sandbox so that pandoc gets installed to the sandbox in the parent directory. Kind of like the first example from the ?Advanced usage? section of: > > http://coldwa.st/e/blog/2013-08-20-Cabal-sandbox.html Creating a shared sandbox ended up working. I don?t know it that?s the proper way to do this kind of thing. For reference, here is what I did to get Hakyll installed with the broken Pandoc dependency: $ mkdir hakyll $ cd hakyll $ cabal sandbox init --sandbox . $ cabal install -j hakyll [compilation fails at Pandoc] $ cabal get pandoc-1.13.1 $ cd pandoc-1.13.1/ $ cabal sandbox init --sandbox ../ [make trivial source change] $ cabal install -j $ cd .. $ cabal install -j hakyll I?ve not tested the Hakyll installation yet to see if it works properly, but the installation succeeded. James From benjaminfjones at gmail.com Sat Sep 20 06:09:52 2014 From: benjaminfjones at gmail.com (Benjamin Jones) Date: Fri, 19 Sep 2014 23:09:52 -0700 Subject: [Haskell-beginners] Patch source, then pickup compile In-Reply-To: <52BCCC1F-E5B2-4A26-8D1D-982E29D9103B@jtoll.com> References: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> <03C825EB-E697-4F67-A7B5-A054E8A93A56@jtoll.com> <383C4CFD-D581-408C-BB03-4EF49C843AEF@jtoll.com> <778FC1FC-25AA-4276-A03D-10EBF03D5B7B@jtoll.com> <52BCCC1F-E5B2-4A26-8D1D-982E29D9103B@jtoll.com> Message-ID: I ran into this same build problem myself the other day. I believe that forcing pandoc to build with the https flag set is a workaround until the next hackage release. You can add this on the command line with: $ cabal install pandoc -fhttps or in the cabal.config file: constraints: pandoc +https -- Benjamin Jones On Fri, Sep 19, 2014 at 11:06 PM, James Toll wrote: > On Sep 20, 2014, at 12:04 AM, James Toll wrote: > > > On Sep 19, 2014, at 11:05 PM, Brandon Allbery > wrote: > > > >> On Sat, Sep 20, 2014 at 12:01 AM, James Toll wrote: > >> [james ~/src/haskell/sandboxes/hakyll/pandoc-1.13.1]$ cabal install -j > >> Resolving dependencies... > >> In order, the following will be installed: > >> > >> This sounds like it did not indeed install in the sandbox (compare the > notice after "Resolving dependencies" in the hakyll install). Unfortunately > I don't know what follows from here; it sounds like a cabal bug to me, but > maybe being in the patched pandoc source directory keeps it from seeing the > sandbox, in which case maybe there's an option to point to a specific > sandbox for installs? (I still don't have a working Haskell install on my > new machine, and am not sure at this point when I'll be able to get to it, > sigh.) > > > > > > Thank you for the help. I wonder if I need to set this up as a shared > sandbox so that pandoc gets installed to the sandbox in the parent > directory. Kind of like the first example from the ?Advanced usage? > section of: > > > > http://coldwa.st/e/blog/2013-08-20-Cabal-sandbox.html > > Creating a shared sandbox ended up working. I don?t know it that?s the > proper way to do this kind of thing. For reference, here is what I did to > get Hakyll installed with the broken Pandoc dependency: > > $ mkdir hakyll > $ cd hakyll > $ cabal sandbox init --sandbox . > $ cabal install -j hakyll > [compilation fails at Pandoc] > $ cabal get pandoc-1.13.1 > $ cd pandoc-1.13.1/ > $ cabal sandbox init --sandbox ../ > [make trivial source change] > $ cabal install -j > $ cd .. > $ cabal install -j hakyll > > I?ve not tested the Hakyll installation yet to see if it works properly, > but the installation succeeded. > > James > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nadirsampaoli at gmail.com Sat Sep 20 06:52:29 2014 From: nadirsampaoli at gmail.com (Nadir Sampaoli) Date: Sat, 20 Sep 2014 08:52:29 +0200 Subject: [Haskell-beginners] Patch source, then pickup compile In-Reply-To: <52BCCC1F-E5B2-4A26-8D1D-982E29D9103B@jtoll.com> References: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> <03C825EB-E697-4F67-A7B5-A054E8A93A56@jtoll.com> <383C4CFD-D581-408C-BB03-4EF49C843AEF@jtoll.com> <778FC1FC-25AA-4276-A03D-10EBF03D5B7B@jtoll.com> <52BCCC1F-E5B2-4A26-8D1D-982E29D9103B@jtoll.com> Message-ID: Hello, > > I wonder if I need to set this up as a shared sandbox so that pandoc gets installed to the sandbox in the parent directory. Kind of like the first example from the ?Advanced usage? section of: > > > > http://coldwa.st/e/blog/2013-08-20-Cabal-sandbox.html > > Creating a shared sandbox ended up working. I don?t know it that?s the proper way to do this kind of thing. For the moment Benjamin's solution seems the best way to go but, just for the record, I think the command you're looking for might be `cabal sandbox add-source ./your-local-patched-pandoc/` and then `install` (see http://www.haskell.org/cabal/users-guide/installing-packages.html under "Sandboxes: Basic usage" or probably the very same article you referred to, which seems the source for the wiki). -- Nadir -------------- next part -------------- An HTML attachment was scrubbed... URL: From vlatko.basic at gmail.com Sat Sep 20 07:43:12 2014 From: vlatko.basic at gmail.com (Vlatko Basic) Date: Sat, 20 Sep 2014 09:43:12 +0200 Subject: [Haskell-beginners] Patch source, then pickup compile In-Reply-To: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> References: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> Message-ID: <541D3010.9050100@gmail.com> Get (patched) package into a separate dir $ cabal sandbox add-source /my/patched/library # Add a new add-source dependency $ cabal install --dependencies-only # Install it into the sandbox $ cabal build # Build the local package This way cabal first searches in the add-source dir for any dependency, and builds it from there. You can add several dirs with patched packages You can/might have to add constraints in local cabal.config file (in sandboxed dir) to force cabal to use the latest version of the package If a file in any add-source dir is changed, cabal will rebuild it automatically Take a look at cabal user guide http://www.haskell.org/cabal/users-guide/installing-packages.html vlatko -------- Original Message -------- Subject: [Haskell-beginners] Patch source, then pickup compile From: James Toll To: haskell-beginners Date: 20.09.2014 03:48 > Hi, > > I?m trying to install Hakyll within a cabal sandbox. The issue I?m running into is that the current version of Pandoc doesn?t build because of this bug: > > https://github.com/jgm/pandoc/issues/1590 > > The bug is a simple fix, and is fixed on github, but not in the version on hackage. I?d like to use ?cabal get? to download the source, manually fix the source, then compile. The question I have is how do I pick up the installation process after fixing the source? > > So far this is what I?ve done: > > $ mkdir hakyll > $ cabal update > $ cd hakyll > $ cabal sandbox init --sandbox . > $ cabal install -j hakyll > [this is the spot where pandoc fails to install] > $ cabal get pandoc-1.13.1 > $ cd pandoc-1.13.1/ > [patch the source] > > At this point I need to resume the compilation and installation process. How do I do that? Do I move back up to the parent directory and then issue the 'cabal install -j hakyll? command again? > > Thanks, > > > James > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > From james at jtoll.com Sat Sep 20 16:58:05 2014 From: james at jtoll.com (James Toll) Date: Sat, 20 Sep 2014 11:58:05 -0500 Subject: [Haskell-beginners] Patch source, then pickup compile In-Reply-To: <541D3010.9050100@gmail.com> References: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> <541D3010.9050100@gmail.com> Message-ID: <0796DBCD-62E4-4378-9883-B67031A26C49@jtoll.com> On Sep 20, 2014, at 2:43 AM, Vlatko Basic wrote: > Get (patched) package into a separate dir > $ cabal sandbox add-source /my/patched/library # Add a new add-source dependency > $ cabal install --dependencies-only # Install it into the sandbox > $ cabal build # Build the local package > > This way cabal first searches in the add-source dir for any dependency, and builds it from there. You can add several dirs with patched packages > > You can/might have to add constraints in local cabal.config file (in sandboxed dir) to force cabal to use the latest version of the package Thanks to you, Nadir, and Benjamin for the follow-up emails explaining the proper way to handle this. From your emails, it sounds like instead of using a shared sandbox, I should have added the Pandoc source using 'cabal sandbox add-source'. What I?m wondering now is what are the implications of the way I managed to get it to work? And whether I should go back and re-do it the way you?ve described. I do have one concern though. The part where you mention that if any of the source files are changed, then cabal will rebuild. I don?t want or need that functionality given that this is supposed to be a temporary work around until the fixed version of Pandoc is in Hackage. > If a file in any add-source dir is changed, cabal will rebuild it automatically If possible, I might prefer to just delete the pandoc-1.13.1 source subdirectory entirely, as long as it doesn?t mess up the current hakyll installation. Is that possible? If not, in the future, once the version of Pandoc in Hackage has been updated, is it then possible to remove the added source? Thanks, James From nadirsampaoli at gmail.com Sat Sep 20 17:08:24 2014 From: nadirsampaoli at gmail.com (Nadir Sampaoli) Date: Sat, 20 Sep 2014 19:08:24 +0200 Subject: [Haskell-beginners] Patch source, then pickup compile In-Reply-To: <0796DBCD-62E4-4378-9883-B67031A26C49@jtoll.com> References: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> <541D3010.9050100@gmail.com> <0796DBCD-62E4-4378-9883-B67031A26C49@jtoll.com> Message-ID: Il 20/set/2014 18:58 "James Toll" wrote: > > I do have one concern though. The part where you mention that if any of the source files are changed, then cabal will rebuild. I don?t want or need that functionality given that this is supposed to be a temporary work around until the fixed version of Pandoc is in Hackage. According to the wiki ("sandboxes: advanced usage" section) you should use `cabal sandbox add-source --snapshot` "which disables the change tracking". > > If possible, I might prefer to just delete the pandoc-1.13.1 source subdirectory entirely, as long as it doesn?t mess up the current hakyll installation. Is that possible? If not, in the future, once the version of Pandoc in Hackage has been updated, is it then possible to remove the added source? To remove an added source I think the correct sandbox subcommand is `delete-source`. See the --help for more info. -- Nadir -------------- next part -------------- An HTML attachment was scrubbed... URL: From james at jtoll.com Sat Sep 20 17:41:28 2014 From: james at jtoll.com (James Toll) Date: Sat, 20 Sep 2014 12:41:28 -0500 Subject: [Haskell-beginners] Patch source, then pickup compile In-Reply-To: References: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> <541D3010.9050100@gmail.com> <0796DBCD-62E4-4378-9883-B67031A26C49@jtoll.com> Message-ID: <03F81764-63A2-477B-95F6-B2BA3EC4C6DA@jtoll.com> On Sep 20, 2014, at 12:08 PM, Nadir Sampaoli wrote: > > Il 20/set/2014 18:58 "James Toll" wrote: > > > > I do have one concern though. The part where you mention that if any of the source files are changed, then cabal will rebuild. I don?t want or need that functionality given that this is supposed to be a temporary work around until the fixed version of Pandoc is in Hackage. > > According to the wiki ("sandboxes: advanced usage" section) you should use `cabal sandbox add-source --snapshot` "which disables the change tracking". > > > > > If possible, I might prefer to just delete the pandoc-1.13.1 source subdirectory entirely, as long as it doesn?t mess up the current hakyll installation. Is that possible? If not, in the future, once the version of Pandoc in Hackage has been updated, is it then possible to remove the added source? > To remove an added source I think the correct sandbox subcommand is `delete-source`. See the --help for more info. Yes, thank you. The ??snapshot' was in the documentation. I should have noticed it. The 'delete-source' doesn?t appear to be in the ?cabal sandbox ?help? page, although 'cabal sandbox list-sources? supposedly mentions it once you have local build trees. I'll see if that ends up being the case. Thank you. James From james at jtoll.com Sun Sep 21 01:26:40 2014 From: james at jtoll.com (James Toll) Date: Sat, 20 Sep 2014 20:26:40 -0500 Subject: [Haskell-beginners] Patch source, then pickup compile In-Reply-To: References: <25BB30C7-FABA-4EB0-884F-179F7D326694@jtoll.com> <541D3010.9050100@gmail.com> <0796DBCD-62E4-4378-9883-B67031A26C49@jtoll.com> Message-ID: On Sep 20, 2014, at 12:08 PM, Nadir Sampaoli wrote: > Il 20/set/2014 18:58 "James Toll" wrote: > > > > I do have one concern though. The part where you mention that if any of the source files are changed, then cabal will rebuild. I don?t want or need that functionality given that this is supposed to be a temporary work around until the fixed version of Pandoc is in Hackage. > > According to the wiki ("sandboxes: advanced usage" section) you should use `cabal sandbox add-source --snapshot` "which disables the change tracking". > > > > > If possible, I might prefer to just delete the pandoc-1.13.1 source subdirectory entirely, as long as it doesn?t mess up the current hakyll installation. Is that possible? If not, in the future, once the version of Pandoc in Hackage has been updated, is it then possible to remove the added source? > To remove an added source I think the correct sandbox subcommand is `delete-source`. See the --help for more info. I wish I could say that I got this to work, but I?ve had no success. The problem I?m having is that I can?t even get 'cabal sandbox add-source --snapshot? to work. This is what I?m trying to do, and the output: $ mkdir hakyll $ cd hakyll $ cabal sandbox init --sandbox . $ cabal install -j hakyll [compilation fails] $ cabal get pandoc-1.13.1 $ cabal sandbox add-source --snapshot pandoc-1.13.1/ cabal: Error: Could not find module: Text.Pandoc.Data with any suffix: ["gc","chs","hsc","x","y","ly","cpphs","hs","lhs?] This last command creates the ?snapshots' directory within the hakyll directory. Snapshots contains an empty subdirectory called ?pandoc-1.13.1-tmp?. If I then try a different slightly different path to pandoc, it fails, but differently: $ cabal sandbox add-source --snapshot ./pandoc-1.13.1/ cabal: /Users/james/src/haskell/sandboxes/hakyll/snapshots/pandoc-1.13.1: does not exist If I delete the ?snapshots? directory, it fails with the first error where it can?t find the module. What am I doing wrong? I?ve tried many different iterations of this. Executing the command from within the pandoc directory, renaming the directory, plus many other variations. Nothing has worked. How is this supposed to work. It just doesn?t seem like it should be this hard. Thanks. James From derek.mcloughlin at gmail.com Sun Sep 21 14:02:55 2014 From: derek.mcloughlin at gmail.com (Derek McLoughlin) Date: Sun, 21 Sep 2014 15:02:55 +0100 Subject: [Haskell-beginners] Using a monadic operation in a list comprehension. Message-ID: Hi, I'm trying to get Graham Hutton's "Programming with Effects" article (http://www.cs.nott.ac.uk/~gmh/monads) working with Data.Tree instead of the Tree he provides. My code is here: https://gist.github.com/derekmcloughlin/95ab690e0c07c5a7221e The compiler is complaining about the use of lab <- mlabel c in the list comprehension: Couldn't match expected type ?[Tree (a, Int)]? with actual type ?ST (Tree (a, Int))? This makes sense, but is there any way to execute the monad operation "mlabel" within the list comprehension? I've tried the MonadComprehensions extension but still get an error. Derek. From defigueiredo at ucdavis.edu Sun Sep 21 17:05:43 2014 From: defigueiredo at ucdavis.edu (Dimitri DeFigueiredo) Date: Sun, 21 Sep 2014 11:05:43 -0600 Subject: [Haskell-beginners] what space leak could happen here? Message-ID: <541F0567.4060205@ucdavis.edu> Hi All, I was looking at the definition of intersperse on http://hackage.haskell.org/package/base-4.7.0.1/docs/src/Data-List.html#intersperse And found this -- | The 'intersperse' function takes an element and a list and -- \`intersperses\' that element between the elements of the list. -- For example, -- -- > intersperse ',' "abcde" == "a,b,c,d,e" intersperse :: a -> [a] -> [a] intersperse _ [] = [] intersperse sep (x:xs) = x : prependToAll sep xs -- Not exported: -- We want to make every element in the 'intersperse'd list available -- as soon as possible to avoid space leaks. Experiments suggested that -- a separate top-level helper is more efficient than a local worker. prependToAll :: a -> [a] -> [a] prependToAll _ [] = [] prependToAll sep (x:xs) = sep : x : prependToAll sep xs I don't understand why we need to "make every element in the 'intersperse'd list available as soon as possible to avoid space leaks." Could somebody shed some light on what could cause a space leak here? In particular, would this simpler version cause problems? intersperse :: a -> [a] -> [a] intersperse _ [] = [] intersperse _ [x] = [x] intersperse a (x: xs@(y:ys)) = x : a : intersperse a xs Thanks, Dimitri -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Sun Sep 21 18:38:36 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Mon, 22 Sep 2014 01:38:36 +0700 Subject: [Haskell-beginners] Using a monadic operation in a list comprehension. In-Reply-To: References: Message-ID: On Sun, Sep 21, 2014 at 9:02 PM, Derek McLoughlin < derek.mcloughlin at gmail.com> wrote: > I'm trying to get Graham Hutton's "Programming with Effects" article > (http://www.cs.nott.ac.uk/~gmh/monads) working with Data.Tree instead > of the Tree he provides. > Hi Derek, This is a lovely problem that's inspired a bunch of interesting papers recently. Here's a stab at the compilation error you're facing: http://www.atamo.com/blog/how-to-solve-a-tricky-monad-problem-1/ Enjoy :) -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From chaddai.fouche at gmail.com Sun Sep 21 19:20:04 2014 From: chaddai.fouche at gmail.com (=?UTF-8?B?Q2hhZGRhw68gRm91Y2jDqQ==?=) Date: Sun, 21 Sep 2014 21:20:04 +0200 Subject: [Haskell-beginners] what space leak could happen here? In-Reply-To: <541F0567.4060205@ucdavis.edu> References: <541F0567.4060205@ucdavis.edu> Message-ID: On Sun, Sep 21, 2014 at 7:05 PM, Dimitri DeFigueiredo < defigueiredo at ucdavis.edu> wrote: > I don't understand why we need to "make every element in the > 'intersperse'd list available as soon as possible to avoid space leaks." > Could somebody shed some light on what could cause a space leak here? In > particular, would this simpler version cause problems? > This is delicate but basically your version needs to force the second element of the list (to check if it's []) before it produce the first element of the result while the base version doesn't, check with "take 1 . intersperse ',' $ 'a' : undefined". The leak can occur when you only need the first element of the result to start producing but the second one is expensive to produce and store, the base version avoid the problem by being maximally lazy. -- Jeda? -------------- next part -------------- An HTML attachment was scrubbed... URL: From defigueiredo at ucdavis.edu Sun Sep 21 20:12:04 2014 From: defigueiredo at ucdavis.edu (Dimitri DeFigueiredo) Date: Sun, 21 Sep 2014 14:12:04 -0600 Subject: [Haskell-beginners] what space leak could happen here? In-Reply-To: References: <541F0567.4060205@ucdavis.edu> Message-ID: <541F3114.4010308@ucdavis.edu> Thanks! I don't quite understand the last sentence, though. So, it is a leak just because it needs to evaluate an element that may not be required? I thought a space leak implied we would be changing the "Big O" asymptotic order of space usage. How would the extra evaluation would change that? Thanks again, Dimitri On 21/09/14 13:20, Chadda? Fouch? wrote: > On Sun, Sep 21, 2014 at 7:05 PM, Dimitri DeFigueiredo > > wrote: > > I don't understand why we need to "make every element in the > 'intersperse'd list available as soon as possible to avoid space > leaks." Could somebody shed some light on what could cause a space > leak here? In particular, would this simpler version cause problems? > > > This is delicate but basically your version needs to force the second > element of the list (to check if it's []) before it produce the first > element of the result while the base version doesn't, check with "take > 1 . intersperse ',' $ 'a' : undefined". > > The leak can occur when you only need the first element of the result > to start producing but the second one is expensive to produce and > store, the base version avoid the problem by being maximally lazy. > -- > Jeda? > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From derek.mcloughlin at gmail.com Sun Sep 21 20:55:50 2014 From: derek.mcloughlin at gmail.com (Derek McLoughlin) Date: Sun, 21 Sep 2014 21:55:50 +0100 Subject: [Haskell-beginners] Using a monadic operation in a list comprehension. In-Reply-To: References: Message-ID: Thanks very much for your clear explanation! Worked perfectly. You're right about the ST - I got very confused at the start with Control.Monad.ST. I'll be removing Graham's ST in favour of the 'normal' State monad. On 21 September 2014 19:38, Kim-Ee Yeoh wrote: > > On Sun, Sep 21, 2014 at 9:02 PM, Derek McLoughlin > wrote: >> >> I'm trying to get Graham Hutton's "Programming with Effects" article >> (http://www.cs.nott.ac.uk/~gmh/monads) working with Data.Tree instead >> of the Tree he provides. > > > Hi Derek, > > This is a lovely problem that's inspired a bunch of interesting papers > recently. > > Here's a stab at the compilation error you're facing: > > http://www.atamo.com/blog/how-to-solve-a-tricky-monad-problem-1/ > > Enjoy :) > > -- Kim-Ee > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > From phil at cnphil.com Mon Sep 22 04:10:45 2014 From: phil at cnphil.com (Phil Xiaojun Hu) Date: Mon, 22 Sep 2014 12:10:45 +0800 Subject: [Haskell-beginners] what space leak could happen here? In-Reply-To: <541F3114.4010308@ucdavis.edu> References: <541F0567.4060205@ucdavis.edu> <541F3114.4010308@ucdavis.edu> Message-ID: <20140922041045.GA23800@narita.takau.net> On Sun, Sep 21, 2014 at 02:12:04PM -0600, Dimitri DeFigueiredo wrote: > Thanks! > > I don't quite understand the last sentence, though. So, it is a leak just > because it needs to evaluate an element that may not be required? I thought > a space leak implied we would be changing the "Big O" asymptotic order of > space usage. How would the extra evaluation would change that? Think of a network socket as the source of your list, and the first character is all you need. If you need to evaluate the second character to get the first, you could be stuck on the network socket for some time waiting for the second one to come. And I think the reason it would break some "Big O"s is that most complexity analysis in Haskell are amortized bounds and it uses the fact that Haskell is lazy and won't evaluate something until we actually need it. -- Phil Xiaojun Hu -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 819 bytes Desc: not available URL: From allbery.b at gmail.com Mon Sep 22 04:19:19 2014 From: allbery.b at gmail.com (Brandon Allbery) Date: Mon, 22 Sep 2014 00:19:19 -0400 Subject: [Haskell-beginners] what space leak could happen here? In-Reply-To: <20140922041045.GA23800@narita.takau.net> References: <541F0567.4060205@ucdavis.edu> <541F3114.4010308@ucdavis.edu> <20140922041045.GA23800@narita.takau.net> Message-ID: On Mon, Sep 22, 2014 at 12:10 AM, Phil Xiaojun Hu wrote: > Think of a network socket as the source of your list, and the first > character is all you need. If you need to evaluate the second character > to get the first, you could be stuck on the network socket for some > time waiting for the second one to come. > That's more of a time leak. I think the space leak aspect comes from the fact that you've evaluated a second list element that was not requested, may never be used, and will be held in the heap until all shared consumers of the list go out of scope. (It may of course also be a time leak if computing that second element is expensive.) -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From miroslav.karpis at gmail.com Tue Sep 23 11:04:44 2014 From: miroslav.karpis at gmail.com (Miroslav Karpis) Date: Tue, 23 Sep 2014 13:04:44 +0200 Subject: [Haskell-beginners] fresh install - cabal version confusion Message-ID: Hi, please can you help me with following? I?m having some issues with a Haskell upgrade. Before upgrade I have uninstalled Haskell, removed directory + removed .ghc and .cabal files. After I install haskell and run cabal ?V I get the output below. Confusing is the versions cabal returns: cabal-install version 1.18.0.5 using version 1.18.1.4? I have tried to run also cabal update, what installed 1.20.0.3, but I still got the same output. What does it mean? I?m running on Mac. ********************************************************************** === Configuration for cabal has been written to /Users/miro/.cabal/config === Executables will be installed in: /Users/miro/Library/Haskell/bin You may wish to place this on your PATH by adding the following line to your ~/.bash_profile: export PATH="$HOME/Library/Haskell/bin:$PATH" === When documentation is built, a master index to all documentation will be placed in: /Users/miro/Library/Haskell/doc/index.html You may wish to bookmark that file once it gets built (after the first cabal install). ********************************************************************** Downloading the latest package list from hackage.haskell.org Note: there is a new version of cabal-install available. To upgrade, run: cabal install cabal-install cabal-install version 1.18.0.5 using version 1.18.1.4 of the Cabal library -------------- next part -------------- An HTML attachment was scrubbed... URL: From miroslav.karpis at gmail.com Tue Sep 23 11:10:36 2014 From: miroslav.karpis at gmail.com (Miroslav Karpis) Date: Tue, 23 Sep 2014 13:10:36 +0200 Subject: [Haskell-beginners] FW: fresh install - cabal version confusion In-Reply-To: References: Message-ID: So I found out that cabal and cabal-install are 2 different modules ;-) Would it be not cleaner with this: > cabal-install version 1.18.0.5 > Cabal version 1.18.1.4 Instead of what we currently get? > cabal-install version 1.18.0.5 > using version 1.18.1.4 of the Cabal library Cheers Miro From: Miroslav Karpis Date: Tuesday 23 September 2014 13:04 To: Haskell-Beginners Haskell Subject: fresh install - cabal version confusion Hi, please can you help me with following? I?m having some issues with a Haskell upgrade. Before upgrade I have uninstalled Haskell, removed directory + removed .ghc and .cabal files. After I install haskell and run cabal ?V I get the output below. Confusing is the versions cabal returns: cabal-install version 1.18.0.5 using version 1.18.1.4? I have tried to run also cabal update, what installed 1.20.0.3, but I still got the same output. What does it mean? I?m running on Mac. ********************************************************************** === Configuration for cabal has been written to /Users/miro/.cabal/config === Executables will be installed in: /Users/miro/Library/Haskell/bin You may wish to place this on your PATH by adding the following line to your ~/.bash_profile: export PATH="$HOME/Library/Haskell/bin:$PATH" === When documentation is built, a master index to all documentation will be placed in: /Users/miro/Library/Haskell/doc/index.html You may wish to bookmark that file once it gets built (after the first cabal install). ********************************************************************** Downloading the latest package list from hackage.haskell.org Note: there is a new version of cabal-install available. To upgrade, run: cabal install cabal-install cabal-install version 1.18.0.5 using version 1.18.1.4 of the Cabal library -------------- next part -------------- An HTML attachment was scrubbed... URL: From gmizrahi22 at gmail.com Tue Sep 23 11:13:45 2014 From: gmizrahi22 at gmail.com (Gil Mizrahi) Date: Tue, 23 Sep 2014 14:13:45 +0300 Subject: [Haskell-beginners] fresh install - cabal version confusion In-Reply-To: References: Message-ID: Hi, You probably want to add the path in which the new cabal was installed to the $PATH variable in your ~/.bashrc or ~/.bash_profile file. So add the following line: export PATH="$HOME/Library/Haskell/bin:$PATH" at the end of either ~/.bash_profile or ~/.bashrc and restart your terminal. This will tell your shell where to find the new cabal you installed with cabal install. On Tue, Sep 23, 2014 at 2:04 PM, Miroslav Karpis wrote: > Hi, please can you help me with following? I?m having some issues with a > Haskell upgrade. > Before upgrade I have uninstalled Haskell, removed directory + removed > .ghc and .cabal files. After I install haskell and run cabal ?V I get the > output below. Confusing is the versions cabal returns: *cabal-install > version 1.18.0.5 using version 1.18.1.4*? I have tried to run also cabal > update, what installed 1.20.0.3, but I still got the same output. What does > it mean? > > I?m running on Mac. > > > ********************************************************************** > === Configuration for cabal has been written to > /Users/miro/.cabal/config > > === Executables will be installed in: > /Users/miro/Library/Haskell/bin > > You may wish to place this on your PATH by adding the following > line to your ~/.bash_profile: > > export PATH="$HOME/Library/Haskell/bin:$PATH" > > === When documentation is built, a master index to all documentation > will be placed in: > > /Users/miro/Library/Haskell/doc/index.html > > You may wish to bookmark that file once it gets built (after the > first cabal install). > > ********************************************************************** > > Downloading the latest package list from hackage.haskell.org > Note: there is a new version of cabal-install available. > To upgrade, run: cabal install cabal-install > cabal-install version 1.18.0.5 > using version 1.18.1.4 of the Cabal library > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Thu Sep 25 19:07:13 2014 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Fri, 26 Sep 2014 02:07:13 +0700 Subject: [Haskell-beginners] Using a monadic operation in a list comprehension. In-Reply-To: References: Message-ID: On Mon, Sep 22, 2014 at 3:55 AM, Derek McLoughlin < derek.mcloughlin at gmail.com> wrote: > Thanks very much for your clear explanation! Worked perfectly. Thanks for taking the time to say this :) I hope I didn't belabor the mismatched effects bit. Combining effects is a wide open field of research if you look at papers like Extensible Effects, Monad Coproducts, etc. Point being, there just might be a way to make your code as originally written compile and work as you expect it to. Ah, the joys of life at the bleeding edge! -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From miroslav.karpis at gmail.com Fri Sep 26 14:34:32 2014 From: miroslav.karpis at gmail.com (Miro Karpis) Date: Fri, 26 Sep 2014 16:34:32 +0200 Subject: [Haskell-beginners] aeson json paring Message-ID: Hi, I'm trying to run an example from the eason documentation : ?> do result <- decode "{\"name\":\"Dave\",\"age\":2}" flip parseMaybe result $ \obj -> do age <- obj .: "age" name <- obj .: "name" return (name ++ ": " ++ show (age*2)) I made a function: jsonTest = do result <- decode "{\"name\":\"Dave\",\"age\":2}" flip parseMaybe result $ \obj -> do age <- obj .: "age" name <- obj .: "name" return (name ++ ": " ++ show (age*2)) which can not compile: hh.hs:35:41: No instance for (Show a0) arising from a use of ?show? The type variable ?a0? is ambiguous .... ... Please what am I doing wrong? Cheers, Miro -------------- next part -------------- An HTML attachment was scrubbed... URL: From raphaelsimeon at gmail.com Fri Sep 26 14:41:35 2014 From: raphaelsimeon at gmail.com (=?UTF-8?Q?Rapha=C3=ABl_Mongeau?=) Date: Fri, 26 Sep 2014 10:41:35 -0400 Subject: [Haskell-beginners] aeson json paring In-Reply-To: References: Message-ID: The key here is "The type variable ?a0? is ambiguous". You need to add a type signature to age so the compiler know if age is of type In,Float or Double ... :) 2014-09-26 10:34 GMT-04:00 Miro Karpis : > Hi, I'm trying to run an example from the eason documentation > > : > > ?> do result <- decode "{\"name\":\"Dave\",\"age\":2}" > flip parseMaybe result $ \obj -> do > age <- obj .: "age" > name <- obj .: "name" > return (name ++ ": " ++ show (age*2)) > > > I made a function: > > jsonTest = do > result <- decode "{\"name\":\"Dave\",\"age\":2}" > flip parseMaybe result $ \obj -> do > age <- obj .: "age" > name <- obj .: "name" > return (name ++ ": " ++ show (age*2)) > > which can not compile: > hh.hs:35:41: > No instance for (Show a0) arising from a use of ?show? > The type variable ?a0? is ambiguous > .... > ... > > > Please what am I doing wrong? > > Cheers, Miro > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -- Viva Cila -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuuzetsu at fuuzetsu.co.uk Sat Sep 27 04:20:11 2014 From: fuuzetsu at fuuzetsu.co.uk (Mateusz Kowalczyk) Date: Sat, 27 Sep 2014 05:20:11 +0100 Subject: [Haskell-beginners] aeson json paring In-Reply-To: References: Message-ID: <54263AFB.5040208@fuuzetsu.co.uk> On 09/26/2014 03:34 PM, Miro Karpis wrote: > Hi, I'm trying to run an example from the eason documentation > > : > > ?> do result <- decode "{\"name\":\"Dave\",\"age\":2}" > flip parseMaybe result $ \obj -> do > age <- obj .: "age" > name <- obj .: "name" > return (name ++ ": " ++ show (age*2)) > > > I made a function: > > jsonTest = do > result <- decode "{\"name\":\"Dave\",\"age\":2}" > flip parseMaybe result $ \obj -> do > age <- obj .: "age" > name <- obj .: "name" > return (name ++ ": " ++ show (age*2)) > > which can not compile: > hh.hs:35:41: > No instance for (Show a0) arising from a use of ?show? > The type variable ?a0? is ambiguous > .... > ... > > > Please what am I doing wrong? > > Cheers, Miro > As pointed out in the other response, you'll need a type signature somewhere to indicate what type your ?age? should be. I'd like to point out something else however. You appear to be using hard tabs (?\t? character): please don't do this! Haskell is alignment-sensitive and you'll run into problems due to this unless you *very* strictly only insert tabs. FTR GHC treats one \t as 8 spaces. There are beginners on daily basis in #haskell wondering why their code doesn't compile just to discover tabs once they share it through lpaste.net or similar service. [1] is the standard reference for style, especially see the ?Tabs? section. So, please, set your editor to only insert spaces. [1]: http://urchin.earth.li/~ian/style/haskell.html -- Mateusz K. From lists at webconect.ch Sat Sep 27 15:57:08 2014 From: lists at webconect.ch (Elias Diem) Date: Sat, 27 Sep 2014 17:57:08 +0200 Subject: [Haskell-beginners] HXT: encoding problem Message-ID: <20140927155708.GA6547@webconect.local> Hi guys I have got the following haskell program: ------------------------------------------------------ import Text.XML.HXT.Core main = do xml <- readFile "test_data-small.xml" let doc = readString config xml res <- runX . xshow $ doc >>> getChildren >>> isElem >>> hasName "contacts" >>> deep isText mapM_ putStrLn res config = [ withParseHTML no , withWarnings yes , withInputEncoding utf8 , withOutputEncoding utf8 , withValidate yes ] ------------------------------------------------------ The file 'test_data-small.xml' contains the following data: ------------------------------------------------------ Max M?ller ------------------------------------------------------ Note the umlaut in the lastname! If I run the program, I get the following error: ------------------------------------------------------ error: UTF-8 encoding error at input position 127: ValueOutOfBounds ------------------------------------------------------ Any help is appreciated. Thanks. -- Greetings Elias From derek.mcloughlin at gmail.com Sat Sep 27 16:13:56 2014 From: derek.mcloughlin at gmail.com (Derek McLoughlin) Date: Sat, 27 Sep 2014 17:13:56 +0100 Subject: [Haskell-beginners] HXT: encoding problem In-Reply-To: <20140927155708.GA6547@webconect.local> References: <20140927155708.GA6547@webconect.local> Message-ID: I just ran this (OS/X + Platform 2014 + hxt 9.3.1.7) and it worked perfectly. Are you sure that the XML file is actually saved with UTF-8 encoding? Can you attach it? On 27 September 2014 16:57, Elias Diem wrote: > Hi guys > > I have got the following haskell program: > > ------------------------------------------------------ > import Text.XML.HXT.Core > > main = do > xml <- readFile "test_data-small.xml" > let doc = readString config xml > res <- runX . xshow $ > doc > >>> > getChildren >>> isElem >>> hasName "contacts" > >>> > deep isText > mapM_ putStrLn res > > config = > [ withParseHTML no > , withWarnings yes > , withInputEncoding utf8 > , withOutputEncoding utf8 > , withValidate yes > ] > ------------------------------------------------------ > > The file 'test_data-small.xml' contains the following data: > > ------------------------------------------------------ > > > > > > > Max > M?ller > > > > > ------------------------------------------------------ > > Note the umlaut in the lastname! > > If I run the program, I get the following error: > > ------------------------------------------------------ > error: UTF-8 encoding error at input position 127: ValueOutOfBounds > ------------------------------------------------------ > > Any help is appreciated. Thanks. > > -- > Greetings > Elias > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners From lists at webconect.ch Sat Sep 27 17:21:34 2014 From: lists at webconect.ch (Elias Diem) Date: Sat, 27 Sep 2014 19:21:34 +0200 Subject: [Haskell-beginners] HXT: encoding problem In-Reply-To: References: <20140927155708.GA6547@webconect.local> Message-ID: <20140927172134.GA6848@webconect.local> Hi Derek On 2014-09-27, Derek McLoughlin wrote: > I just ran this (OS/X + Platform 2014 + hxt 9.3.1.7) and > it worked perfectly. Good. Thanks. > Are you sure that the XML file is actually saved with > UTF-8 encoding? I *think* so. Vim tells me that it's UTF-8. I will double check. > Can you attach it? Here it is. -- Greetings Elias -------------- next part -------------- A non-text attachment was scrubbed... Name: test_data-small.xml Type: application/xml Size: 181 bytes Desc: not available URL: From lists at webconect.ch Sat Sep 27 17:41:21 2014 From: lists at webconect.ch (Elias Diem) Date: Sat, 27 Sep 2014 19:41:21 +0200 Subject: [Haskell-beginners] HXT: encoding problem In-Reply-To: <20140927172134.GA6848@webconect.local> References: <20140927155708.GA6547@webconect.local> <20140927172134.GA6848@webconect.local> Message-ID: <20140927174121.GA6950@webconect.local> On 2014-09-27, Elias Diem wrote: > I *think* so. Vim tells me that it's UTF-8. I will double > check. I just double checked. I'm 99% sure now that it is indeed UTF-8. -- Greetings Elias From lists at webconect.ch Sat Sep 27 17:53:12 2014 From: lists at webconect.ch (Elias Diem) Date: Sat, 27 Sep 2014 19:53:12 +0200 Subject: [Haskell-beginners] HXT: encoding problem In-Reply-To: References: <20140927155708.GA6547@webconect.local> Message-ID: <20140927175312.GA7102@webconect.local> On 2014-09-27, Derek McLoughlin wrote: > I just ran this (OS/X + Platform 2014 + hxt 9.3.1.7) and > it worked perfectly. My version of HXT is 9.2.2. I run Debian GNU/Linux stable. -- Greetings Elias From derek.mcloughlin at gmail.com Sat Sep 27 21:12:37 2014 From: derek.mcloughlin at gmail.com (Derek McLoughlin) Date: Sat, 27 Sep 2014 22:12:37 +0100 Subject: [Haskell-beginners] HXT: encoding problem In-Reply-To: <20140927175312.GA7102@webconect.local> References: <20140927155708.GA6547@webconect.local> <20140927175312.GA7102@webconect.local> Message-ID: That file ran fine for me. I also tested it on a Cloud9 installation with GHC 7.6.3 and HXT 9.3 and it ran fine. Also Ubuntu 14.04, GHC 7.6.3 and HXT 9.3 worked fine. What's your default locale in Debian? On my Mac and test Ubuntu box, it's: LANG="en_IE.UTF-8" LC_COLLATE="en_IE.UTF-8" LC_CTYPE="en_IE.UTF-8" ... all values = "C.UTF-8" On my Cloud9 instance: LANG=C LANGUAGE= LC_CTYPE="C.UTF-8" ... all values = "C.UTF-8" On 27 September 2014 18:53, Elias Diem wrote: > On 2014-09-27, Derek McLoughlin wrote: > >> I just ran this (OS/X + Platform 2014 + hxt 9.3.1.7) and >> it worked perfectly. > > My version of HXT is 9.2.2. > > I run Debian GNU/Linux stable. > > -- > Greetings > Elias > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners From lists at webconect.ch Sun Sep 28 07:57:28 2014 From: lists at webconect.ch (Elias Diem) Date: Sun, 28 Sep 2014 09:57:28 +0200 Subject: [Haskell-beginners] HXT: encoding problem In-Reply-To: References: <20140927155708.GA6547@webconect.local> <20140927175312.GA7102@webconect.local> Message-ID: <20140928075728.GA4505@webconect.local> Hi Derek Thanks for your help so far. On 2014-09-27, Derek McLoughlin wrote: > That file ran fine for me. Ok. > I also tested it on a Cloud9 installation with GHC 7.6.3 and HXT 9.3 > and it ran fine. > > Also Ubuntu 14.04, GHC 7.6.3 and HXT 9.3 worked fine. I will test it later this day on another computer as well. > What's your default locale in Debian? > > On my Mac and test Ubuntu box, it's: > LANG="en_IE.UTF-8" > LC_COLLATE="en_IE.UTF-8" > LC_CTYPE="en_IE.UTF-8" > ... > all values = "C.UTF-8" > > On my Cloud9 instance: > > LANG=C > LANGUAGE= > LC_CTYPE="C.UTF-8" > ... > all values = "C.UTF-8" LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_COLLATE= LC_CTYPE= I haven't got any environment variables starting with LC defined. -- Greetings Elias From lists at webconect.ch Sun Sep 28 12:11:35 2014 From: lists at webconect.ch (Elias Diem) Date: Sun, 28 Sep 2014 14:11:35 +0200 Subject: [Haskell-beginners] HXT: encoding problem In-Reply-To: <20140928075728.GA4505@webconect.local> References: <20140927155708.GA6547@webconect.local> <20140927175312.GA7102@webconect.local> <20140928075728.GA4505@webconect.local> Message-ID: <20140928121135.GA22868@webconect.local> On 2014-09-28, Elias Diem wrote: > I will test it later this day on another computer as well. I just tested it on another Linux box. And it works!! What could be the problem? I noticed that on the other box I use HXT 9.3.1.1. Maybe that is solving the problem. -- Greetings Elias From toad3k at gmail.com Sun Sep 28 15:20:52 2014 From: toad3k at gmail.com (David McBride) Date: Sun, 28 Sep 2014 11:20:52 -0400 Subject: [Haskell-beginners] HXT: encoding problem In-Reply-To: <20140928121135.GA22868@webconect.local> References: <20140927155708.GA6547@webconect.local> <20140927175312.GA7102@webconect.local> <20140928075728.GA4505@webconect.local> <20140928121135.GA22868@webconect.local> Message-ID: I've had issues like this before where it had to do with the locale settings on my machine at the time. It is subtle and annoying but it will cause various haskell functions that read, like hGetContents to flip out if they see a character that is not readable by the locale you have set. It has to be something to do with that. On Sun, Sep 28, 2014 at 8:11 AM, Elias Diem wrote: > On 2014-09-28, Elias Diem wrote: > > > I will test it later this day on another computer as well. > > I just tested it on another Linux box. And it works!! What > could be the problem? > > I noticed that on the other box I use HXT 9.3.1.1. Maybe > that is solving the problem. > > -- > Greetings > Elias > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From chaddai.fouche at gmail.com Mon Sep 29 04:46:08 2014 From: chaddai.fouche at gmail.com (=?UTF-8?B?Q2hhZGRhw68gRm91Y2jDqQ==?=) Date: Mon, 29 Sep 2014 06:46:08 +0200 Subject: [Haskell-beginners] HXT: encoding problem In-Reply-To: <20140928121135.GA22868@webconect.local> References: <20140927155708.GA6547@webconect.local> <20140927175312.GA7102@webconect.local> <20140928075728.GA4505@webconect.local> <20140928121135.GA22868@webconect.local> Message-ID: On Sun, Sep 28, 2014 at 2:11 PM, Elias Diem wrote: > On 2014-09-28, Elias Diem wrote: > > > I will test it later this day on another computer as well. > > I just tested it on another Linux box. And it works!! What > could be the problem? > > readString is documented as not doing any decoding, so you're dependent on your readFile doing it right for you, but that depends on your locale ! You could set your IO system input encoding yourself to avoid the problem but it seems simpler to use "readDocument" provided by Hxt instead since that'll read the file with your specified input encoding. -- Jeda? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dontdieych at gmail.com Mon Sep 29 09:27:00 2014 From: dontdieych at gmail.com (Dontdie YCH) Date: Mon, 29 Sep 2014 18:27:00 +0900 Subject: [Haskell-beginners] Is there a way to add package to .cabal when I import some module? Message-ID: Is there a way to add package to .cabal when I import new module? From raymond at kestrel.nmt.edu Mon Sep 29 15:52:43 2014 From: raymond at kestrel.nmt.edu (David Raymond) Date: Mon, 29 Sep 2014 09:52:43 -0600 Subject: [Haskell-beginners] Unformatted binary IO Message-ID: <21545.32843.148976.521710@gargle.gargle.HOWL> I am trying to read and write to/from files or stdout/stdin that have an ascii header followed by unformatted float32 binary data. (The files are created using a C program.) The ascii header first needs to be parsed to understand the structure of the floating point data. I have solved the parsing problem, but getting the unformatted binary float data into a series of float (or double) immutable, unboxed vectors has defeated me so far. The binary package doesn't help as far as I can see, as the binary format it reads and writes has some control information at the beginning that doesn't exist in the format I am reading. This is easy in C, but seems to be hard in Haskell unless I am missing something. Any suggestions? -- David J. Raymond Prof. of Physics New Mexico Tech http://www.physics.nmt.edu/~raymond/index.html From chaddai.fouche at gmail.com Mon Sep 29 17:35:03 2014 From: chaddai.fouche at gmail.com (=?UTF-8?B?Q2hhZGRhw68gRm91Y2jDqQ==?=) Date: Mon, 29 Sep 2014 19:35:03 +0200 Subject: [Haskell-beginners] Unformatted binary IO In-Reply-To: <21545.32843.148976.521710@gargle.gargle.HOWL> References: <21545.32843.148976.521710@gargle.gargle.HOWL> Message-ID: This is easy in Haskell too and binary provide everything you need. It's not like you're _forced_ to use the Vector instance to construct a Vector from your values, you can simply repeat (with replicateM) the get for the Float (or Double) instance instead and build a Vector from the resulting list (if you do it properly it will probably fuse into a tight loop anyway). I don't understand your problem ? On Mon, Sep 29, 2014 at 5:52 PM, David Raymond wrote: > > I am trying to read and write to/from files or stdout/stdin that have > an ascii header followed by unformatted float32 binary data. (The > files are created using a C program.) The ascii header first needs to > be parsed to understand the structure of the floating point data. I > have solved the parsing problem, but getting the unformatted binary > float data into a series of float (or double) immutable, unboxed > vectors has defeated me so far. The binary package doesn't help as > far as I can see, as the binary format it reads and writes has some > control information at the beginning that doesn't exist in the format > I am reading. > > This is easy in C, but seems to be hard in Haskell unless I am missing > something. > > Any suggestions? > > -- > David J. Raymond > Prof. of Physics > New Mexico Tech > http://www.physics.nmt.edu/~raymond/index.html > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From byorgey at gmail.com Mon Sep 29 23:43:00 2014 From: byorgey at gmail.com (Brent Yorgey) Date: Mon, 29 Sep 2014 19:43:00 -0400 Subject: [Haskell-beginners] Unformatted binary IO In-Reply-To: <21545.32843.148976.521710@gargle.gargle.HOWL> References: <21545.32843.148976.521710@gargle.gargle.HOWL> Message-ID: I am not sure I have quite understood your problem, but perhaps the data-binary-ieee754 package may be of use? -Brent I am trying to read and write to/from files or stdout/stdin that have an ascii header followed by unformatted float32 binary data. (The files are created using a C program.) The ascii header first needs to be parsed to understand the structure of the floating point data. I have solved the parsing problem, but getting the unformatted binary float data into a series of float (or double) immutable, unboxed vectors has defeated me so far. The binary package doesn't help as far as I can see, as the binary format it reads and writes has some control information at the beginning that doesn't exist in the format I am reading. This is easy in C, but seems to be hard in Haskell unless I am missing something. Any suggestions? -- David J. Raymond Prof. of Physics New Mexico Tech http://www.physics.nmt.edu/~raymond/index.html _______________________________________________ Beginners mailing list Beginners at haskell.org http://www.haskell.org/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at webconect.ch Tue Sep 30 07:23:45 2014 From: lists at webconect.ch (Elias Diem) Date: Tue, 30 Sep 2014 09:23:45 +0200 Subject: [Haskell-beginners] HXT: encoding problem In-Reply-To: References: <20140927155708.GA6547@webconect.local> <20140927175312.GA7102@webconect.local> <20140928075728.GA4505@webconect.local> <20140928121135.GA22868@webconect.local> Message-ID: <20140930072345.GA4565@webconect.local> Hi Jeda? On 2014-09-29, Chadda? Fouch? wrote: > readString is documented as not doing any decoding, so you're dependent on > your readFile doing it right for you, but that depends on your locale ! > You could set your IO system input encoding yourself to avoid the problem > but it seems simpler to use "readDocument" provided by Hxt instead since > that'll read the file with your specified input encoding. I use readDocument now as sugested and it works. Thanks for the explanation. Thanks to the others too! -- Greetings Elias From raymond at kestrel.nmt.edu Tue Sep 30 10:56:41 2014 From: raymond at kestrel.nmt.edu (David Raymond) Date: Tue, 30 Sep 2014 04:56:41 -0600 Subject: [Haskell-beginners] Unformatted binary IO In-Reply-To: References: <21545.32843.148976.521710@gargle.gargle.HOWL> Message-ID: <21546.35945.707901.833368@gargle.gargle.HOWL> Brent Yorgey writes: > I am not sure I have quite understood your problem, but perhaps the > data-binary-ieee754 package may be of use? > > -Brent This package looks interesting. However, I am a true Haskell beginner and I am having a hard time figuring out how the various Binary packages are actually used to read and write files. Any help or pointers to tutorials would be greatly appreciated. Dave -- David J. Raymond Prof. of Physics New Mexico Tech http://www.physics.nmt.edu/~raymond/index.html From francesquini at gmail.com Tue Sep 30 15:33:51 2014 From: francesquini at gmail.com (Emilio De Camargo Francesquini) Date: Tue, 30 Sep 2014 12:33:51 -0300 Subject: [Haskell-beginners] Different behaviors between GHC 7.6.3 and 7.8.3 Message-ID: Hello everyone, I'm quite intrigued about these different behaviors between GHCs 7.6.3 and 7.8.3: GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> let x = 3 + 4 Prelude> :print x x = (_t1::Integer) Prelude> :force x x = 7 Prelude> print _t1 7 Prelude> GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Prelude> let x = 3 + 4 Prelude> :print x x = (_t1::Num a => a) Prelude> :force x x = _ Prelude> print _t1 ghc: panic! (the 'impossible' happened) (GHC version 7.8.3 for x86_64-unknown-linux): tcTyVarDetails a{tv atm} [tv] Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug Is it really a bug or is it something I really shouldn't be doing? I've found this (fixed) bug (https://ghc.haskell.org/trac/ghc/ticket/8557), with a similar error output, but it does not seem to be the same case. Thanks Emilio -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas at koch.ro Tue Sep 30 20:15:57 2014 From: thomas at koch.ro (Thomas Koch) Date: Tue, 30 Sep 2014 22:15:57 +0200 Subject: [Haskell-beginners] How to pass configuration to a function further down the call stack? Message-ID: <201409302215.58309.thomas@koch.ro> Hi, I wrote my first Haskell 'project', a test suite for my personal SIEVE mail filter script using dovecots 'sieve-test' tool: https://github.com/thkoch2001/sieve-test-hs The file Network/Sieve/Test.hs might actually be interesting as a standalone library. The most important function is assertMailActions :: Mail -> Actions -> IO () 'Actions' is a type that describes the result of running a SIEVE filter over the passed mail, e.g. store in a certain folder, discard, reject, ... Somewhere the external process 'sieve-test' is called. At this point I'd like to make certain things configurable: - the path and name of the executable - the parameters for the test-sieve executable - the name of the sieve script - the place where to store the temporary mail files - whether or not to remove the temporary mail files Does anybody has an idea where I could start to look for a solution? Thank you, Thomas Koch From cma at bitemyapp.com Tue Sep 30 21:23:58 2014 From: cma at bitemyapp.com (Christopher Allen) Date: Tue, 30 Sep 2014 16:23:58 -0500 Subject: [Haskell-beginners] How to pass configuration to a function further down the call stack? In-Reply-To: <201409302215.58309.thomas@koch.ro> References: <201409302215.58309.thomas@koch.ro> Message-ID: First, define a datatype unifying all this config information. Then there are two simple, common solutions. If only one or two functions need to be passed the Config data, then just pass it as an argument. If use of the config data is going to be prolific, you might want to consider Reader. http://stackoverflow.com/questions/14178889/reader-monad-purpose http://book.realworldhaskell.org/read/programming-with-monads.html https://hackage.haskell.org/package/transformers-0.4.1.0/docs/Control-Monad-Trans-Reader.html You could engage in deeper magic than this, but it's not worth it for your use-case. Hope this helps. -- Chris On Tue, Sep 30, 2014 at 3:15 PM, Thomas Koch wrote: > Hi, > > I wrote my first Haskell 'project', a test suite for my personal SIEVE mail > filter script using dovecots 'sieve-test' tool: > > https://github.com/thkoch2001/sieve-test-hs > > The file Network/Sieve/Test.hs might actually be interesting as a > standalone > library. The most important function is > > assertMailActions :: Mail -> Actions -> IO () > > 'Actions' is a type that describes the result of running a SIEVE filter > over > the passed mail, e.g. store in a certain folder, discard, reject, ... > > Somewhere the external process 'sieve-test' is called. At this point I'd > like > to make certain things configurable: > > - the path and name of the executable > - the parameters for the test-sieve executable > - the name of the sieve script > - the place where to store the temporary mail files > - whether or not to remove the temporary mail files > > Does anybody has an idea where I could start to look for a solution? > > Thank you, > > Thomas Koch > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: