From imantc at gmail.com Tue Jul 7 10:21:54 2015 From: imantc at gmail.com (Imants Cekusins) Date: Tue, 7 Jul 2015 12:21:54 +0200 Subject: [Haskell-beginners] case statement Message-ID: interestingly, the below test fails. May I ask: If "case" a1 is not the same as "where" a1, what is its value? Why does x=1 match against a1? note: result1 indent is aligned with a1 on the previous line ------ test module TestCase where import Test.Hspec main::IO() main = hspec $ do describe "TestCase" $ do it "case 1 - pass" $ do result1 1 `shouldBe` "one" it "case 2 - fail" $ do result1 2 `shouldBe` "two" where a1 = 2 result1 x = case x of a1 -> "one" 2 -> "two" From imantc at gmail.com Tue Jul 7 10:28:58 2015 From: imantc at gmail.com (Imants Cekusins) Date: Tue, 7 Jul 2015 12:28:58 +0200 Subject: [Haskell-beginners] case statement In-Reply-To: References: Message-ID: ok with a small tweak I can see "case" a1 value is x: result1 x = case x of a1 -> trace (show a1) "one" 2 -> "two" From daniel.trstenjak at gmail.com Tue Jul 7 10:36:04 2015 From: daniel.trstenjak at gmail.com (Daniel Trstenjak) Date: Tue, 7 Jul 2015 12:36:04 +0200 Subject: [Haskell-beginners] case statement In-Reply-To: References: Message-ID: <20150707103604.GA13608@brick> Hi Imants, On Tue, Jul 07, 2015 at 12:28:58PM +0200, Imants Cekusins wrote: > ok with a small tweak I can see "case" a1 value is x: > > result1 x = case x of > a1 -> trace (show a1) "one" > 2 -> "two" 'a1' is new variable which is always bound to the value of 'x' and this case is always matching. You should also get a warning for this: Warning: Pattern match(es) are overlapped In a case alternative: 2 -> ... Greetings, Daniel From imantc at gmail.com Tue Jul 7 10:46:25 2015 From: imantc at gmail.com (Imants Cekusins) Date: Tue, 7 Jul 2015 12:46:25 +0200 Subject: [Haskell-beginners] case statement In-Reply-To: <20150707103604.GA13608@brick> References: <20150707103604.GA13608@brick> Message-ID: > 'a1' is new variable Thank you Daniel! is there a way to "freeze" outside variables into constants which can be used as "case" statement patterns? for example if I use "if", the below test passes. It would be handy to use case statement instead of multiple ifs or guards main::IO() main = hspec $ do describe "TestCase" $ do it "case 1 - pass" $ do result1 1 `shouldBe` "one" it "case 2 - pass" $ do result1 2 `shouldBe` "two" where result1 x = if x == a1 then "one" else if x == a2 then "two" else "three" where a1 = 1 a2 = 2 From daniel.trstenjak at gmail.com Tue Jul 7 11:51:17 2015 From: daniel.trstenjak at gmail.com (Daniel Trstenjak) Date: Tue, 7 Jul 2015 13:51:17 +0200 Subject: [Haskell-beginners] case statement In-Reply-To: References: <20150707103604.GA13608@brick> Message-ID: <20150707115117.GA14962@brick> Hi Imants, On Tue, Jul 07, 2015 at 12:46:25PM +0200, Imants Cekusins wrote: > is there a way to "freeze" outside variables into constants which can > be used as "case" statement patterns? I don't think so. > result1 x = if x == a1 then "one" > else if x == a2 then "two" > else "three" > where a1 = 1 > a2 = 2 There're several other ways to solve this: result1 1 = "one" result1 2 = "two" result1 _ = "three" Or: result1 x | x == 1 = "one" | x == 2 = "two" | _ = "three" Greetings, Daniel From imantc at gmail.com Tue Jul 7 12:04:34 2015 From: imantc at gmail.com (Imants Cekusins) Date: Tue, 7 Jul 2015 14:04:34 +0200 Subject: [Haskell-beginners] case statement In-Reply-To: <20150707115117.GA14962@brick> References: <20150707103604.GA13608@brick> <20150707115117.GA14962@brick> Message-ID: > There're several other ways to solve this: Thank you. You are right, GHC warns about shadowed variables. This "case" behaviour (patterns allow no access to outer scope variables) is different from some other languages. Well, I'll remember this from now on. From allbery.b at gmail.com Tue Jul 7 13:24:56 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Tue, 7 Jul 2015 09:24:56 -0400 Subject: [Haskell-beginners] case statement In-Reply-To: References: <20150707103604.GA13608@brick> <20150707115117.GA14962@brick> Message-ID: On Tue, Jul 7, 2015 at 8:04 AM, Imants Cekusins wrote: > This "case" behaviour (patterns allow no access to outer scope > variables) is different from some other languages. > In most functional languages, "case" is about structure, not values. You specify the structure in terms of constructors, which must be literal. Variables in patterns always capture values associated with those constructors, never to values outside the case expression. That said, doing a value-based comparison ("switch"-type construct) is rather annoying, and most of Haskell's (and ghc extension) mechanisms only reduce the pain somewhat. :/ -- 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 imantc at gmail.com Tue Jul 7 14:06:47 2015 From: imantc at gmail.com (Imants Cekusins) Date: Tue, 7 Jul 2015 16:06:47 +0200 Subject: [Haskell-beginners] case statement In-Reply-To: References: <20150707103604.GA13608@brick> <20150707115117.GA14962@brick> Message-ID: Thank you Brandon. Well in Erlang you can mix and match patterns with outer scope variables. It is very handy, I agree. Here is an example. You can try this code in browser here: http://tryerl.seriyps.ru/#id=e3f2 % -*- coding: utf8 -*- -module(main). -export([main/0]). main() -> check(2), check({other,4}). check(X)-> A1 = 1, A2 = 2, case X of A1 -> io:format("A1~n"); A2 -> io:format("A2~n"); {other,X1} -> io:format("~p~n",[X1]) end. From imantc at gmail.com Tue Jul 7 18:15:46 2015 From: imantc at gmail.com (Imants Cekusins) Date: Tue, 7 Jul 2015 20:15:46 +0200 Subject: [Haskell-beginners] Loch package builds? Message-ID: Did anyone try to install loch package recently: https://wiki.haskell.org/Debugging#Source-located_errors This error comes up on install: Debug/Trace/Location.hs:70:8: Expecting one more argument to ?C.Exception? Expected a type, but ?C.Exception? has kind ?* -> Constraint? In the type signature for ?ppr?: ppr :: C.Exception -> String Failed to install loch-0.2 cabal: Error: some packages failed to install: loch-0.2 failed during the building phase. The exception was: ExitFailure 1 ? From allbery.b at gmail.com Tue Jul 7 18:19:34 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Tue, 7 Jul 2015 14:19:34 -0400 Subject: [Haskell-beginners] Loch package builds? In-Reply-To: References: Message-ID: On Tue, Jul 7, 2015 at 2:15 PM, Imants Cekusins wrote: > Did anyone try to install loch package recently: It's from 2007 with no updates, and that error indicates that it's using old-style exceptions. -- 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 imantc at gmail.com Tue Jul 7 18:32:28 2015 From: imantc at gmail.com (Imants Cekusins) Date: Tue, 7 Jul 2015 20:32:28 +0200 Subject: [Haskell-beginners] Loch package builds? In-Reply-To: References: Message-ID: Thank you Brandon. loch-th seems to be more recent. I'll try that From imantc at gmail.com Thu Jul 9 14:32:52 2015 From: imantc at gmail.com (Imants Cekusins) Date: Thu, 9 Jul 2015 16:32:52 +0200 Subject: [Haskell-beginners] -fglasgow-exts in .cabal Message-ID: How to specify defaultExtensions in cabal (1.22) file? e.g. -fglasgow-exts or TypeSynonymInstances ? From sumit.sahrawat.apm13 at iitbhu.ac.in Thu Jul 9 15:35:43 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Thu, 9 Jul 2015 21:05:43 +0530 Subject: [Haskell-beginners] -fglasgow-exts in .cabal In-Reply-To: References: Message-ID: https://www.haskell.org/cabal/users-guide/developing-packages.html might help. On 9 July 2015 at 20:02, Imants Cekusins wrote: > How to specify defaultExtensions in cabal (1.22) file? > > e.g. > -fglasgow-exts or > TypeSynonymInstances > > ? > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Thu Jul 9 16:02:34 2015 From: imantc at gmail.com (Imants Cekusins) Date: Thu, 9 Jul 2015 18:02:34 +0200 Subject: [Haskell-beginners] -fglasgow-exts in .cabal In-Reply-To: References: Message-ID: Thank you Sumit. This is how far I got: if I put this right after hs-source-dirs: default-extensions: FlexibleInstances , it works: ghc asks for MultiParamTypeClasses option. However if I add FlexibleInstances, MultiParamTypeClasses - either separated with comma or on the next line, the compiler parses .cabal and tries to build however prompts for FlexibleInstances again. How would I specify >1 option? From sumit.sahrawat.apm13 at iitbhu.ac.in Thu Jul 9 16:04:51 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Thu, 9 Jul 2015 21:34:51 +0530 Subject: [Haskell-beginners] -fglasgow-exts in .cabal In-Reply-To: References: Message-ID: I used to take a look at cabal files from projects that I've used and found to work. For example, IHaskell uses a lot of extensions [1]. [1]: https://github.com/gibiansky/IHaskell/blob/master/ihaskell.cabal#L122-L126 On 9 July 2015 at 21:32, Imants Cekusins wrote: > Thank you Sumit. > > This is how far I got: > > if I put this right after hs-source-dirs: > > default-extensions: FlexibleInstances > > , it works: ghc asks for MultiParamTypeClasses option. > > However if I add FlexibleInstances, MultiParamTypeClasses > - either separated with comma or on the next line, the compiler parses > .cabal and tries to build however prompts for FlexibleInstances again. > > How would I specify >1 option? > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Thu Jul 9 16:18:13 2015 From: imantc at gmail.com (Imants Cekusins) Date: Thu, 9 Jul 2015 18:18:13 +0200 Subject: [Haskell-beginners] -fglasgow-exts in .cabal In-Reply-To: References: Message-ID: Cheers Sumit. it worked: default-extensions: FlexibleInstances MultiParamTypeClasses TypeSynonymInstances needed to run cabal clean, then cabal build. this needs to be specified in both library & test-suite spec section hope this helps someone. From stf.list.haskell at eisenbits.com Fri Jul 10 11:49:24 2015 From: stf.list.haskell at eisenbits.com (Stanislaw Findeisen) Date: Fri, 10 Jul 2015 13:49:24 +0200 Subject: [Haskell-beginners] cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 Message-ID: <559FB144.4050009@eisenbits.com> Hi Could anyone explain this to me, please? $ cabal install snap-server-0.9.5.1 Resolving dependencies... Configuring snap-server-0.9.5.1... cabal: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 cabal: Error: some packages failed to install: snap-server-0.9.5.1 failed during the configure step. The exception was: ExitFailure 1 Where does this unsatisfiable dependency come from? snap-server-0.9.5.1 seems to require just attoparsec (>=0.10 && <0.14): http://hackage.haskell.org/package/snap-server-0.9.5.1 . And attoparsec 0.13.0.1 is already installed: $ cabal list --installed attoparsec * attoparsec Synopsis: Fast combinator parsing for bytestrings and text Default available version: 0.13.0.1 Installed versions: 0.13.0.1 Homepage: https://github.com/bos/attoparsec License: BSD3 * attoparsec-enumerator Synopsis: Pass input from an enumerator to an Attoparsec parser. Default available version: 0.3.4 Installed versions: 0.3.4 Homepage: https://john-millikin.com/software/attoparsec-enumerator/ License: MIT I am trying to install hakyll 4.6.*, and snap-server seems to be one of the requirements. Hakyll 4.6.* is an old version but AFAIR I need that due to conflicting versions of containers. Thanks! -- http://people.eisenbits.com/~stf/ http://www.eisenbits.com/ OpenPGP: 9EC2 5620 2355 B1DC 4A8F 8C79 0EC7 C214 E5AE 3B4E -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From imantc at gmail.com Fri Jul 10 12:14:33 2015 From: imantc at gmail.com (Imants Cekusins) Date: Fri, 10 Jul 2015 14:14:33 +0200 Subject: [Haskell-beginners] cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: <559FB144.4050009@eisenbits.com> References: <559FB144.4050009@eisenbits.com> Message-ID: > snap-server-0.9.5.1 failed during the configure step. just a guess: ________ https://hackage.haskell.org/package/snap-server-0.9.5.1/src/snap-server.cabal attoparsec >= 0.10 && < 0.13, ________ this line seems odd: attoparsec >=0.10 && <0.13 && ==0.13.0.1 particularly this part: <0.13 && ==0.13.0.1 maybe try to use sandbox? From stf.list.haskell at eisenbits.com Fri Jul 10 12:25:13 2015 From: stf.list.haskell at eisenbits.com (Stanislaw Findeisen) Date: Fri, 10 Jul 2015 14:25:13 +0200 Subject: [Haskell-beginners] cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: References: <559FB144.4050009@eisenbits.com> Message-ID: <559FB9A9.3090301@eisenbits.com> On 2015-07-10 14:14, Imants Cekusins wrote: > https://hackage.haskell.org/package/snap-server-0.9.5.1/src/snap-server.cabal > > attoparsec >= 0.10 && < 0.13, But this: https://hackage.haskell.org/package/snap-server-0.9.5.1/snap-server.cabal (no "src/" here) says: attoparsec >= 0.10 && < 0.14, WTF?!? Shouldn't these 2 files be the same? -- http://people.eisenbits.com/~stf/ http://www.eisenbits.com/ OpenPGP: 9EC2 5620 2355 B1DC 4A8F 8C79 0EC7 C214 E5AE 3B4E -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From vlatko.basic at gmail.com Fri Jul 10 12:32:31 2015 From: vlatko.basic at gmail.com (Vlatko Basic) Date: Fri, 10 Jul 2015 14:32:31 +0200 Subject: [Haskell-beginners] cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: <559FB144.4050009@eisenbits.com> References: <559FB144.4050009@eisenbits.com> Message-ID: <559FBB5F.3040709@gmail.com> Most of such problems can be solved with LTS (Long Term Support) from Stackage. https://www.stackage.org/ Take a look. -------- Original Message -------- Subject: [Haskell-beginners] cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 From: Stanislaw Findeisen To: beginners at haskell.org Date: 10/07/15 13:49 > Hi > > Could anyone explain this to me, please? > > $ cabal install snap-server-0.9.5.1 > Resolving dependencies... > Configuring snap-server-0.9.5.1... > cabal: At least the following dependencies are missing: > attoparsec >=0.10 && <0.13 && ==0.13.0.1 > cabal: Error: some packages failed to install: > snap-server-0.9.5.1 failed during the configure step. The exception was: > ExitFailure 1 > > Where does this unsatisfiable dependency come from? snap-server-0.9.5.1 > seems to require just attoparsec (>=0.10 && <0.14): > http://hackage.haskell.org/package/snap-server-0.9.5.1 . And attoparsec > 0.13.0.1 is already installed: > > $ cabal list --installed attoparsec > * attoparsec > Synopsis: Fast combinator parsing for bytestrings and text > Default available version: 0.13.0.1 > Installed versions: 0.13.0.1 > Homepage: https://github.com/bos/attoparsec > License: BSD3 > > * attoparsec-enumerator > Synopsis: Pass input from an enumerator to an Attoparsec parser. > Default available version: 0.3.4 > Installed versions: 0.3.4 > Homepage: https://john-millikin.com/software/attoparsec-enumerator/ > License: MIT > > I am trying to install hakyll 4.6.*, and snap-server seems to be one of > the requirements. Hakyll 4.6.* is an old version but AFAIR I need that > due to conflicting versions of containers. > > Thanks! > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From imantc at gmail.com Fri Jul 10 12:36:46 2015 From: imantc at gmail.com (Imants Cekusins) Date: Fri, 10 Jul 2015 14:36:46 +0200 Subject: [Haskell-beginners] cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: <559FB9A9.3090301@eisenbits.com> References: <559FB144.4050009@eisenbits.com> <559FB9A9.3090301@eisenbits.com> Message-ID: > attoparsec >= 0.10 && < 0.14, you could try to change the source cabal file or you could use cabal sandbox. Sandboxes are easy. They allow to install exact versions required by the package. Take a look: http://coldwa.st/e/blog/2013-08-20-Cabal-sandbox.html From imantc at gmail.com Fri Jul 10 13:30:40 2015 From: imantc at gmail.com (Imants Cekusins) Date: Fri, 10 Jul 2015 15:30:40 +0200 Subject: [Haskell-beginners] cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: <559FBB5F.3040709@gmail.com> References: <559FB144.4050009@eisenbits.com> <559FBB5F.3040709@gmail.com> Message-ID: > Stackage Cheers Vlatko I was not aware of this initiative. Learnt something new today. From vlatko.basic at gmail.com Fri Jul 10 13:55:54 2015 From: vlatko.basic at gmail.com (Vlatko Basic) Date: Fri, 10 Jul 2015 15:55:54 +0200 Subject: [Haskell-beginners] cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: References: <559FB144.4050009@eisenbits.com> <559FBB5F.3040709@gmail.com> Message-ID: <559FCEEA.3020605@gmail.com> There is also a stack tool, new tool that might be considered a cabal replacement, developed for solving install problems, and much more. You might find it interesting. It is stable now and has very active community. https://github.com/commercialhaskell/stack It might be worth spending some time and master it. -------- Original Message -------- Subject: Re: [Haskell-beginners] cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 From: Imants Cekusins To: vlatko.basic at gmail.com, The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell Date: 10/07/15 15:30 >> Stackage > > Cheers Vlatko > > I was not aware of this initiative. Learnt something new today. > From imantc at gmail.com Fri Jul 10 14:30:02 2015 From: imantc at gmail.com (Imants Cekusins) Date: Fri, 10 Jul 2015 16:30:02 +0200 Subject: [Haskell-beginners] Fwd: cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: References: <559FB144.4050009@eisenbits.com> <559FBB5F.3040709@gmail.com> <559FCEEA.3020605@gmail.com> Message-ID: > There is also a stack tool, Thank you. It is very interesting. Why were new tools introduced instead of adding new functionality to cabal? A mix of packaging tools may lead to confusion. From bo.bjornsen at gmail.com Fri Jul 10 14:34:49 2015 From: bo.bjornsen at gmail.com (=?UTF-8?B?QmrDuHJuIMOYaXZpbmQgQmrDuHJuc2Vu?=) Date: Fri, 10 Jul 2015 16:34:49 +0200 Subject: [Haskell-beginners] Fwd: cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: References: <559FB144.4050009@eisenbits.com> <559FBB5F.3040709@gmail.com> <559FCEEA.3020605@gmail.com> Message-ID: <559FD809.9070209@gmail.com> On 10/07/15 16:30, Imants Cekusins wrote: >> There is also a stack tool, > > Thank you. It is very interesting. > > Why were new tools introduced instead of adding new functionality to cabal? > > A mix of packaging tools may lead to confusion. Hi, There is a blog post over at FP complete that attempts to answer these questions: https://www.fpcomplete.com/blog/2015/06/why-is-stack-not-cabal Bj?rn ?ivind -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: OpenPGP digital signature URL: From imantc at gmail.com Fri Jul 10 14:48:20 2015 From: imantc at gmail.com (Imants Cekusins) Date: Fri, 10 Jul 2015 16:48:20 +0200 Subject: [Haskell-beginners] Fwd: cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: <559FD809.9070209@gmail.com> References: <559FB144.4050009@eisenbits.com> <559FBB5F.3040709@gmail.com> <559FCEEA.3020605@gmail.com> <559FD809.9070209@gmail.com> Message-ID: Thank you very much Bj?rn. Are Stackage packages - a subset of Hackage packages? Do packages get uploaded to Hackage and then get transferred to Stackage? It would be nice to agree to merge Hackage & Stackage, cabal-install & stack one day. Without this merge the "DLL-mess" might get worse. From allbery.b at gmail.com Fri Jul 10 14:56:00 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Fri, 10 Jul 2015 10:56:00 -0400 Subject: [Haskell-beginners] Fwd: cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: References: <559FB144.4050009@eisenbits.com> <559FBB5F.3040709@gmail.com> <559FCEEA.3020605@gmail.com> <559FD809.9070209@gmail.com> Message-ID: On Fri, Jul 10, 2015 at 10:48 AM, Imants Cekusins wrote: > Are Stackage packages - a subset of Hackage packages? Do packages get > uploaded to Hackage and then get transferred to Stackage? > Stackage is a curated subset of Hackage. (Sadly, the main criterion for curation is "works with Yesod", so you get to take your chances if you're not using Yesod.) It's more an alternative to the Haskell Platform, since Yesod always wants newer stuff. (De facto the Haskell Platform is irrelevant, since everyone is rushing pell-mell to tie themselves to Yesod via Stackage. We're Ruby now! When the ecosystem is defined by a web platform, the ecosystem *becomes* the web platform. This might even work for you; for me, it's a cliff rushing ever closer.) -- 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 bo.bjornsen at gmail.com Fri Jul 10 14:57:15 2015 From: bo.bjornsen at gmail.com (=?UTF-8?B?QmrDuHJuIMOYaXZpbmQgQmrDuHJuc2Vu?=) Date: Fri, 10 Jul 2015 16:57:15 +0200 Subject: [Haskell-beginners] Fwd: cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: References: <559FB144.4050009@eisenbits.com> <559FBB5F.3040709@gmail.com> <559FCEEA.3020605@gmail.com> <559FD809.9070209@gmail.com> Message-ID: <559FDD4B.4010303@gmail.com> On 10/07/15 16:48, Imants Cekusins wrote: > Thank you very much Bj?rn. > > Are Stackage packages - a subset of Hackage packages? Do packages get > uploaded to Hackage and then get transferred to Stackage? > > It would be nice to agree to merge Hackage & Stackage, cabal-install & > stack one day. Without this merge the "DLL-mess" might get worse. My experience from playing around with stack the last couple of nights have been that Stackage is indeed a subset of Hackage packages, but that it is possible (and fairly easy - if not very documented) to use packages from Hackage with stack as well. One caveat - depending on how you look at it - is that you end up specifying these packages with specific versions in the stack.yaml file for your project. I personally believe that both a curated subset of "known good" packages like Stackage and the complete set of packages like Hackage can co-exist to their mutual benefit. I can certainly see the appeal of stack - I rather like it so far. Bj?rn ?ivind -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: OpenPGP digital signature URL: From imantc at gmail.com Fri Jul 10 15:06:43 2015 From: imantc at gmail.com (Imants Cekusins) Date: Fri, 10 Jul 2015 17:06:43 +0200 Subject: [Haskell-beginners] Fwd: cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: <559FDD4B.4010303@gmail.com> References: <559FB144.4050009@eisenbits.com> <559FBB5F.3040709@gmail.com> <559FCEEA.3020605@gmail.com> <559FD809.9070209@gmail.com> <559FDD4B.4010303@gmail.com> Message-ID: Well if Stackage packages ? Hackage packages, there is choice: If you need the added benefits Stackage gives, "upgrade". Otherwise can stay with Hackage. ? From bo.bjornsen at gmail.com Fri Jul 10 15:20:21 2015 From: bo.bjornsen at gmail.com (=?UTF-8?B?QmrDuHJuIMOYaXZpbmQgQmrDuHJuc2Vu?=) Date: Fri, 10 Jul 2015 17:20:21 +0200 Subject: [Haskell-beginners] Fwd: cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: References: <559FB144.4050009@eisenbits.com> <559FBB5F.3040709@gmail.com> <559FCEEA.3020605@gmail.com> <559FD809.9070209@gmail.com> <559FDD4B.4010303@gmail.com> Message-ID: <559FE2B5.3020404@gmail.com> On 10/07/15 17:06, Imants Cekusins wrote: > Well if Stackage packages ? Hackage packages, there is choice: > > If you need the added benefits Stackage gives, "upgrade". Otherwise > can stay with Hackage. > > ? There's nothing stopping you from using Stackage in addition to Hackage. As an example, I used stack to create a new app-skeleton last night. One of the packages I wanted to use was the FFT package not available in Stackage. I just added it to the .cabal file, and ran "stack solver": % stack solver This command is not guaranteed to give you a perfect build plan It's possible that even with the changes generated below, you will still need to do some manual tweaking Asking cabal to calculate a build plan, please wait flags: carray: bytestringinbase: false extra-deps: - carray-0.1.5.2 - fft-0.1.8.1 - ix-shapable-0.1.0 Resulting in the following stack.yaml file: % cat stack.yaml flags: carray: bytestringinbase: false packages: - '.' extra-deps: - carray-0.1.5.2 - fft-0.1.8.1 - ix-shapable-0.1.0 resolver: nightly-2015-07-08 When building using "stack build", it automatically downloaded, configured and installed all my dependencies. No worrying about sandboxes (because stack handles this gracefully by default as far as I can tell) and no problems getting this simple skeleton up and running. Note that I used the nightly resolver simply because I wanted to use GHC 7.10 which I already had installed. There are multiple resolvers available (for GHC 7.8 and an LTS version with GHC 7.10 looks to arrive shortly after GHC 7.10.2 has been released: https://groups.google.com/forum/#!topic/stackage/Ux7ideofwIA) Bj?rn ?ivind -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: OpenPGP digital signature URL: From imantc at gmail.com Fri Jul 10 15:33:41 2015 From: imantc at gmail.com (Imants Cekusins) Date: Fri, 10 Jul 2015 17:33:41 +0200 Subject: [Haskell-beginners] Fwd: cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: <559FE2B5.3020404@gmail.com> References: <559FB144.4050009@eisenbits.com> <559FBB5F.3040709@gmail.com> <559FCEEA.3020605@gmail.com> <559FD809.9070209@gmail.com> <559FDD4B.4010303@gmail.com> <559FE2B5.3020404@gmail.com> Message-ID: .. does stack also allow to reference local packages (not on Hackage)? I just began to learn cabal so maybe it is early for me to switch to stack yet. One thing at a time :) From bo.bjornsen at gmail.com Fri Jul 10 15:38:55 2015 From: bo.bjornsen at gmail.com (=?UTF-8?B?QmrDuHJuIMOYaXZpbmQgQmrDuHJuc2Vu?=) Date: Fri, 10 Jul 2015 17:38:55 +0200 Subject: [Haskell-beginners] Fwd: cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: References: <559FB144.4050009@eisenbits.com> <559FBB5F.3040709@gmail.com> <559FCEEA.3020605@gmail.com> <559FD809.9070209@gmail.com> <559FDD4B.4010303@gmail.com> <559FE2B5.3020404@gmail.com> Message-ID: <559FE70F.6030802@gmail.com> On 10/07/15 17:33, Imants Cekusins wrote: > .. does stack also allow to reference local packages (not on Hackage)? > > I just began to learn cabal so maybe it is early for me to switch to > stack yet. One thing at a time :) I believe so, but I have not tried it yet. Check out the wiki on Github: https://github.com/commercialhaskell/stack/wiki/FAQ#i-need-to-use-a-package-or-version-of-a-package-that-is-not-available-on-hackage-what-should-i-do Maybe that works for you? I must admit that I am still quite green at Haskell infrastructure/tooling stuff, but I have still had a fair amount of trouble with cabal-install, so trying stack was a no-brainer for me at least :) Bj?rn ?ivind -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: OpenPGP digital signature URL: From michael at snoyman.com Fri Jul 10 15:49:05 2015 From: michael at snoyman.com (Michael Snoyman) Date: Fri, 10 Jul 2015 15:49:05 +0000 Subject: [Haskell-beginners] Fwd: cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: <559FE70F.6030802@gmail.com> References: <559FB144.4050009@eisenbits.com> <559FBB5F.3040709@gmail.com> <559FCEEA.3020605@gmail.com> <559FD809.9070209@gmail.com> <559FDD4B.4010303@gmail.com> <559FE2B5.3020404@gmail.com> <559FE70F.6030802@gmail.com> Message-ID: If you have questions getting started, feel free to ask them over on the stack mailing list[1], you'll find many very helpful people over there. >From quickly scanning this thread, I don't see any use cases that aren't handled well by stack, but I'd rather not spam the beginner mailing list with details of how to make it all happen. I would also recommend reading the wiki pages, which give quite a bit of information on various use cases. [1] https://groups.google.com/d/forum/haskell-stack On Fri, Jul 10, 2015 at 8:39 AM Bj?rn ?ivind Bj?rnsen wrote: > On 10/07/15 17:33, Imants Cekusins wrote: > > .. does stack also allow to reference local packages (not on Hackage)? > > > > I just began to learn cabal so maybe it is early for me to switch to > > stack yet. One thing at a time :) > > I believe so, but I have not tried it yet. > Check out the wiki on Github: > > https://github.com/commercialhaskell/stack/wiki/FAQ#i-need-to-use-a-package-or-version-of-a-package-that-is-not-available-on-hackage-what-should-i-do > > Maybe that works for you? > > I must admit that I am still quite green at Haskell > infrastructure/tooling stuff, but I have still had a fair amount of > trouble with cabal-install, so trying stack was a no-brainer for me at > least :) > > Bj?rn ?ivind > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From amindfv at gmail.com Fri Jul 10 18:47:07 2015 From: amindfv at gmail.com (amindfv at gmail.com) Date: Fri, 10 Jul 2015 14:47:07 -0400 Subject: [Haskell-beginners] cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: <559FB9A9.3090301@eisenbits.com> References: <559FB144.4050009@eisenbits.com> <559FB9A9.3090301@eisenbits.com> Message-ID: It looks like the package bounds were changed on hackage though. Your install will probably work with an empty sandbox. Also try asking #snapframework on freenode -- they're very helpful! Tom El Jul 10, 2015, a las 8:25, Stanislaw Findeisen escribi?: > On 2015-07-10 14:14, Imants Cekusins wrote: >> https://hackage.haskell.org/package/snap-server-0.9.5.1/src/snap-server.cabal >> >> attoparsec >= 0.10 && < 0.13, > > But this: > https://hackage.haskell.org/package/snap-server-0.9.5.1/snap-server.cabal (no > "src/" here) says: > > attoparsec >= 0.10 && < 0.14, > > WTF?!? > > Shouldn't these 2 files be the same? > > -- > http://people.eisenbits.com/~stf/ > http://www.eisenbits.com/ > > OpenPGP: 9EC2 5620 2355 B1DC 4A8F 8C79 0EC7 C214 E5AE 3B4E > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From rene.klacan at gmail.com Sat Jul 11 12:16:36 2015 From: rene.klacan at gmail.com (=?UTF-8?B?UmVuw6kgS2xhxI1hbg==?=) Date: Sat, 11 Jul 2015 14:16:36 +0200 Subject: [Haskell-beginners] Monad problem Message-ID: Hi all, I've been trying to create working example with "ig" https://hackage.haskell.org/package/ig-0.2.2 - library over instagram API and I am facing little monad problem. Can someone advise me please how to make this small piece of code work? {-# LANGUAGE OverloadedStrings #-} import Network.HTTP.Client import Instagram code = "xxx_some_code" redirectUrl = "http://localhost:9988/instagram/oauth2/callback" credentials = Credentials "xxx_some_api_id" "xxx_some_api_secret" main :: IO () main = do manager <- newManager defaultManagerSettings token <- runInstagramT credentials manager $ getUserAccessTokenURL2 redirectUrl code print token I am getting following error: src/Main.hs:14:9: No instance for (Control.Monad.Trans.Resource.Internal.MonadResource IO) arising from a use of ?getUserAccessTokenURL2? In the second argument of ?($)?, namely ?getUserAccessTokenURL2 redirectUrl code? In a stmt of a 'do' block: token <- runInstagramT credentials manager $ getUserAccessTokenURL2 redirectUrl code In the expression: do { manager <- newManager defaultManagerSettings; token <- runInstagramT credentials manager $ getUserAccessTokenURL2 redirectUrl code; print token } Thanks Rene -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at redivi.com Sat Jul 11 17:52:34 2015 From: bob at redivi.com (Bob Ippolito) Date: Sat, 11 Jul 2015 10:52:34 -0700 Subject: [Haskell-beginners] Monad problem In-Reply-To: References: Message-ID: Great question! Many libraries use a monad transformer stack on top of IO rather than a direct IO interface. This can be convenient if you are also using such a stack, but it certainly complicates things a bit if you're just in IO directly. If you follow the error messages it says that it's expecting your Monad to have an instance of MonadResource. IO does not (or else it would've just worked). This means that you'll need to find a monad transformer that provides MonadResource. By looking at the name " Control.Monad.Trans.Resource.Internal.MonadResource" I know that I should probably start looking for something called "Control.Monad.Trans.Resource". After a bit of searching on Hackage I found http://hackage.haskell.org/package/resourcet The relevant function is `runResourceT` (most monad transformers are going to have a similarly named run function to "unwrap" a transformer): http://hackage.haskell.org/package/resourcet-1.1.5/docs/Control-Monad-Trans-Resource.html#v:runResourceT Something like this should compile: {-# LANGUAGE OverloadedStrings #-} import Network.HTTP.Client import Instagram import Control.Monad.Trans.Resource code = "xxx_some_code" redirectUrl = "http://localhost:9988/instagram/oauth2/callback" credentials = Credentials "xxx_some_api_id" "xxx_some_api_secret" main :: IO () main = do manager <- newManager defaultManagerSettings token <- runResourceT . runInstagramT credentials manager $ getUserAccessTokenURL2 redirectUrl code print token On Sat, Jul 11, 2015 at 5:16 AM, Ren? Kla?an wrote: > Hi all, > > I've been trying to create working example with "ig" > https://hackage.haskell.org/package/ig-0.2.2 - library over instagram API > and I am facing little monad problem. > > Can someone advise me please how to make this small piece of code work? > > {-# LANGUAGE OverloadedStrings #-} > > import Network.HTTP.Client > import Instagram > > code = "xxx_some_code" > redirectUrl = "http://localhost:9988/instagram/oauth2/callback" > credentials = Credentials "xxx_some_api_id" "xxx_some_api_secret" > > main :: IO () > main = do > manager <- newManager defaultManagerSettings > token <- runInstagramT credentials manager $ > getUserAccessTokenURL2 redirectUrl code > print token > > > > I am getting following error: > > > src/Main.hs:14:9: > No instance for (Control.Monad.Trans.Resource.Internal.MonadResource > IO) > arising from a use of ?getUserAccessTokenURL2? > In the second argument of ?($)?, namely > ?getUserAccessTokenURL2 redirectUrl code? > In a stmt of a 'do' block: > token <- runInstagramT credentials manager > $ getUserAccessTokenURL2 redirectUrl code > In the expression: > do { manager <- newManager defaultManagerSettings; > token <- runInstagramT credentials manager > $ getUserAccessTokenURL2 redirectUrl code; > print token } > > > > Thanks > > Rene > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Sat Jul 11 18:41:25 2015 From: imantc at gmail.com (Imants Cekusins) Date: Sat, 11 Jul 2015 20:41:25 +0200 Subject: [Haskell-beginners] Monad problem In-Reply-To: References: Message-ID: > Many libraries use a monad transformer stack on top of IO rather than a direct IO interface. Does this mean that they do not perform IO, or do IO but "break out of" / hide their IO using unsafe or something? if we tried to call runInstagramT from a regular (non-IO) "do", would it have worked without runResourceT? From marcin.jan.mrotek at gmail.com Sat Jul 11 19:09:54 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Sat, 11 Jul 2015 21:09:54 +0200 Subject: [Haskell-beginners] Monad problem In-Reply-To: References: Message-ID: Hello, > Does this mean that they do not perform IO, or do IO but "break out of" / hide their IO using unsafe or something? No, monad transformers sort of compose "backwards", that is, if you have something like FooT (BarT (IO a)) then after running everything, you'll get something in the lines of IO (Bar (Foo a)). That's why IO, if it is there at all, must be at the bottom of the stack. Now, I don't know the library you're using, from the docs it would appear that you indeed can runInstagramT without any IO in there, but some of the actions defined force this or that constraint, and in particular this "getUserAccessTokenURL2" forces (MonadControlBase IO m), which is more or less a fancy way of saying that there must be IO at the bottom. Best regards, Marcin Mrotek From rene.klacan at gmail.com Sat Jul 11 20:42:27 2015 From: rene.klacan at gmail.com (=?UTF-8?B?UmVuw6kgS2xhxI1hbg==?=) Date: Sat, 11 Jul 2015 22:42:27 +0200 Subject: [Haskell-beginners] Monad problem In-Reply-To: References: Message-ID: Bob Ippolito, thank you for great explanation! Your suggestion is working. Marcin Mrotek, thank you for additional info. On Sat, Jul 11, 2015 at 9:09 PM, Marcin Mrotek wrote: > Hello, > > > Does this mean that they do not perform IO, or do IO but "break out > of" / hide their IO using unsafe or something? > > No, monad transformers sort of compose "backwards", that is, if you > have something like FooT (BarT (IO a)) then after running everything, > you'll get something in the lines of IO (Bar (Foo a)). That's why IO, > if it is there at all, must be at the bottom of the stack. > > Now, I don't know the library you're using, from the docs it would > appear that you indeed can runInstagramT without any IO in there, but > some of the actions defined force this or that constraint, and in > particular this "getUserAccessTokenURL2" forces (MonadControlBase IO > m), which is more or less a fancy way of saying that there must be IO > at the bottom. > > Best regards, > Marcin Mrotek > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From marcin.jan.mrotek at gmail.com Sun Jul 12 07:39:05 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Sun, 12 Jul 2015 09:39:05 +0200 Subject: [Haskell-beginners] Monad problem In-Reply-To: References: Message-ID: Imants Cekusins, Well using monad transformers like that is a fairly common design pattern in Haskell, so I think you should get used to it ;) But you don't really need to understand monad transformers in depth just to use the ig library, it appears that all actions defined there have a type like :: (MonadBaseControl IO m, MonadResource m) => _ some arguments _ -> InstagramT m _result_ The smallest monad that satisfies both (MonadBaseControl IO m) and (MonadResource m) is just (ResourceT IO), so the code suggested by Bob Ippolito token <- runResourceT . runInstagramT credentials manager $ getUserAccessTokenURL2 redirectUrl code works, because "getUserAccessTokenURL2 redirectUrl code" has type "InstagramT (ResourceT IO) OAuthToken". It is one of Haskell's features that the actual concrete type of an expression is inferred according to the context in which it appears, and thus may vary. * The whole thing starts with the type "MonadBaseControl IO m, MonadResource m => InstagramT m OAuthToken" * runInstagramT strips the InstagramT layer, leaving "MonadBaseControl IO m, MonadResource m =>m OAuthToken" * runResourceT has type "MonadBaseControl IO m => ResourceT m a -> m a", so Haskell infers that the "m OAuthToken" above is actually "MonadBaseControl IO m => ResourceT m OAuthToken". The satisfaction of the MonadResource constraint is provided by the ResouceT layer itself, which is stripped by runResourceT then. * at the end, Haskell is left with "MonadBaseControl IO m => m OAuthToken", which it tries to unify with "IO something", because you're using it in the do block of main, that must have the type IO () in the end. As "IO OAuthToken" does satisfy this constraint, everything is fine. The library uses type classes instead of this concrete type, because some users might want to supply a more complicated monad transformer stack than that, but of course you don't actually have to do this. Best regards, Marcin Mrotek From imantc at gmail.com Sun Jul 12 07:59:38 2015 From: imantc at gmail.com (Imants Cekusins) Date: Sun, 12 Jul 2015 09:59:38 +0200 Subject: [Haskell-beginners] Monad problem In-Reply-To: References: Message-ID: Cheers Marcin, One more question: MonadBaseControl IO m, MonadResource m => getUserAccessTokenURL2 however Monad m => getUserAccessTokenURL1 if we used getUserAccessTokenURL1, would we be able to access result "a" (Text in this case) with: token <- runInstagramT ... ? From marcin.jan.mrotek at gmail.com Sun Jul 12 08:21:50 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Sun, 12 Jul 2015 10:21:50 +0200 Subject: [Haskell-beginners] Monad problem In-Reply-To: References: Message-ID: Yes, apparently the getUserAccessTokenURL1 action doesn't do any IO or use the ResourceT transformer, so you can bind it directly to IO actions. Actually, since it works with literally any monad, you could instantiate it Identity and run it as a pure computation: let token = runIdentity . runInstagram ... Best regards, Marcin Mrotek From marcin.jan.mrotek at gmail.com Sun Jul 12 13:14:24 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Sun, 12 Jul 2015 15:14:24 +0200 Subject: [Haskell-beginners] Monad problem In-Reply-To: References: Message-ID: You're welcome :) Though I made a mistake in my previous post, if the getUserWhatever function did IO, i.e. had a type like (MonadBaseControl IO m => m a), then of course you could also use it in IO directly, but of course running it with runIdentity would no longer work. Btw. for the record, instead of something like "MonadBaseControl IO m" you may see "MonadBase IO m" or just "MonadIO m" (of which MonadBase is a generalization, to allow other base monads than just IO). All three type classes have instances for IO, so it doesn't matter at all if you use it like above (though MonadBaseControl and MonadBase require MultiParamTypeclasses and FunctionalDependencies extensions, so they might not work in compilers other than GHC) it only matters when implementing instances for other monads, as MonadBaseControl requires one to implement a little more complicated methods. Best regards, Marcin Mrotek From imantc at gmail.com Sun Jul 12 14:28:33 2015 From: imantc at gmail.com (Imants Cekusins) Date: Sun, 12 Jul 2015 16:28:33 +0200 Subject: [Haskell-beginners] Monad problem In-Reply-To: References: Message-ID: No worries Marcin. It makes sense. From stf.list.haskell at eisenbits.com Sun Jul 12 15:40:11 2015 From: stf.list.haskell at eisenbits.com (Stanislaw Findeisen) Date: Sun, 12 Jul 2015 17:40:11 +0200 Subject: [Haskell-beginners] cabal install snap-server-0.9.5.1: At least the following dependencies are missing: attoparsec >=0.10 && <0.13 && ==0.13.0.1 In-Reply-To: References: <559FB144.4050009@eisenbits.com> <559FB9A9.3090301@eisenbits.com> Message-ID: <55A28A5B.6000004@eisenbits.com> On 2015-07-10 14:36, Imants Cekusins wrote: > you could use cabal sandbox. I went along these lines: $ cabal update $ cabal install cabal-install $ ~/.cabal/bin/cabal sandbox init $ ~/.cabal/bin/cabal install --only-dependencies --max-backjumps=-1 Then I still had to resolve: Loading package transformers-0.4.3.0 ... ghc: mmap 1400832 bytes at (nil): Operation not permitted ghc: Try specifying an address with +RTS -xm -RTS Failed to install vector-0.10.12.3 (and similar) but finally made it work. Thanks! -- http://people.eisenbits.com/~stf/ http://www.eisenbits.com/ OpenPGP: 9EC2 5620 2355 B1DC 4A8F 8C79 0EC7 C214 E5AE 3B4E -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From sevcsik at gmail.com Sun Jul 12 18:31:49 2015 From: sevcsik at gmail.com (=?UTF-8?Q?Sevcsik_Andr=C3=A1s?=) Date: Sun, 12 Jul 2015 18:31:49 +0000 Subject: [Haskell-beginners] http-client: Access response body of error responses Message-ID: Hi list, Is there any way to read the response body of an >=400 HTTP response with http-client? If the response is an error response, it throws a StatusCodeException [1], which only exposes the headers, not the whole Response value. However, CouchDB gives a response body for the error responses, describing the error, which I want to access. [1]: https://hackage.haskell.org/package/http-client-0.2.1.1/docs/Network-HTTP-Client.html#v:StatusCodeException Cheers -- Minden j?t, Sevcsik Andr?s -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael at snoyman.com Sun Jul 12 20:28:24 2015 From: michael at snoyman.com (Michael Snoyman) Date: Sun, 12 Jul 2015 20:28:24 +0000 Subject: [Haskell-beginners] http-client: Access response body of error responses In-Reply-To: References: Message-ID: Look at the docs on the checkStatus field of Request. It allows controlling whether an exception is thrown. On Sun, Jul 12, 2015, 11:32 AM Sevcsik Andr?s wrote: > Hi list, > > Is there any way to read the response body of an >=400 HTTP response with > http-client? > > If the response is an error response, it throws a StatusCodeException [1], > which only exposes the headers, not the whole Response value. > > However, CouchDB gives a response body for the error responses, describing > the error, which I want to access. > > [1]: > https://hackage.haskell.org/package/http-client-0.2.1.1/docs/Network-HTTP-Client.html#v:StatusCodeException > > Cheers > -- > Minden j?t, > Sevcsik Andr?s > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sevcsik at gmail.com Sun Jul 12 23:37:19 2015 From: sevcsik at gmail.com (=?UTF-8?Q?Sevcsik_Andr=C3=A1s?=) Date: Sun, 12 Jul 2015 23:37:19 +0000 Subject: [Haskell-beginners] http-client: Access response body of error responses In-Reply-To: References: Message-ID: Great, that did the trick. Thank you! On Sun, Jul 12, 2015 at 10:28 PM Michael Snoyman wrote: > Look at the docs on the checkStatus field of Request. It allows > controlling whether an exception is thrown. > > On Sun, Jul 12, 2015, 11:32 AM Sevcsik Andr?s wrote: > >> Hi list, >> >> Is there any way to read the response body of an >=400 HTTP response with >> http-client? >> >> If the response is an error response, it throws a StatusCodeException >> [1], which only exposes the headers, not the whole Response value. >> >> However, CouchDB gives a response body for the error responses, >> describing the error, which I want to access. >> >> [1]: >> https://hackage.haskell.org/package/http-client-0.2.1.1/docs/Network-HTTP-Client.html#v:StatusCodeException >> >> Cheers >> -- >> Minden j?t, >> Sevcsik Andr?s >> > _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Minden j?t, Sevcsik Andr?s -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Thu Jul 16 19:52:36 2015 From: imantc at gmail.com (Imants Cekusins) Date: Thu, 16 Jul 2015 21:52:36 +0200 Subject: [Haskell-beginners] basic Functor, Applicative and Monad instances Message-ID: Here are complete working snippets with Functor, Applicative and Monad instances. This is my first attempt to write own instances rather than use ready ones. Here we go: module Part.Monad where import Control.Applicative {-# ANN module ("HLint: ignore Use let"::String) #-} {- Val' { val = b1 } can also be written as Val' b1 -} data Val a = Val' { val::a } deriving Show data Weather = Cold | Warm deriving Show instance Functor Val where -- (a -> b) -> f a -> f b fmap ab fa = let a1 = val fa b1 = ab a1 in Val' { val = b1 } instance Applicative Val where -- a -> f a pure a = Val' { val = a } -- f (a -> b) -> f a -> f b (<*>) fab fa = let ab1 = val fab a1 = val fa b1 = ab1 a1 in Val' { val = b1 } instance Monad Val where -- a -> m a return a = Val' { val = a } -- m a -> (a -> m b) -> m b (>>=) ma amb = let a1 = val ma in amb a1 -- pure and return in this example are interchangeable main::Int -> IO() main i = do -- do: Val as monad v1 <- pure Val' { val = i } -- pure: applicative v2 <- return $ over20 <$> v1 -- <$> : functor print v2 v3 <- return $ Val' weather <*> v2 -- <*> : applicative print v3 over20::Int-> Bool over20 i | i > 20 = True | otherwise = False weather::Bool-> Weather weather False = Cold weather True = Warm From rein.henrichs at gmail.com Thu Jul 16 20:26:19 2015 From: rein.henrichs at gmail.com (Rein Henrichs) Date: Thu, 16 Jul 2015 20:26:19 +0000 Subject: [Haskell-beginners] basic Functor, Applicative and Monad instances In-Reply-To: References: Message-ID: This would all be much easier with pattern matching. For example: instance Functor Val where fmap f (Val x) = Val (f x) instance Applicative Val where pure = Val Val f <*> Val x = Val (f x) -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Thu Jul 16 20:45:53 2015 From: imantc at gmail.com (Imants Cekusins) Date: Thu, 16 Jul 2015 22:45:53 +0200 Subject: [Haskell-beginners] basic Functor, Applicative and Monad instances In-Reply-To: References: Message-ID: Cheers, Rein. This is new for me. I tried to make it work. BTW the monad instance is not used. Commenting it out has no effect on running main. How can I apply Val (not IO) Monad instance in this example? Could you suggest a simple change? From imantc at gmail.com Thu Jul 16 20:54:36 2015 From: imantc at gmail.com (Imants Cekusins) Date: Thu, 16 Jul 2015 22:54:36 +0200 Subject: [Haskell-beginners] basic Functor, Applicative and Monad instances In-Reply-To: References: Message-ID: v2: Val monad is now necessary: main::Int -> Val Weather main i = do -- do: Val as monad v1 <- return $ Val' i -- pure: applicative v2 <- return $ over20 <$> v1 -- <$> : functor v3 <- Val' weather <*> v2 -- <*> : applicative return v3 From imantc at gmail.com Fri Jul 17 07:53:01 2015 From: imantc at gmail.com (Imants Cekusins) Date: Fri, 17 Jul 2015 09:53:01 +0200 Subject: [Haskell-beginners] basic Functor, Applicative and Monad instances In-Reply-To: References: Message-ID: based on this snippet and Rein's comment, here is monad file template for intellij Idea to make new monads a quick exercise: module ${PACKAGE_NAME}.${NAME} where data ${Type} a = ${ctor} { ${prop}::a } instance Functor ${Type} where -- (a -> b) -> f a -> f b -- fmap f (${ctor} x) = ${ctor} (f x) fmap ab fa = let a1 = ${prop} fa b1 = ab a1 in fa { ${prop} = b1 } instance Applicative ${Type} where -- a -> f a -- pure = ${ctor} pure a = ${ctor} { ${prop} = a } -- f (a -> b) -> f a -> f b -- ${ctor} f <*> ${ctor} x = ${ctor} (f x) (<*>) fab fa = let ab1 = ${prop} fab a1 = ${prop} fa b1 = ab1 a1 in fa { ${prop} = b1 } instance Monad ${Type} where -- a -> m a return a = ${ctor} { ${prop} = a } -- m a -> (a -> m b) -> m b (>>=) ma amb = let a1 = ${prop} ma in amb a1 From amindfv at gmail.com Fri Jul 17 16:00:49 2015 From: amindfv at gmail.com (amindfv at gmail.com) Date: Fri, 17 Jul 2015 12:00:49 -0400 Subject: [Haskell-beginners] basic Functor, Applicative and Monad instances In-Reply-To: References: Message-ID: <59CCE329-6A7E-4AA7-BFAF-C1A3DB36AB8A@gmail.com> You have the types of the functions commented out in the instances. If you use {-# LANGUAGE InstanceSigs #-} you can write them for real (and be sure that they're accurate) Tom El Jul 17, 2015, a las 3:53, Imants Cekusins escribi?: > based on this snippet and Rein's comment, here is monad file template > for intellij Idea to make new monads a quick exercise: > > module ${PACKAGE_NAME}.${NAME} where > > > data ${Type} a = ${ctor} { > ${prop}::a > } > > > instance Functor ${Type} where > -- (a -> b) -> f a -> f b > -- fmap f (${ctor} x) = ${ctor} (f x) > fmap ab fa = let a1 = ${prop} fa > b1 = ab a1 > in fa { ${prop} = b1 } > > > instance Applicative ${Type} where > -- a -> f a > -- pure = ${ctor} > pure a = ${ctor} { ${prop} = a } > > -- f (a -> b) -> f a -> f b > -- ${ctor} f <*> ${ctor} x = ${ctor} (f x) > (<*>) fab fa = let ab1 = ${prop} fab > a1 = ${prop} fa > b1 = ab1 a1 > in fa { ${prop} = b1 } > > > instance Monad ${Type} where > -- a -> m a > return a = ${ctor} { ${prop} = a } > > -- m a -> (a -> m b) -> m b > (>>=) ma amb = let a1 = ${prop} ma > in amb a1 > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From amindfv at gmail.com Fri Jul 17 18:06:09 2015 From: amindfv at gmail.com (amindfv at gmail.com) Date: Fri, 17 Jul 2015 14:06:09 -0400 Subject: [Haskell-beginners] basic Functor, Applicative and Monad instances In-Reply-To: References: <59CCE329-6A7E-4AA7-BFAF-C1A3DB36AB8A@gmail.com> Message-ID: <86DF2DE8-6550-4AA5-AC5F-C42F55BCDCB4@gmail.com> Right, you'll want to say eg fmap :: (a -> b) -> Val a -> Val b Tom El Jul 17, 2015, a las 12:23, Imants Cekusins escribi?: >> InstanceSigs > > Thank you Tom. > > this sig does not work though: > fmap ::(a -> b) -> f a -> f b From defigueiredo at ucdavis.edu Fri Jul 17 19:59:16 2015 From: defigueiredo at ucdavis.edu (Dimitri DeFigueiredo) Date: Fri, 17 Jul 2015 13:59:16 -0600 Subject: [Haskell-beginners] Cabal dependencies are per target or global? In-Reply-To: <86DF2DE8-6550-4AA5-AC5F-C42F55BCDCB4@gmail.com> References: <59CCE329-6A7E-4AA7-BFAF-C1A3DB36AB8A@gmail.com> <86DF2DE8-6550-4AA5-AC5F-C42F55BCDCB4@gmail.com> Message-ID: <55A95E94.6070208@ucdavis.edu> Hello, I'm trying to figure out how cabal understands dependencies. It seems all "build-depends:" sections have to build satisfied for any one target to be built. Is that correct or is there a problem with my setup? I assumed those "build-depends:" sections were "per target", but apparently that not exactly the case. I have a small .cabal file that builds the second target "myPersonalMain" if and only if I comment out the build-dependencies for the first target (i.e. myAgent) here's my test file agent.cabal: ------------------------------------------------ name: agent version: 0.1.0.0 synopsis: Just testing author: Dimitri DeFigueiredo maintainer: defigueireo at ucdavis.edu build-type: Simple cabal-version: >=1.20 ---------------------------------------------- executable myAgent main-is: Main.hs hs-source-dirs: ./src build-depends: base >=4.6 && <4.7 , unordered-containers >= 0.2.3.0 , unix >= 2.6.0.1 , process >= 1.1.0.2 , stm >= 2.4.2 default-language: Haskell2010 ---------------------------------------------- executable myPersonalMain main-is: Mpm.hs hs-source-dirs: ./src build-depends: base >=4.6 default-language: Haskell2010 ---------------------------------------------- if I try to build the second target I get: cabal build MyPersonalMain ./agent.cabal has been changed. Re-configuring with most recently used options. If this fails, please run configure manually. Resolving dependencies... Configuring agent-0.1.0.0... cabal: At least the following dependencies are missing: process >=1.1.0.2, stm >=2.4.2, unix >=2.6.0.1, unordered-containers >=0.2.3.0 could someone shed some light into this behavior? Thanks, Dimitri From defigueiredo at ucdavis.edu Fri Jul 17 23:08:13 2015 From: defigueiredo at ucdavis.edu (Dimitri DeFigueiredo) Date: Fri, 17 Jul 2015 17:08:13 -0600 Subject: [Haskell-beginners] Cabal dependencies are per target or global? In-Reply-To: References: <59CCE329-6A7E-4AA7-BFAF-C1A3DB36AB8A@gmail.com> <86DF2DE8-6550-4AA5-AC5F-C42F55BCDCB4@gmail.com> <55A95E94.6070208@ucdavis.edu> Message-ID: <55A98ADD.3050803@ucdavis.edu> I guess my example was incomplete. I can make GHC run. Here's a modified version where I do have the ghc-options line. I can build an executable for the second target (myPersonalMain) by commenting the "build-depends: section" for the first target (agent). My .cabal file with (commented lines) is: ------------------------------------------------ name: agent version: 0.1.0.0 build-type: Simple cabal-version: >=1.20 ------------------------------------------------ executable agent main-is: Main.hs hs-source-dirs: ./src -- build-depends: base >=4.6 && <4.7 -- , unordered-containers >= 0.2.3.0 -- , unix >= 2.6.0.1 -- , process >= 1.1.0.2 -- , stm >= 2.4.2 -- Base language which the package is written in. default-language: Haskell2010 ---------------------------------------------- executable myPersonalMain main-is: Mpm.hs hs-source-dirs: ./src ghc-options: -main-is Mpm build-depends: base >=4.4 default-language: Haskell2010 ---------------------------------------------- The contents of Mpm.hs are: module Mpm where main = putStrLn "Hi!" But if I remove the comments in the .cabal file above, I get this: Dis-machine:cabal-tests dimitri$ cabal build myPersonalMain ./agent.cabal has been changed. Re-configuring with most recently used options. If this fails, please run configure manually. Resolving dependencies... Configuring agent-0.1.0.0... cabal: At least the following dependencies are missing: process >=1.1.0.2, stm >=2.4.2, unix >=2.6.0.1, unordered-containers >=0.2.3.0 Is this a bug? Or am I missing something? Cheers, Dimitri On 17/07/15 15:10, Imants Cekusins wrote: > this could shed some light: > > http://stackoverflow.com/questions/14238729/producing-multiple-executables-from-single-project > > answer #2 was marked as answered > > ghc-options: -O2 -threaded -with-rtsopts=-N -main-is FirstExecutable From karl at karlv.net Sat Jul 18 01:29:23 2015 From: karl at karlv.net (Karl Voelker) Date: Fri, 17 Jul 2015 18:29:23 -0700 Subject: [Haskell-beginners] Cabal dependencies are per target or global? In-Reply-To: <55A98ADD.3050803@ucdavis.edu> References: <59CCE329-6A7E-4AA7-BFAF-C1A3DB36AB8A@gmail.com> <86DF2DE8-6550-4AA5-AC5F-C42F55BCDCB4@gmail.com> <55A95E94.6070208@ucdavis.edu> <55A98ADD.3050803@ucdavis.edu> Message-ID: <1437182963.961253.326719945.58708268@webmail.messagingengine.com> On Fri, Jul 17, 2015, at 04:08 PM, Dimitri DeFigueiredo wrote: > Is this a bug? Or am I missing something? The dependencies are not global. You can see this by trying to import a module in Mpm.hs that is in one of the unique dependencies of "agent" - the import fails. [1] However, in order to build, you must first configure. And the "configure" step cannot be done for a single executable - it's done for the whole package. Since package dependencies are checked during the configure step, you have to have all the dependencies in place for all targets. I think this is probably a good thing, because otherwise, you could end up installing some packages that satisfy the dependencies of one target, only to find out that the particular package versions which were chosen make it impossible to satisfy the dependencies of the other target. -Karl 1. https://gist.github.com/ktvoelker/d561889ac4bd56cadc2d From defigueiredo at ucdavis.edu Sat Jul 18 16:47:04 2015 From: defigueiredo at ucdavis.edu (Dimitri DeFigueiredo) Date: Sat, 18 Jul 2015 10:47:04 -0600 Subject: [Haskell-beginners] Cabal dependencies are per target or global? In-Reply-To: <1437182963.961253.326719945.58708268@webmail.messagingengine.com> References: <59CCE329-6A7E-4AA7-BFAF-C1A3DB36AB8A@gmail.com> <86DF2DE8-6550-4AA5-AC5F-C42F55BCDCB4@gmail.com> <55A95E94.6070208@ucdavis.edu> <55A98ADD.3050803@ucdavis.edu> <1437182963.961253.326719945.58708268@webmail.messagingengine.com> Message-ID: <55AA8308.9000802@ucdavis.edu> Thanks Karl! The way cabal is working makes sense now. I don't like it, though. Having a build fail because of changes made to another target is counter-intuitive to me. I don't understand your argument for why the current behavior is a good thing. It seems we would be extending so called "cabal hell" to within targets in a package if we were to change this? I do wish there were other options here. Anyway, thanks again for the explanation! Dimitri Em 17/07/15 19:29, Karl Voelker escreveu: > On Fri, Jul 17, 2015, at 04:08 PM, Dimitri DeFigueiredo wrote: >> Is this a bug? Or am I missing something? > The dependencies are not global. You can see this by trying to import a > module in Mpm.hs that is in one of the unique dependencies of "agent" - > the import fails. [1] > > However, in order to build, you must first configure. And the > "configure" step cannot be done for a single executable - it's done for > the whole package. Since package dependencies are checked during the > configure step, you have to have all the dependencies in place for all > targets. > > I think this is probably a good thing, because otherwise, you could end > up installing some packages that satisfy the dependencies of one target, > only to find out that the particular package versions which were chosen > make it impossible to satisfy the dependencies of the other target. > > -Karl > > 1. https://gist.github.com/ktvoelker/d561889ac4bd56cadc2d > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From rene.klacan at gmail.com Sat Jul 18 21:15:50 2015 From: rene.klacan at gmail.com (=?UTF-8?B?UmVuw6kgS2xhxI1hbg==?=) Date: Sat, 18 Jul 2015 23:15:50 +0200 Subject: [Haskell-beginners] Cabal dependencies are per target or global? In-Reply-To: <55AA8308.9000802@ucdavis.edu> References: <59CCE329-6A7E-4AA7-BFAF-C1A3DB36AB8A@gmail.com> <86DF2DE8-6550-4AA5-AC5F-C42F55BCDCB4@gmail.com> <55A95E94.6070208@ucdavis.edu> <55A98ADD.3050803@ucdavis.edu> <1437182963.961253.326719945.58708268@webmail.messagingengine.com> <55AA8308.9000802@ucdavis.edu> Message-ID: Hello Dimitri, I recommend you to use stack (https://github.com/commercialhaskell/stack) instead of cabal. Never had any problem with building since I started using it. It's awesome. It solved all my headaches caused by Cabal. But it still treats dependencies in the same way. Rene On Sat, Jul 18, 2015 at 6:47 PM, Dimitri DeFigueiredo < defigueiredo at ucdavis.edu> wrote: > Thanks Karl! > > The way cabal is working makes sense now. > > I don't like it, though. Having a build fail because of changes made to > another target is counter-intuitive to me. I don't understand your argument > for why the current behavior is a good thing. It seems we would be > extending so called "cabal hell" to within targets in a package if we were > to change this? I do wish there were other options here. > > Anyway, thanks again for the explanation! > > > Dimitri > > Em 17/07/15 19:29, Karl Voelker escreveu: > >> On Fri, Jul 17, 2015, at 04:08 PM, Dimitri DeFigueiredo wrote: >> >>> Is this a bug? Or am I missing something? >>> >> The dependencies are not global. You can see this by trying to import a >> module in Mpm.hs that is in one of the unique dependencies of "agent" - >> the import fails. [1] >> >> However, in order to build, you must first configure. And the >> "configure" step cannot be done for a single executable - it's done for >> the whole package. Since package dependencies are checked during the >> configure step, you have to have all the dependencies in place for all >> targets. >> >> I think this is probably a good thing, because otherwise, you could end >> up installing some packages that satisfy the dependencies of one target, >> only to find out that the particular package versions which were chosen >> make it impossible to satisfy the dependencies of the other target. >> >> -Karl >> >> 1. https://gist.github.com/ktvoelker/d561889ac4bd56cadc2d >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From karl at karlv.net Sun Jul 19 00:14:31 2015 From: karl at karlv.net (Karl Voelker) Date: Sat, 18 Jul 2015 17:14:31 -0700 Subject: [Haskell-beginners] Cabal dependencies are per target or global? In-Reply-To: <55AA8308.9000802@ucdavis.edu> References: <59CCE329-6A7E-4AA7-BFAF-C1A3DB36AB8A@gmail.com> <86DF2DE8-6550-4AA5-AC5F-C42F55BCDCB4@gmail.com> <55A95E94.6070208@ucdavis.edu> <55A98ADD.3050803@ucdavis.edu> <1437182963.961253.326719945.58708268@webmail.messagingengine.com> <55AA8308.9000802@ucdavis.edu> Message-ID: <1437264871.1295055.327206433.61C09BD7@webmail.messagingengine.com> On Sat, Jul 18, 2015, at 09:47 AM, Dimitri DeFigueiredo wrote: > I don't like it, though. Having a build fail because of changes made to > another target is counter-intuitive to me. I don't understand your > argument for why the current behavior is a good thing. It seems we would > be extending so called "cabal hell" to within targets in a package if we > were to change this? I do wish there were other options here. Yes, that's exactly right - it would be another way to end up in cabal hell. There is another option, though: you could put the executables in separate packages. -Karl From ryan.warner.mn+haskell at gmail.com Wed Jul 22 02:29:57 2015 From: ryan.warner.mn+haskell at gmail.com (Ryan Warner) Date: Tue, 21 Jul 2015 21:29:57 -0500 Subject: [Haskell-beginners] seq vs deepseq Message-ID: I'm trying to grok Haskell's laziness. In this example, why does the seq not force youTyped to wait for s to be fully evaluated, before returning a result to putStrLn? -------------------- import System.IO (hSetBuffering,stdin,BufferMode(..)) youTyped :: String -> String youTyped s = s `seq` "you typed: " ++ s main = do hSetBuffering stdin NoBuffering s <- getContents let l = map youTyped $ lines $ takeWhile ( /= '\04' ) s mapM_ putStrLn ("Start Typing (Ctrl-D to exit):":l) -------------------- The output looks like: -------------------- $ runhaskell seqLazy.hs Start Typing (Ctrl-D to exit): Hyou typed: Heelllloo wwoorrlldd fyou typed: faaiill ^D -------------------- Changing seq, to deepseq does the trick though. -------------------- import System.IO (hSetBuffering,stdin,BufferMode(..)) import Control.DeepSeq youTyped :: String -> String youTyped s = s `deepseq` "you typed: " ++ s main = do hSetBuffering stdin NoBuffering s <- getContents let l = map youTyped $ lines $ takeWhile ( /= '\04' ) s mapM_ putStrLn ("Start Typing (Ctrl-D to exit):":l) -------------------- Output: $ runhaskell deepSeqLazy.hs Start Typing (Ctrl-D to exit): Hello world you typed: Hello world success you typed: success ^D When does it make sense to use seq then? -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at redivi.com Wed Jul 22 02:59:35 2015 From: bob at redivi.com (Bob Ippolito) Date: Tue, 21 Jul 2015 19:59:35 -0700 Subject: [Haskell-beginners] seq vs deepseq In-Reply-To: References: Message-ID: seq forces the term into weak-head normal form. Basically just enough to tell whether the list is `[]` or not. It's the same kind of evaluation that would happen if you pattern matched on the constructor. Only one Char needs to be read in order to make that determination. Sometimes this is desirable, but other times you want to traverse the whole structure and make sure everything is forced. The confusion is made much worse because you're using lazy IO. The `takeWhile (/= '\04')` is redundant here, the ^D never ends up in that string. Most cases where you use `seq` rather than `deepseq` are because you know that the substructure is already evaluated, or there is no need to evaluate it, and it may be very inefficient to do that redundant work. See also: * http://chimera.labs.oreilly.com/books/1230000000929/ch02.html#sec_par-eval-whnf * https://hackhands.com/lazy-evaluation-works-haskell/ On Tue, Jul 21, 2015 at 7:29 PM, Ryan Warner < ryan.warner.mn+haskell at gmail.com> wrote: > I'm trying to grok Haskell's laziness. In this example, why does the seq > not force youTyped to wait for s to be fully evaluated, before returning a > result to putStrLn? > > -------------------- > import System.IO (hSetBuffering,stdin,BufferMode(..)) > > youTyped :: String -> String > youTyped s = s `seq` "you typed: " ++ s > > main = do > hSetBuffering stdin NoBuffering > s <- getContents > let l = map youTyped $ lines $ takeWhile ( /= '\04' ) s > mapM_ putStrLn ("Start Typing (Ctrl-D to exit):":l) > -------------------- > > The output looks like: > > -------------------- > > $ runhaskell seqLazy.hs > > Start Typing (Ctrl-D to exit): > > Hyou typed: Heelllloo wwoorrlldd > > > fyou typed: faaiill > > > ^D > -------------------- > > Changing seq, to deepseq does the trick though. > > -------------------- > import System.IO (hSetBuffering,stdin,BufferMode(..)) > import Control.DeepSeq > > youTyped :: String -> String > youTyped s = s `deepseq` "you typed: " ++ s > > main = do > hSetBuffering stdin NoBuffering > s <- getContents > let l = map youTyped $ lines $ takeWhile ( /= '\04' ) s > mapM_ putStrLn ("Start Typing (Ctrl-D to exit):":l) > -------------------- > > Output: > > > $ runhaskell deepSeqLazy.hs > > Start Typing (Ctrl-D to exit): > > Hello world > > you typed: Hello world > > success > > you typed: success > > ^D > > > When does it make sense to use seq then? > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ali.baharev at gmail.com Wed Jul 22 21:24:07 2015 From: ali.baharev at gmail.com (Ali Baharev) Date: Wed, 22 Jul 2015 23:24:07 +0200 Subject: [Haskell-beginners] Traversing generic trees Message-ID: Dear All, I have started learning Haskell recently, and I try to reimplement interesting algorithms that are challenging to do in other languages. I would like to ask you for your kind help with a problem that I am stuck with. A generic tree is given in the form of nested sequences (nested lists or nested tuples) and I would like to traverse it in (1) depth-first order, (2) lazily and (3) without copying the data into some other datastructure first. I test the algorithm by pretty printing the tree. My goal is learning, so Data.Tree is not an option (although I did look into its implementation). Here is my first attempt: data Tree a = Leaf a | Node [Tree a] tree = Node [Leaf 'a', Node [Leaf 'b', Leaf 'c', Node []], Leaf 'd'] toString :: (Show a) => Tree a -> String toString (Leaf leaf) = " " ++ show leaf ++ " " toString (Node nodes) = " [ " ++ concatMap toString nodes ++ " ] " main = print $ toString tree It (more or less) satisfies the above requirements. The pretty printing is not very pretty but the part that I am really not happy with is the lot of code duplication in giving the tree. I would like to enter it as: tree = ['a', ['b', 'c', []], 'd'] which of course won't work. Is there a (not too obscure) way to help the compiler so that it understands that 'a' means Leaf 'a', etc? I have also tried tree = ('a', ('b', 'c', ()), 'd') but then I do not know how to destructure the nested tuples. Any help is greatly appreciated. Ali From ali.baharev at gmail.com Wed Jul 22 22:14:50 2015 From: ali.baharev at gmail.com (Ali Baharev) Date: Thu, 23 Jul 2015 00:14:50 +0200 Subject: [Haskell-beginners] Traversing generic trees In-Reply-To: References: Message-ID: Dear Elliot, The question is whether there is a (not too obscure) way to eliminate the code duplication, or how the code duplication can be avoided using nested tuples instead. Please try to answer the question. Ali On Wed, Jul 22, 2015 at 11:51 PM, elliot wrote: > In general you don't produce large trees (or any data structure) by hand. It's slightly frustrating to test of course (as you've discovered) but for the most part you'll only need to produce small structures. > > -- > e: elliot at citrusbytes.net > p: +44 751 070 5158 > ---- Original Message ---- > From: "Ali Baharev" > To: beginners at haskell.org > Sent: Wed, Jul 22, 2015, 10:24 PM > Subject: [Haskell-beginners] Traversing generic trees > Dear All, > > I have started learning Haskell recently, and I try to reimplement > interesting algorithms that are challenging to do in other languages. > I would like to ask you for your kind help with a problem that I am > stuck with. > > A generic tree is given in the form of nested sequences (nested lists > or nested tuples) and I would like to traverse it in (1) depth-first > order, (2) lazily and (3) without copying the data into some other > datastructure first. I test the algorithm by pretty printing the tree. > My goal is learning, so Data.Tree is not an option (although I did > look into its implementation). > > Here is my first attempt: > > data Tree a = Leaf a | Node [Tree a] > > tree = Node [Leaf 'a', Node [Leaf 'b', Leaf 'c', Node []], Leaf 'd'] > > toString :: (Show a) => Tree a -> String > toString (Leaf leaf) = " " ++ show leaf ++ " " > toString (Node nodes) = " [ " ++ concatMap toString nodes ++ " ] " > > main = print $ toString tree > > It (more or less) satisfies the above requirements. The pretty > printing is not very pretty but the part that I am really not happy > with is the lot of code duplication in giving the tree. I would like > to enter it as: > > tree = ['a', ['b', 'c', []], 'd'] > > which of course won't work. > > Is there a (not too obscure) way to help the compiler so that it > understands that 'a' means Leaf 'a', etc? > > I have also tried > > tree = ('a', ('b', 'c', ()), 'd') > > but then I do not know how to destructure the nested tuples. > > Any help is greatly appreciated. > > Ali > _______________________________________________ > Beginners mailing list > Beginners at haskell.org (mailto:Beginners at haskell.org) > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners (http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners) From imantc at gmail.com Wed Jul 22 23:10:12 2015 From: imantc at gmail.com (Imants Cekusins) Date: Thu, 23 Jul 2015 01:10:12 +0200 Subject: [Haskell-beginners] Traversing generic trees In-Reply-To: References: Message-ID: how about this: data Tree a = L a | N [Tree a] deriving Show l::a -> Tree a l = L n::a -> Tree a n x = N [L x] m::(a->Tree a) ->[a]-> Tree a m f list = N $ f <$> list run it like this: m l [2,3] m n [2,3] any good? From ali.baharev at gmail.com Wed Jul 22 23:26:41 2015 From: ali.baharev at gmail.com (Ali Baharev) Date: Thu, 23 Jul 2015 01:26:41 +0200 Subject: [Haskell-beginners] Traversing generic trees In-Reply-To: References: Message-ID: Dear Imants, Thanks. Unfortunately, I am not sure I get it. It seems to me that it generates a homogeneous list of either nodes with single leaver or just leaves. Or how would the ['a', ['b', 'c', []], 'd'] input look like, when using your proposed approach? Ali On Thu, Jul 23, 2015 at 1:10 AM, Imants Cekusins wrote: > how about this: > > > data Tree a = L a | N [Tree a] deriving Show > > > l::a -> Tree a > l = L > > n::a -> Tree a > n x = N [L x] > > m::(a->Tree a) ->[a]-> Tree a > m f list = N $ f <$> list > > > run it like this: > m l [2,3] > m n [2,3] > > any good? > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From joel.s.williamson at gmail.com Thu Jul 23 02:52:50 2015 From: joel.s.williamson at gmail.com (Joel Williamson) Date: Wed, 22 Jul 2015 22:52:50 -0400 Subject: [Haskell-beginners] Traversing generic trees In-Reply-To: References: Message-ID: Ali, Nested lists with different nesting depths cannot be properly typed. You could probably get around this with a heterogenous collection ( https://wiki.haskell.org/Heterogenous_collections), but the mechanisms proposed there strike me as overkill for this problem. QuasiQuoters could definitely do it, by defining a new grammar construct. That would be quite advanced, and would teach you more about meta-programming than about trees, algorithms or functional programming. Using Imants' suggestion, you would write: n [l 'a', n [l 'b', l 'c', n []], l 'd'] This is just as much boiler plate as you had in your initial definition of tree, but it uses shorter identifiers. Joel On Wed, 22 Jul 2015 19:27 Ali Baharev wrote: > Dear Imants, > > Thanks. Unfortunately, I am not sure I get it. It seems to me that it > generates a homogeneous list of either nodes with single leaver or > just leaves. Or how would the > > ['a', ['b', 'c', []], 'd'] > > input look like, when using your proposed approach? > > Ali > > On Thu, Jul 23, 2015 at 1:10 AM, Imants Cekusins wrote: > > how about this: > > > > > > data Tree a = L a | N [Tree a] deriving Show > > > > > > l::a -> Tree a > > l = L > > > > n::a -> Tree a > > n x = N [L x] > > > > m::(a->Tree a) ->[a]-> Tree a > > m f list = N $ f <$> list > > > > > > run it like this: > > m l [2,3] > > m n [2,3] > > > > any good? > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tkoster at gmail.com Thu Jul 23 06:05:12 2015 From: tkoster at gmail.com (Thomas Koster) Date: Thu, 23 Jul 2015 16:05:12 +1000 Subject: [Haskell-beginners] Traversing generic trees In-Reply-To: References: Message-ID: Hi Ali, On 23 July 2015 at 07:24, Ali Baharev wrote: > I have started learning Haskell recently, and I try to reimplement > interesting algorithms that are challenging to do in other languages. > I would like to ask you for your kind help with a problem that I am > stuck with. ... > Here is my first attempt: > > data Tree a = Leaf a | Node [Tree a] > > tree = Node [Leaf 'a', Node [Leaf 'b', Leaf 'c', Node []], Leaf 'd'] > > toString :: (Show a) => Tree a -> String > toString (Leaf leaf) = " " ++ show leaf ++ " " > toString (Node nodes) = " [ " ++ concatMap toString nodes ++ " ] " ... > the part that I am really not happy > with is the lot of code duplication in giving the tree. I would like > to enter it as: > tree = ['a', ['b', 'c', []], 'd'] > which of course won't work. > Is there a (not too obscure) way to help the compiler so that it > understands that 'a' means Leaf 'a', etc? On Wed, Jul 22, 2015 at 11:51 PM, elliot wrote: > In general you don't produce large trees (or any data structure) by hand. I am a Haskell novice myself, so don't take my advice as expert opinion, but it sounds like you may have the wrong expectation about what Haskell offers regarding "shorter", "cleaner", "purer" code. I think Elliot was right to question your question. You seem to want a more concise way to define a constant without having to repeatedly type the data constructor names, hoping that the compiler offers some nifty syntax for saving a few characters of duplicated text. The answers by others seem to agree that "there isn't any". I think you should not focus so hard on trying to save a few characters in the definition of "tree". The way I see it, the "conciseness" aspect of functional programming is not really about saving a few characters in the small. It is more about saving thousands of lines of code in the large. You do this by using modular, composable abstractions, and, in Haskell's case, exploiting laziness. Focus instead on writing a higher-order traversal function that can be used to write "toString" and all your other tree-traversing functions as simple one-liners. To get started, you should read this influential article by J. Hughes [1][2]. The first third of the article demonstrates these ideas with lists and trees. The article is well-suited to imperative programmers learning their first functional language. You don't need a doctorate to understand it. This should give you some hints on how to exploit Haskell better in your own list and tree implementations. (Hughes' tree data type is slightly different from yours; his has labels on all the nodes, not just the leaves, but the lesson is still perfectly relevant.) [1] Hughes, J. "Why Functional Programming Matters", The Computer Journal 32 (2), pp. 98-107, 1989. [2] http://www.cse.chalmers.se/~rjmh/Papers/whyfp.html -- Thomas Koster From imantc at gmail.com Thu Jul 23 07:41:33 2015 From: imantc at gmail.com (Imants Cekusins) Date: Thu, 23 Jul 2015 09:41:33 +0200 Subject: [Haskell-beginners] Traversing generic trees In-Reply-To: References: Message-ID: .. on the other hand, if facing this problem: - import large trees from concise human-readable representation as string , it is probably possible to write a parser which does just that. After all json parser works somehow ;) Just saying that you could do this in Haskell, given enough interest. From martin at vlkk.cz Thu Jul 23 08:07:04 2015 From: martin at vlkk.cz (Martin Vlk) Date: Thu, 23 Jul 2015 08:07:04 +0000 Subject: [Haskell-beginners] (->) reader/environment Message-ID: <55B0A0A8.3010304@vlkk.cz> Hi, this one is a bit of a mystery to me. I am working on solutions to cis194/NICTA Haskell exercises and among others I am asked to work with (->). I understand it refers to the reader/environment design patterns, but I am stumped as for what exactly it is. It doesn't seem to be an ordinary type, I know it is used as type constructor in type declarations, so that suggests it's a function, but somehow special. Looking in Hoogle it seems to be Haskell keyword - e.g. not an ordinary function. So what is it - type constructor, a keyword, how is it related to the reader/environment pattern? >From GHCI's :info (->) I get: data (->) a b -- Defined in ?ghc-prim-0.4.0.0:GHC.Prim? instance P.Monad ((->) r) -- Defined in ?GHC.Base? instance P.Functor ((->) r) -- Defined in ?GHC.Base? instance P.Applicative ((->) a) -- Defined in ?GHC.Base? instance P.Monoid b => P.Monoid (a -> b) -- Defined in ?GHC.Base? Cheers Martin From grzegorzmilka at gmail.com Thu Jul 23 08:58:19 2015 From: grzegorzmilka at gmail.com (Grzegorz Milka) Date: Thu, 23 Jul 2015 10:58:19 +0200 Subject: [Haskell-beginners] (->) reader/environment In-Reply-To: <55B0A0A8.3010304@vlkk.cz> References: <55B0A0A8.3010304@vlkk.cz> Message-ID: <55B0ACAB.3020002@gmail.com> Hi Martin, You certainly know what (->) is, but you might be confused about its prefix notation. (->) is a type constructor which represent a normal Haskell function. That is,(->) A B represents a type of a function from type A to type B. Since (->) is a right-associative infix operator we almost always write it in the infix form: a -> b -> c, which means a -> (b -> c), which means in the prefix form:(->) a ((->) b c). Similarly + is the normal, infix addition operator, but written in parenthesis you can write it in prefix form, that is: (+) 2 2 == 1 + 3. When you import Control.Monad.Reader, ghci will tell you that: Prelude Control.Monad.Reader> :info (->) data (->) a b -- Defined in `GHC.Prim' instance Monad ((->) r) -- Defined in `GHC.Base' instance Functor ((->) r) -- Defined in `GHC.Base' instance MonadReader r ((->) r) That is a type contructor (still not a complete type!) (->) r is of class MonadReader r. In other words, a function which accepts type r may act as a reader from environment of type r. It might be easier to understand after reading its implementation. instance MonadReader r ((->) r) where ask = id local f m = m . f Best, Grzegorz Milka On 23.07.2015 10:07, Martin Vlk wrote: > Hi, this one is a bit of a mystery to me. > > I am working on solutions to cis194/NICTA Haskell exercises and among > others I am asked to work with (->). > > I understand it refers to the reader/environment design patterns, but I > am stumped as for what exactly it is. It doesn't seem to be an ordinary > type, I know it is used as type constructor in type declarations, so > that suggests it's a function, but somehow special. Looking in Hoogle it > seems to be Haskell keyword - e.g. not an ordinary function. > > So what is it - type constructor, a keyword, how is it related to the > reader/environment pattern? > > From GHCI's :info (->) I get: > data (->) a b -- Defined in ?ghc-prim-0.4.0.0:GHC.Prim? > instance P.Monad ((->) r) -- Defined in ?GHC.Base? > instance P.Functor ((->) r) -- Defined in ?GHC.Base? > instance P.Applicative ((->) a) -- Defined in ?GHC.Base? > instance P.Monoid b => P.Monoid (a -> b) -- Defined in ?GHC.Base? > > Cheers > Martin > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From martin at vlkk.cz Thu Jul 23 09:03:29 2015 From: martin at vlkk.cz (Martin Vlk) Date: Thu, 23 Jul 2015 09:03:29 +0000 Subject: [Haskell-beginners] (->) reader/environment In-Reply-To: <55B0A0A8.3010304@vlkk.cz> References: <55B0A0A8.3010304@vlkk.cz> Message-ID: <55B0ADE1.4070405@vlkk.cz> Found some info on Typeclassopedia (https://wiki.haskell.org/Typeclassopedia) - see below. It sounds like this is basically a "function with one parameter already applied". The parameter is then available for further usage.. ---- ((->) e) (which can be thought of as (e ->); see above), the type of functions which take a value of type e as a parameter, is a Functor. As a container, (e -> a) represents a (possibly infinite) set of values of a, indexed by values of e. Alternatively, and more usefully, ((->) e) can be thought of as a context in which a value of type e is available to be consulted in a read-only fashion. This is also why ((->) e) is sometimes referred to as the reader monad; more on this later. ...then: As mentioned earlier, ((->) e) is known as the reader monad, since it describes computations in which a value of type e is available as a read-only environment. The Control.Monad.Reader module provides the Reader e a type, which is just a convenient newtype wrapper around (e -> a), along with an appropriate Monad instance and some Reader-specific utility functions such as ask (retrieve the environment), asks (retrieve a function of the environment), and local (run a subcomputation under a different environment). Martin Martin Vlk: > Hi, this one is a bit of a mystery to me. > > I am working on solutions to cis194/NICTA Haskell exercises and among > others I am asked to work with (->). > > I understand it refers to the reader/environment design patterns, but I > am stumped as for what exactly it is. It doesn't seem to be an ordinary > type, I know it is used as type constructor in type declarations, so > that suggests it's a function, but somehow special. Looking in Hoogle it > seems to be Haskell keyword - e.g. not an ordinary function. > > So what is it - type constructor, a keyword, how is it related to the > reader/environment pattern? > > From GHCI's :info (->) I get: > data (->) a b -- Defined in ?ghc-prim-0.4.0.0:GHC.Prim? > instance P.Monad ((->) r) -- Defined in ?GHC.Base? > instance P.Functor ((->) r) -- Defined in ?GHC.Base? > instance P.Applicative ((->) a) -- Defined in ?GHC.Base? > instance P.Monoid b => P.Monoid (a -> b) -- Defined in ?GHC.Base? > > Cheers > Martin > From ali.baharev at gmail.com Thu Jul 23 16:48:49 2015 From: ali.baharev at gmail.com (Ali Baharev) Date: Thu, 23 Jul 2015 18:48:49 +0200 Subject: [Haskell-beginners] Traversing generic trees In-Reply-To: References: Message-ID: Dear All, I used to work at the University. Whenever a student asked me a question, I first focused on the question and tried to answer it. Sometimes the question was tough, maybe because there wasn't any easy solution to the problem. In those situations I used to say to my students: ?Problem well spotted, unfortunately I cannot give you an answer / there is no easy solution to this problem.? However, I have never started questioning the questions of my students, especially when I could not give them an answer. According to the Wiki on beginners at haskell.org: "Here, there is no such thing as a 'stupid question.'" If you start questioning my question, then I really do not know where to go... You might as well say: The whole question is pointless, just use Data.Tree and be done with it! It is really not part of the original question, and I sooo not want to get into a discussion over this: It is important to have language support for helping humans to input data, without a full-blown parser. Examples would be user-defined implicit type conversions and user-defined literals in other statically typed languages. OK, let's get back to the original question. Apparently, there is no easy way to solve it with nested lists. However, no one has touched the nested tuples so far. How can I write a toString function that works similarly to mine but destructures arbitrarily nested tuples? Thanks, Ali On Thu, Jul 23, 2015 at 9:41 AM, Imants Cekusins wrote: > .. on the other hand, if facing this problem: > - import large trees from concise human-readable representation as string > > , it is probably possible to write a parser which does just that. > > After all json parser works somehow ;) > > Just saying that you could do this in Haskell, given enough interest. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From bob at redivi.com Thu Jul 23 19:38:34 2015 From: bob at redivi.com (Bob Ippolito) Date: Thu, 23 Jul 2015 12:38:34 -0700 Subject: [Haskell-beginners] Traversing generic trees In-Reply-To: References: Message-ID: You should not try and use the built-in lists or tuples to represent a tree data structure. That's not what they're good at. You probably could make tuples work and write functions using GHC.Generics to work with it as a tree data structure, but it definitely won't be easy or elegant. If you want a more economic syntax for expressing the tree you can provide shorter names for Leaf and Node (one char isn't too bad), or else you're stuck with using a parser. You may not have to write a parser though, perhaps JSON or YAML would work fine for this. If it needs to go in the source file, there's always TemplateHaskell and QuasiQuotes. On Thu, Jul 23, 2015 at 9:48 AM, Ali Baharev wrote: > Dear All, > > I used to work at the University. Whenever a student asked me a > question, I first focused on the question and tried to answer it. > Sometimes the question was tough, maybe because there wasn't any easy > solution to the problem. In those situations I used to say to my > students: ?Problem well spotted, unfortunately I cannot give you an > answer / there is no easy solution to this problem.? However, I have > never started questioning the questions of my students, especially > when I could not give them an answer. > > According to the Wiki on beginners at haskell.org: "Here, there is no > such thing as a 'stupid question.'" If you start questioning my > question, then I really do not know where to go... > > You might as well say: The whole question is pointless, just use > Data.Tree and be done with it! > > It is really not part of the original question, and I sooo not want to > get into a discussion over this: It is important to have language > support for helping humans to input data, without a full-blown parser. > Examples would be user-defined implicit type conversions and > user-defined literals in other statically typed languages. > > OK, let's get back to the original question. > > Apparently, there is no easy way to solve it with nested lists. > However, no one has touched the nested tuples so far. How can I write > a toString function that works similarly to mine but destructures > arbitrarily nested tuples? > > Thanks, > > Ali > > On Thu, Jul 23, 2015 at 9:41 AM, Imants Cekusins wrote: > > .. on the other hand, if facing this problem: > > - import large trees from concise human-readable representation as string > > > > , it is probably possible to write a parser which does just that. > > > > After all json parser works somehow ;) > > > > Just saying that you could do this in Haskell, given enough interest. > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ali.baharev at gmail.com Thu Jul 23 21:11:11 2015 From: ali.baharev at gmail.com (Ali Baharev) Date: Thu, 23 Jul 2015 23:11:11 +0200 Subject: [Haskell-beginners] Traversing generic trees In-Reply-To: References: Message-ID: Dear Bob, Thanks. OK, so you are saying that there is no easy way of doing it with nested tuples either. Well, that's disappointing. :( The custom parser is violating the third requirement ("without copying the data into some other datastructure first"). It is a learning exercise: I am trying to understand how to achieve certain things things in Haskell. I deliberately picked this exercise because it is very challenging to do it in certain statically typed languages, and I was curious how difficult it would be to solve it in Haskell. In my opinion, you can learn a lot about programming languages in general by re-implementing algorithms in them and comparing the difficulties you encountered on the way. Best wishes, Ali On Thu, Jul 23, 2015 at 9:38 PM, Bob Ippolito wrote: > You should not try and use the built-in lists or tuples to represent a tree > data structure. That's not what they're good at. You probably could make > tuples work and write functions using GHC.Generics to work with it as a tree > data structure, but it definitely won't be easy or elegant. If you want a > more economic syntax for expressing the tree you can provide shorter names > for Leaf and Node (one char isn't too bad), or else you're stuck with using > a parser. You may not have to write a parser though, perhaps JSON or YAML > would work fine for this. If it needs to go in the source file, there's > always TemplateHaskell and QuasiQuotes. > > On Thu, Jul 23, 2015 at 9:48 AM, Ali Baharev wrote: >> >> Dear All, >> >> I used to work at the University. Whenever a student asked me a >> question, I first focused on the question and tried to answer it. >> Sometimes the question was tough, maybe because there wasn't any easy >> solution to the problem. In those situations I used to say to my >> students: ?Problem well spotted, unfortunately I cannot give you an >> answer / there is no easy solution to this problem.? However, I have >> never started questioning the questions of my students, especially >> when I could not give them an answer. >> >> According to the Wiki on beginners at haskell.org: "Here, there is no >> such thing as a 'stupid question.'" If you start questioning my >> question, then I really do not know where to go... >> >> You might as well say: The whole question is pointless, just use >> Data.Tree and be done with it! >> >> It is really not part of the original question, and I sooo not want to >> get into a discussion over this: It is important to have language >> support for helping humans to input data, without a full-blown parser. >> Examples would be user-defined implicit type conversions and >> user-defined literals in other statically typed languages. >> >> OK, let's get back to the original question. >> >> Apparently, there is no easy way to solve it with nested lists. >> However, no one has touched the nested tuples so far. How can I write >> a toString function that works similarly to mine but destructures >> arbitrarily nested tuples? >> >> Thanks, >> >> Ali >> >> On Thu, Jul 23, 2015 at 9:41 AM, Imants Cekusins wrote: >> > .. on the other hand, if facing this problem: >> > - import large trees from concise human-readable representation as >> > string >> > >> > , it is probably possible to write a parser which does just that. >> > >> > After all json parser works somehow ;) >> > >> > Just saying that you could do this in Haskell, given enough interest. >> > _______________________________________________ >> > Beginners mailing list >> > Beginners at haskell.org >> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From bob at redivi.com Thu Jul 23 22:07:08 2015 From: bob at redivi.com (Bob Ippolito) Date: Thu, 23 Jul 2015 15:07:08 -0700 Subject: [Haskell-beginners] Traversing generic trees In-Reply-To: References: Message-ID: Well, you've picked the wrong beginner project :) This isn't really an algorithm that you're implementing, you're trying to reuse Haskell syntax to do something that it's not intended to do. Implementing algorithms in Haskell is a breeze if you are using a sane representation, but you need to use the right tools. On Thu, Jul 23, 2015 at 2:11 PM, Ali Baharev wrote: > Dear Bob, > > Thanks. OK, so you are saying that there is no easy way of doing it > with nested tuples either. Well, that's disappointing. :( > > The custom parser is violating the third requirement ("without copying > the data into some other datastructure first"). > > It is a learning exercise: I am trying to understand how to achieve > certain things things in Haskell. I deliberately picked this exercise > because it is very challenging to do it in certain statically typed > languages, and I was curious how difficult it would be to solve it in > Haskell. > > In my opinion, you can learn a lot about programming languages in > general by re-implementing algorithms in them and comparing the > difficulties you encountered on the way. > > Best wishes, > > Ali > > On Thu, Jul 23, 2015 at 9:38 PM, Bob Ippolito wrote: > > You should not try and use the built-in lists or tuples to represent a > tree > > data structure. That's not what they're good at. You probably could make > > tuples work and write functions using GHC.Generics to work with it as a > tree > > data structure, but it definitely won't be easy or elegant. If you want a > > more economic syntax for expressing the tree you can provide shorter > names > > for Leaf and Node (one char isn't too bad), or else you're stuck with > using > > a parser. You may not have to write a parser though, perhaps JSON or YAML > > would work fine for this. If it needs to go in the source file, there's > > always TemplateHaskell and QuasiQuotes. > > > > On Thu, Jul 23, 2015 at 9:48 AM, Ali Baharev > wrote: > >> > >> Dear All, > >> > >> I used to work at the University. Whenever a student asked me a > >> question, I first focused on the question and tried to answer it. > >> Sometimes the question was tough, maybe because there wasn't any easy > >> solution to the problem. In those situations I used to say to my > >> students: ?Problem well spotted, unfortunately I cannot give you an > >> answer / there is no easy solution to this problem.? However, I have > >> never started questioning the questions of my students, especially > >> when I could not give them an answer. > >> > >> According to the Wiki on beginners at haskell.org: "Here, there is no > >> such thing as a 'stupid question.'" If you start questioning my > >> question, then I really do not know where to go... > >> > >> You might as well say: The whole question is pointless, just use > >> Data.Tree and be done with it! > >> > >> It is really not part of the original question, and I sooo not want to > >> get into a discussion over this: It is important to have language > >> support for helping humans to input data, without a full-blown parser. > >> Examples would be user-defined implicit type conversions and > >> user-defined literals in other statically typed languages. > >> > >> OK, let's get back to the original question. > >> > >> Apparently, there is no easy way to solve it with nested lists. > >> However, no one has touched the nested tuples so far. How can I write > >> a toString function that works similarly to mine but destructures > >> arbitrarily nested tuples? > >> > >> Thanks, > >> > >> Ali > >> > >> On Thu, Jul 23, 2015 at 9:41 AM, Imants Cekusins > wrote: > >> > .. on the other hand, if facing this problem: > >> > - import large trees from concise human-readable representation as > >> > string > >> > > >> > , it is probably possible to write a parser which does just that. > >> > > >> > After all json parser works somehow ;) > >> > > >> > Just saying that you could do this in Haskell, given enough interest. > >> > _______________________________________________ > >> > Beginners mailing list > >> > Beginners at haskell.org > >> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > >> _______________________________________________ > >> Beginners mailing list > >> Beginners at haskell.org > >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tkoster at gmail.com Fri Jul 24 03:36:20 2015 From: tkoster at gmail.com (Thomas Koster) Date: Fri, 24 Jul 2015 13:36:20 +1000 Subject: [Haskell-beginners] Traversing generic trees In-Reply-To: References: Message-ID: Ali, On 23 July 2015 at 07:24, Ali Baharev wrote: > I have started learning Haskell recently, and I try to reimplement > interesting algorithms that are challenging to do in other languages. .. > The pretty > printing is not very pretty but the part that I am really not happy > with is the lot of code duplication in giving the tree. On Wed, Jul 22, 2015 at 11:51 PM, elliot wrote: > In general you don't produce large trees (or any data structure) by hand. On 23 July 2015 at 16:05, Thomas Koster wrote: > I am a Haskell novice myself, so don't take my advice as expert > opinion, but it sounds like you may have the wrong expectation about > what Haskell offers regarding "shorter", "cleaner", "purer" code. I > think Elliot was right to question your question. > > To get started, you should read this influential article by J. Hughes > [1][2]. > > [1] Hughes, J. "Why Functional Programming Matters", The Computer > Journal 32 (2), pp. 98-107, 1989. > [2] http://www.cse.chalmers.se/~rjmh/Papers/whyfp.html On 24 July 2015 at 02:48, Ali Baharev wrote: > I used to work at the University. ... > I have never started questioning the questions of my students, > especially when I could not give them an answer. ... > OK, let's get back to the original question. > > Apparently, there is no easy way to solve it with nested lists. > However, no one has touched the nested tuples so far. How can I write > a toString function that works similarly to mine but destructures > arbitrarily nested tuples? Sorry, my point was not to defend Elliot's useless response (he didn't actually respond to the list anyway). I admit that "to question your question" was a poor phraseology. >From your original email, your question regarding the efficacy of nested lists or tuples for implementing a tree data structure seems to have been motivated by a desire to reduce the amount of typing in a tree constant. The question itself has already been answered by others with "neither of these are appropriate." But now what? My point is that this exercise of saving some characters in the definitions of constants by fiddling with the data structure will not really lead to any useful intuitions about Haskell. Instead, Hug89 demonstrates two concepts (higher-order functions and laziness) that really do show you what makes non-strict functional languages like Haskell exceptional. Not only that, Hughes does this by talking you through some functions for lists, trees and numerical algorithms, which all sound very relevant to your learning project. -- Thomas Koster From twashing at gmail.com Sat Jul 25 17:30:26 2015 From: twashing at gmail.com (Timothy Washington) Date: Sat, 25 Jul 2015 10:30:26 -0700 Subject: [Haskell-beginners] Haskell equivalent to Clojure's partition fn Message-ID: Is there a Haskell equivalent to Clojure's partition function? I'm particularly interested in the stepwise feature, where we can select a certain `n` size of the list, then step `m` and take again. What's returned is a list of lists. Each list being a sublist incremented by `m`. I didn't see anything in the below packages. And I wanted to check before I go about writing my own. - Prelude - Data.List - Data.Array - Data.Vector Thanks Tim -------------- next part -------------- An HTML attachment was scrubbed... URL: From karl at karlv.net Sat Jul 25 17:42:48 2015 From: karl at karlv.net (Karl Voelker) Date: Sat, 25 Jul 2015 10:42:48 -0700 Subject: [Haskell-beginners] Haskell equivalent to Clojure's partition fn In-Reply-To: References: Message-ID: <1437846168.477037.332991041.44B5391A@webmail.messagingengine.com> On Sat, Jul 25, 2015, at 10:30 AM, Timothy Washington wrote: > Is there a Haskell equivalent to Clojure's partition[1] function? I'm > particularly interested in the stepwise feature, where we can select a > certain `n` size of the list, then step `m` and take again. This is a great use case for a type-based search engine. Luckily, we have some of those! Here is a search that matches your question, I think: http://hayoo.fh-wedel.de/?query=Int+-%3E+Int+-%3E+%5Ba%5D+-%3E+%5B%5Ba%5D%5D At this moment, there is one result, which appears to be exactly the thing you want. Unfortunately, it's an auxiliary function of a music theory package, which you may not want to install for that one function. There's a package called "split" that contains a bunch of useful tools for splitting lists. It doesn't have exactly what you want, but it does have a function called "chop" that will get you most of the way there: http://hackage.haskell.org/package/split-0.2.2/docs/Data-List-Split.html#v:chop -Karl Links: 1. http://clojuredocs.org/clojure.core/partition -------------- next part -------------- An HTML attachment was scrubbed... URL: From dserban01 at gmail.com Sat Jul 25 17:56:17 2015 From: dserban01 at gmail.com (Dan Serban) Date: Sat, 25 Jul 2015 20:56:17 +0300 Subject: [Haskell-beginners] Haskell equivalent to Clojure's partition fn In-Reply-To: References: Message-ID: It looks like chunksOf will take you most of the way there. Here's my quick and dirty GHCi session output: ?> import Data.List.Split ?> ?> let clojurePartition n m = map (take n) $ chunksOf (n+m) [0..] ?> ?> take 3 $ clojurePartition 4 6 [[0,1,2,3],[10,11,12,13],[20,21,22,23]] From twashing at gmail.com Sat Jul 25 19:28:59 2015 From: twashing at gmail.com (Timothy Washington) Date: Sat, 25 Jul 2015 12:28:59 -0700 Subject: [Haskell-beginners] Haskell equivalent to Clojure's partition fn In-Reply-To: References: Message-ID: While I can say A), what I really need is B) *A)* > *take 5 $ chunksOf 10 [0..]* [[0,1,2,3,4,5,6,7,8,9],[10,11,12,13,14,15,16,17,18,19],[20,21,22,23,24,25,26,27,28,29],[30,31,32,33,34,35,36,37,38,39],[40,41,42,43,44,45,46,47,48,49]] *B)* > take 5 $ someFn 10 1 [0..] [[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,9,10],[2,3,4,5,6,7,8,9,10,11],[3,4,5,6,7,8,9,10,11,12],[4,5,6,7,8,9,10,11,12,13]] The music theory package indeed has a working partition function (source here ). The implementation simply *i)* takes `n` from the source list, *ii)* drops by `m` then recurses. segments :: Int -> Int -> [a] -> [[a]] segments n m p = let q = take n p p' = drop m p in if length q /= n then [] else q : segments n m p' But that's rather manual. So I played around with this using *chop*, and came up with the *divvy* function. It does exactly what I need. divvy :: Int -> Int -> [a] -> [[a]] divvy n m lst = chop (\xs -> (take n xs , drop m xs)) lst > *take 5 $ partitionClojure 10 1 [0..]* [[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,9,10],[2,3,4,5,6,7,8,9,10,11],[3,4,5,6,7,8,9,10,11,12],[4,5,6,7,8,9,10,11,12,13]] Thanks guys. This helped a lot :) Tim On Sat, Jul 25, 2015 at 10:56 AM, Dan Serban wrote: > It looks like chunksOf will take you most of the way there. Here's my > quick and dirty GHCi session output: > > ?> import Data.List.Split > ?> > ?> let clojurePartition n m = map (take n) $ chunksOf (n+m) [0..] > ?> > ?> take 3 $ clojurePartition 4 6 > [[0,1,2,3],[10,11,12,13],[20,21,22,23]] > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jzdudek at gmail.com Sun Jul 26 21:01:51 2015 From: jzdudek at gmail.com (Jacek Dudek) Date: Sun, 26 Jul 2015 17:01:51 -0400 Subject: [Haskell-beginners] Haskell equivalent to Clojure's partition fn In-Reply-To: References: Message-ID: Hi Timothy, You might want to check out the split package. Here's the link: http://hackage.haskell.org/package/split On 7/25/15, Timothy Washington wrote: > While I can say A), what I really need is B) > > *A)* > *take 5 $ chunksOf 10 [0..]* > [[0,1,2,3,4,5,6,7,8,9],[10,11,12,13,14,15,16,17,18,19],[20,21,22,23,24,25,26,27,28,29],[30,31,32,33,34,35,36,37,38,39],[40,41,42,43,44,45,46,47,48,49]] > > *B)* > take 5 $ someFn 10 1 [0..] > [[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,9,10],[2,3,4,5,6,7,8,9,10,11],[3,4,5,6,7,8,9,10,11,12],[4,5,6,7,8,9,10,11,12,13]] > > > The music theory package indeed has a working partition function (source > here ). The > implementation simply *i)* takes `n` from the source list, *ii)* drops by > `m` then recurses. > > segments :: Int -> Int -> [a] -> [[a]] > segments n m p = > let q = take n p > p' = drop m p > in if length q /= n then [] else q : segments n m p' > > > > But that's rather manual. So I played around with this using *chop*, and > came up with the *divvy* function. It does exactly what I need. > > divvy :: Int -> Int -> [a] -> [[a]] > divvy n m lst = > chop (\xs -> (take n xs , drop m xs)) lst > > >> *take 5 $ partitionClojure 10 1 [0..]* > [[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,9,10],[2,3,4,5,6,7,8,9,10,11],[3,4,5,6,7,8,9,10,11,12],[4,5,6,7,8,9,10,11,12,13]] > > > Thanks guys. This helped a lot :) > > > Tim > > > On Sat, Jul 25, 2015 at 10:56 AM, Dan Serban wrote: > >> It looks like chunksOf will take you most of the way there. Here's my >> quick and dirty GHCi session output: >> >> ?> import Data.List.Split >> ?> >> ?> let clojurePartition n m = map (take n) $ chunksOf (n+m) [0..] >> ?> >> ?> take 3 $ clojurePartition 4 6 >> [[0,1,2,3],[10,11,12,13],[20,21,22,23]] >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > From driemer.riemer at gmail.com Thu Jul 30 13:16:25 2015 From: driemer.riemer at gmail.com (derek riemer) Date: Thu, 30 Jul 2015 07:16:25 -0600 Subject: [Haskell-beginners] How to define ord manually. Message-ID: <55BA23A9.5040204@gmail.com> Hi, I was playing around with haskell, and decided to implement a RockPaperScissors type. data RPS= Rock | Paper | Scissors Then I manually derived show for fun. instance Show RPS where show Rock = "rock" show Paper = "paper" show Scissors = "scissors" But, I have a problem when defining ord. How do I look in the sourcecode for ord? In ghci I did prelude> :i Ord Ord (a, b, c, d, e, f, g, h, i, j) -- Defined in `GHC.Classes' instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i) => Ord (a, b, c, d, e, f, g, h, i) -- Defined in `GHC.Classes' instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h) => Ord (a, b, c, d, e, f, g, h) -- Defined in `GHC.Classes' instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g) => Ord (a, b, c, d, e, f, g) -- Defined in `GHC.Classes' instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f) => Ord (a, b, c, d, e, f) -- Defined in `GHC.Classes' instance (Ord a, Ord b, Ord c, Ord d, Ord e) => Ord (a, b, c, d, e) -- Defined in `GHC.Classes' instance (Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d) -- Defined in `GHC.Classes' instance (Ord a, Ord b, Ord c) => Ord (a, b, c) -- Defined in `GHC.Classes' instance (Ord a, Ord b) => Ord (a, b) -- Defined in `GHC.Classes' instance Ord () -- Defined in `GHC.Classes' Prelude> Where is ghc.classes? I looked under the ghc directory and didn't find a classes.hs file. I tried defining it as such. instance Ord RPS where ord Scissors `compare` Rock = LT ord Paper `compare` Scissors = LT ord Rock `compare` Paper = LT But this fails with verry little errors, and I really don't know how I define an instance of Ord for this. I want rock to be less than paper, but greater than scissors, scissors to be less than rock but greater than paper, and paper to be greater than rock but less than scissors. Kind of geeky, but it's one way of learning. Also, What is the best way to write useful programs, One example I tried is to make a simple guess what I am guessing game, but I couldn't make heads or tails of the IO typeclasses, or the System.Random module. How can I possibly get random numbers and do things on them, and does this mean main must be imperative with a do statement? Thanks, Derek From nda at informatik.uni-kiel.de Thu Jul 30 13:34:12 2015 From: nda at informatik.uni-kiel.de (Nikita Danilenko) Date: Thu, 30 Jul 2015 15:34:12 +0200 Subject: [Haskell-beginners] How to define ord manually. In-Reply-To: <55BA23A9.5040204@gmail.com> References: <55BA23A9.5040204@gmail.com> Message-ID: <55BA27D4.4060500@informatik.uni-kiel.de> Hi Derek, you can find the desired functions and type classes using Hoogle [1]. Your attempt at an Ord instance is basically the right idea, but you need to define the function "compare" only [2]. From your syntax it looks like you are trying to define a function called "ord" that additionally uses "compare" (in a way, it cannot be used). Removing "ord" in all three cases fixes your problem, although the resulting function "compare" is not total. The documentation of the type classes usually contains a description of what functions you need to define. The fact that the "Show" type class instance can be obtained using a function called "show" is a coincidence. Best regards, Nikita [1] https://www.haskell.org/hoogle/ [2] http://hackage.haskell.org/package/base-4.8.1.0/docs/Prelude.html#t:Ord On 30/07/15 15:16, derek riemer wrote: > Hi, > I was playing around with haskell, and decided to implement a > RockPaperScissors type. > > data RPS= Rock | Paper | Scissors > Then I manually derived show for fun. > instance Show RPS where > show Rock = "rock" > show Paper = "paper" > show Scissors = "scissors" > > But, I have a problem when defining ord. > How do I look in the sourcecode for ord? > In ghci I did > prelude> :i Ord > > Ord (a, b, c, d, e, f, g, h, i, j) > -- Defined in `GHC.Classes' > instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, > Ord i) => > Ord (a, b, c, d, e, f, g, h, i) > -- Defined in `GHC.Classes' > instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, > Ord h) => > Ord (a, b, c, d, e, f, g, h) > -- Defined in `GHC.Classes' > instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g) => > Ord (a, b, c, d, e, f, g) > -- Defined in `GHC.Classes' > instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f) => > Ord (a, b, c, d, e, f) > -- Defined in `GHC.Classes' > instance (Ord a, Ord b, Ord c, Ord d, Ord e) => Ord (a, b, c, d, e) > -- Defined in `GHC.Classes' > instance (Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d) > -- Defined in `GHC.Classes' > instance (Ord a, Ord b, Ord c) => Ord (a, b, c) > -- Defined in `GHC.Classes' > instance (Ord a, Ord b) => Ord (a, b) -- Defined in `GHC.Classes' > instance Ord () -- Defined in `GHC.Classes' > Prelude> > Where is ghc.classes? I looked under the ghc directory and didn't find a > classes.hs file. > > I tried defining it as such. > > instance Ord RPS where > ord Scissors `compare` Rock = LT > ord Paper `compare` Scissors = LT > ord Rock `compare` Paper = LT > > But this fails with verry little errors, and I really don't know how I > define an instance of Ord for this. > I want rock to be less than paper, but greater than scissors, > scissors to be less than rock but greater than paper, > and paper to be greater than rock but less than scissors. > Kind of geeky, but it's one way of learning. > > Also, What is the best way to write useful programs, > One example I tried is to make a simple guess what I am guessing game, > but I couldn't make heads or tails of the IO typeclasses, or the > System.Random module. How can I possibly get random numbers and do > things on them, and does this mean main must be imperative with a do > statement? > Thanks, > Derek > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -- Dipl.-Math. Nikita Danilenko Research group: Computer Aided Program Development Kiel University Olshausenstr. 40, D-24098 Kiel Phone: +49 431 880 7275 URL: https://www.informatik.uni-kiel.de/index.php?id=nikita -------------- next part -------------- A non-text attachment was scrubbed... Name: 0x76C229F0.asc Type: application/pgp-keys Size: 8170 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From marcin.jan.mrotek at gmail.com Thu Jul 30 13:38:06 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Thu, 30 Jul 2015 16:38:06 +0300 Subject: [Haskell-beginners] How to define ord manually. In-Reply-To: <55BA23A9.5040204@gmail.com> References: <55BA23A9.5040204@gmail.com> Message-ID: The first Google result: https://hackage.haskell.org/package/base-4.8.1.0/docs/Data-Ord.html It says right there that you need to define (at least) either "compare" or "<=", and that there's no "ord" function. Best regards, Marcin Mrotek -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Thu Jul 30 14:10:47 2015 From: imantc at gmail.com (Imants Cekusins) Date: Thu, 30 Jul 2015 16:10:47 +0200 Subject: [Haskell-beginners] How to define ord manually. In-Reply-To: References: <55BA23A9.5040204@gmail.com> Message-ID: Derek, if you face any questions, feel free to write here. The search engines are there alright but humans do tend to communicate. Even if it may be in the books somewhere. Nothing wrong with that ;) From chaddai.fouche at gmail.com Thu Jul 30 14:42:43 2015 From: chaddai.fouche at gmail.com (=?UTF-8?B?Q2hhZGRhw68gRm91Y2jDqQ==?=) Date: Thu, 30 Jul 2015 14:42:43 +0000 Subject: [Haskell-beginners] How to define ord manually. In-Reply-To: <55BA27D4.4060500@informatik.uni-kiel.de> References: <55BA23A9.5040204@gmail.com> <55BA27D4.4060500@informatik.uni-kiel.de> Message-ID: While you may define this *Ord* instance by defining the *compare* method, you should probably not do this since *Ord* is supposed to follow some rules, in particular transitivity "*a < b and b < c means a < c*" is assumed but false in your case. Those rules are important for many functions to work correctly (sort, minimum, maximum and so on...). You may simply define another function like *winAgainst* : *Rock `winAgainst` Scissors = True* *Scissors `winAgainst` Paper = True* *Paper `winAgainst` Rock = True_ `winAgainst` _ = False* or maybe a *battle* function that returns a *Win | Loss | Tie*... (NB : All functions can be used as infix by surrounding their name with ` (antiquotes)) Le jeu. 30 juil. 2015 ? 15:34, Nikita Danilenko a ?crit : > Hi Derek, > > you can find the desired functions and type classes using Hoogle [1]. > Your attempt at an Ord instance is basically the right idea, but you > need to define the function "compare" only [2]. From your syntax it > looks like you are trying to define a function called "ord" that > additionally uses "compare" (in a way, it cannot be used). Removing > "ord" in all three cases fixes your problem, although the resulting > function "compare" is not total. > > The documentation of the type classes usually contains a description of > what functions you need to define. The fact that the "Show" type class > instance can be obtained using a function called "show" is a coincidence. > > Best regards, > > Nikita > > [1] https://www.haskell.org/hoogle/ > > [2] > http://hackage.haskell.org/package/base-4.8.1.0/docs/Prelude.html#t:Ord > -------------- next part -------------- An HTML attachment was scrubbed... URL: From driemer.riemer at gmail.com Fri Jul 31 15:30:35 2015 From: driemer.riemer at gmail.com (derek riemer) Date: Fri, 31 Jul 2015 09:30:35 -0600 Subject: [Haskell-beginners] An unsigned int class. Message-ID: <55BB949B.9080800@gmail.com> Is there anything in haskell that represents an unsigned Int class? namely, something bounded below at 0? If not, is it possible to define an Int in this way to add the bounded constraint (I can't immagine trying to define Int like this, there has got to be a better way that I haven't quite understood in my study of haskell). data UnsignedInt = 0 | 1 | 2 | (...) for a long time doing that ... deriving (Show, Eq, Ord, Bounded, Read) Thanks, Derek From allbery.b at gmail.com Fri Jul 31 15:32:45 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Fri, 31 Jul 2015 11:32:45 -0400 Subject: [Haskell-beginners] An unsigned int class. In-Reply-To: <55BB949B.9080800@gmail.com> References: <55BB949B.9080800@gmail.com> Message-ID: On Fri, Jul 31, 2015 at 11:30 AM, derek riemer wrote: > Is there anything in haskell that represents an unsigned Int class? It's a type, not a class. "Class" implies something very different in Haskell. And I think you're looking for the "Word" type from Data.Word. http://lambda.haskell.org/platform/doc/current/ghc-doc/libraries/haskell2010-1.1.1.0/Data-Word.html -- 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 marcin.jan.mrotek at gmail.com Fri Jul 31 16:08:33 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Fri, 31 Jul 2015 18:08:33 +0200 Subject: [Haskell-beginners] An unsigned int class. In-Reply-To: References: <55BB949B.9080800@gmail.com> Message-ID: Hello, If you're interested in numbers from 0 upto bignums, there's also Numeric.Natural: https://hackage.haskell.org/package/base-4.8.1.0/docs/Numeric-Natural.html Best regards, Marcin Mrotek -------------- next part -------------- An HTML attachment was scrubbed... URL: From david.obwaller at gmx.at Fri Jul 31 19:08:38 2015 From: david.obwaller at gmx.at (David Obwaller) Date: Fri, 31 Jul 2015 21:08:38 +0200 Subject: [Haskell-beginners] An unsigned int class. In-Reply-To: <55BB949B.9080800@gmail.com> References: <55BB949B.9080800@gmail.com> Message-ID: <20150731190838.GA8061@davids-mbp> Hi, On Fri, Jul 31, 2015 at 09:30:35AM -0600, derek riemer wrote: > Is there anything in haskell that represents an unsigned Int class? > namely, something bounded below at 0? The module Data.Word provides unsigned integral types with modular arithmetic: Word (same size as Int), Word8, Word16, etc. $ ghci > import Data.Word ... > maxBound :: Word 18446744073709551615 > maxBound :: Word8 255 > maxBound :: Word32 4294967295 > 0 - 1 :: Word8 255 > maxBound + 1 :: Word8 0 Is that what you are looking for? http://hackage.haskell.org/package/base-4.8.1.0/docs/Data-Word.html David