From voldermort at hotmail.com Thu Aug 1 17:00:59 2013 From: voldermort at hotmail.com (vold) Date: Thu, 1 Aug 2013 15:00:59 +0000 (UTC) Subject: [Haskell-beginners] maybe in IO Message-ID: I've defined a function similar to check x assoc = let found = lookup x assoc in when (isJust found) $putStrLn$ "found " ++ fromJust found which I've used several times from within the IO monad. Is there a more compact way of doing this? From gesh at gesh.uni.cx Thu Aug 1 17:09:11 2013 From: gesh at gesh.uni.cx (Gesh hseG) Date: Thu, 1 Aug 2013 18:09:11 +0300 Subject: [Haskell-beginners] Shorten this code In-Reply-To: References: Message-ID: On Wed, Jul 24, 2013 at 4:18 PM, Henk-Jan van Tuyl wrote: > On Tue, 23 Jul 2013 12:41:32 +0200, Nadav Chernin > wrote: > >> Hi, all >> Below is my solution to SPOJ->Polybius >> square >> >> >> Please try to shorten it: >> >> *import Data.Maybe* >> *d=[1..5]* >> *f s=unwords$map(\c->fromJust$lookup c((' >> ',""):('J',"24"):zip(['A'..'I']++['K'..'Z'])[show(x+10*y)|y<-d,x<-d]))s* >> *main=getLine>>(interact$unlines.map f.lines)* > d="12345" > f s = unwords$ map (\c -> let (Just x) = lookup c ((' ',"") : ('J',"24") : > zip (['A'..'I'] ++ ['K'..'Z']) [y : [x] | y <- d, x <- d]) in x) s > main = getLine >> (interact $unlines . map f . lines) Note that you can point-freeify that solution a little and sacrifice totality, yielding an even shorter solution. (I didn't remove the lambda expression, as it ends up being shorter than flipping lookup) Inline the definitions and remove redundant spaces and newlines in the code below: d = "12345" f = unwords . map$ \c -> fromJust $lookup c ((' ',"") : ('J',"24") : zip (['A'..'Z']\\"J") [[y,x] | y <- d, x <- d]) main = interact$ unlines . map f . drop 1 . lines Just my two cents. Gesh From gtener at gmail.com Thu Aug 1 17:34:15 2013 From: gtener at gmail.com (=?UTF-8?Q?Krzysztof_Skrz=C4=99tnicki?=) Date: Thu, 1 Aug 2013 17:34:15 +0200 Subject: [Haskell-beginners] maybe in IO In-Reply-To: References: Message-ID: I'd rather use pattern matching in this case: check x assoc = case lookup x of Just found -> putStrLn ("found " ++ found) _ -> Not really shorter but I think it's cleaner this way. On Thu, Aug 1, 2013 at 5:00 PM, vold wrote: > I've defined a function similar to > > check x assoc = let found = lookup x assoc in > when (isJust found) $putStrLn$ "found " ++ fromJust > found > > which I've used several times from within the IO monad. Is there a more > compact way of doing this? > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gtener at gmail.com Thu Aug 1 17:35:22 2013 From: gtener at gmail.com (=?UTF-8?Q?Krzysztof_Skrz=C4=99tnicki?=) Date: Thu, 1 Aug 2013 17:35:22 +0200 Subject: [Haskell-beginners] maybe in IO In-Reply-To: References: Message-ID: Of course there is "return ()" missing. check x assoc = case lookup x of Just found -> putStrLn ("found " ++ found) _ -> return () On Thu, Aug 1, 2013 at 5:34 PM, Krzysztof Skrz?tnicki wrote: > I'd rather use pattern matching in this case: > > check x assoc = case lookup x of > Just found -> putStrLn ("found " ++ found) > _ -> > > Not really shorter but I think it's cleaner this way. > > > > > On Thu, Aug 1, 2013 at 5:00 PM, vold wrote: > >> I've defined a function similar to >> >> check x assoc = let found = lookup x assoc in >> when (isJust found) $putStrLn$ "found " ++ fromJust >> found >> >> which I've used several times from within the IO monad. Is there a more >> compact way of doing this? >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gesh at gesh.uni.cx Thu Aug 1 17:39:22 2013 From: gesh at gesh.uni.cx (Gesh hseG) Date: Thu, 1 Aug 2013 18:39:22 +0300 Subject: [Haskell-beginners] maybe in IO In-Reply-To: References: Message-ID: On Thu, Aug 1, 2013 at 6:00 PM, vold wrote: > I've defined a function similar to > > check x assoc = let found = lookup x assoc in > when (isJust found) $putStrLn$ "found " ++ fromJust found > > which I've used several times from within the IO monad. Is there a more > compact way of doing this? Firstly, note that it is more idiomatic to move the IO code to other functions, which would allow check to be pure. Secondly, one can use the fact that Maybe is a Functor to rewrite check as follows: check x db = maybeToIO $(putStrLn . ("found"++)) <$> x lookup db where maybeToIO = fromMaybe (return ()) The refactoring of maybeToIO isn't strictly necessary, but I found it clearer. HTH, Gesh From michael at orlitzky.com Thu Aug 1 17:45:02 2013 From: michael at orlitzky.com (Michael Orlitzky) Date: Thu, 01 Aug 2013 11:45:02 -0400 Subject: [Haskell-beginners] maybe in IO In-Reply-To: References: Message-ID: <51FA827E.8070609@orlitzky.com> On 08/01/2013 11:00 AM, vold wrote: > I've defined a function similar to > > check x assoc = let found = lookup x assoc in > when (isJust found) $putStrLn$ "found " ++ fromJust found > > which I've used several times from within the IO monad. Is there a more > compact way of doing this? > maybe (return ()) (putStrLn . ("found " ++)) found is the best I could do. From hjgtuyl at chello.nl Fri Aug 2 00:18:14 2013 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Fri, 02 Aug 2013 00:18:14 +0200 Subject: [Haskell-beginners] Shorten this code In-Reply-To: References: Message-ID: On Thu, 01 Aug 2013 17:09:11 +0200, Gesh hseG wrote: > On Wed, Jul 24, 2013 at 4:18 PM, Henk-Jan van Tuyl > wrote: >> d="12345" >> f s = unwords $map (\c -> let (Just x) = lookup c ((' ',"") : >> ('J',"24") : >> zip (['A'..'I'] ++ ['K'..'Z']) [y : [x] | y <- d, x <- d]) in x) s >> main = getLine >> (interact$ unlines . map f . lines) > > Note that you can point-freeify that solution a little and sacrifice > totality, > yielding an even shorter solution. (I didn't remove the lambda > expression, > as it ends up being shorter than flipping lookup) > Inline the definitions and remove redundant spaces and newlines > in the code below: > d = "12345" > f = unwords . map $> \c -> fromJust$ lookup c ((' ',"") : ('J',"24") : zip > (['A'..'Z']\\"J") [[y,x] | y <- d, x <- d]) > main = interact $unlines . map f . drop 1 . lines There are imports necessary for fromJust and \\, this makes it longer again. Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From chris at christopher-schneider.com Mon Aug 5 06:05:47 2013 From: chris at christopher-schneider.com (Chris Schneider) Date: Sun, 4 Aug 2013 22:05:47 -0600 Subject: [Haskell-beginners] Threading (lack of) interleaving Message-ID: Hi, I'm working on a program that should launch, spawn two threads, each with a zeromq connection, where those threads ping the zmq channel repeatedly. The main thread just sits and waits. The code is here: https://gist.github.com/cschneid/3862b33c29a803be7848 If I launch one thread, or the other (lines 13 & 14), and comment the other one out, it runs as expected. But if I attempt to launch both, both build themselves, and run one call of themselves, but then it seems that one or the other thread "wins", and the other never gets to run again. Most of the time it's the first one launched that wins, but not always. See the output for an example. Adding explicit yield calls, using forkOS vs forkIO, and moving around of where I make the ZMQ context & socket (into and out of the threads) don't seem to help. What am I missing? How can I get these threads to play nice with each other? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at christopher-schneider.com Mon Aug 5 17:11:04 2013 From: chris at christopher-schneider.com (Chris Schneider) Date: Mon, 5 Aug 2013 09:11:04 -0600 Subject: [Haskell-beginners] Threading (lack of) interleaving In-Reply-To: References: Message-ID: Ok, I've figured out my problem - it wasn't threading related at all - instead it was the second thread dying off due to a ZMQ problem. Specifically I was reusing the node name, which apparently isn't allowed. Tweaking it such that it uses a different name for each fixes the issue. On Sun, Aug 4, 2013 at 10:05 PM, Chris Schneider < chris at christopher-schneider.com> wrote: > Hi, I'm working on a program that should launch, spawn two threads, each > with a zeromq connection, where those threads ping the zmq channel > repeatedly. The main thread just sits and waits. > > The code is here: https://gist.github.com/cschneid/3862b33c29a803be7848 > > If I launch one thread, or the other (lines 13 & 14), and comment the > other one out, it runs as expected. > > But if I attempt to launch both, both build themselves, and run one call > of themselves, but then it seems that one or the other thread "wins", and > the other never gets to run again. Most of the time it's the first one > launched that wins, but not always. See the output for an example. > > Adding explicit yield calls, using forkOS vs forkIO, and moving around of > where I make the ZMQ context & socket (into and out of the threads) don't > seem to help. > > What am I missing? How can I get these threads to play nice with each > other? > > Thanks! > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Mon Aug 5 21:37:18 2013 From: martin.drautzburg at web.de (martin) Date: Mon, 05 Aug 2013 21:37:18 +0200 Subject: [Haskell-beginners] How to construct complex string Message-ID: <51FFFEEE.5050209@web.de> Hello all, recently I was working on a haskell program, which does some calculations and the produces a "plot", i.e. a set of Tikz (a LaTeX thing) commands. While this was not a problem in itself, it lacked composability. While all my plots show a grid, a caption and some data points, some of them additionally show a line with a legend, some of them show two. Now I clearly do not want to duplicate the entire function just to add another line. I'd rather construct the Tikz commands (which at the end of the day is just a String) in a stepwise fashion. When constructing the set of Tikz commands, I cannot rely that additional commands are placed at the end. It is typically more an inside-out thing. The last thing I need to do is wrap the whole thing in \begin and \end directives. Additionally there may be "global" values (like the scale) which need to be known at more than one step. I had a brief look at the "Diagrams" package, which MUST have similar issues, and they "do everything with monoids", but I fail to see the light. Could anyone point me in the right direction? From stephen.tetley at gmail.com Tue Aug 6 19:01:45 2013 From: stephen.tetley at gmail.com (Stephen Tetley) Date: Tue, 6 Aug 2013 18:01:45 +0100 Subject: [Haskell-beginners] How to construct complex string In-Reply-To: <51FFFEEE.5050209@web.de> References: <51FFFEEE.5050209@web.de> Message-ID: Hi Martin If you are building syntax as a sequence of commands (or statements) a common idiom is to collect them with a Writer monad. Andy Gill's Dotgen on Hackage is a nice realization of this idiom. See the how example included in the package has acceptably nice syntax without obliging the implementation to use complex facilities such as Template Haskell. In the source code, the data type GraphElement represents the main statement types in GraphViz's "dot" language. The data type Dot is the monad - here a combination of a Writer monad and a State monad, with the State monad supplying unique integers for fresh identifiers. The monad is written as a direct combination of State and Writer (it is perhaps more common to rely on _monad transformers_ but once you know what you are looking at, Andy's code is simple and clear). http://hackage.haskell.org/package/dotgen Best wishes Stephen -------------- next part -------------- An HTML attachment was scrubbed... URL: From voldermort at hotmail.com Wed Aug 7 09:23:34 2013 From: voldermort at hotmail.com (vold) Date: Wed, 7 Aug 2013 07:23:34 +0000 (UTC) Subject: [Haskell-beginners] Why is my GHC bigger than the distribution Message-ID: I've built GHC 7.6.3 from source using the default "perf" settings, and all my programs are about 4 Mb bigger after linking than if I used the pre-built binary. What could be causing this? (x64 Linux with gold linker.) From voldermort at hotmail.com Wed Aug 7 09:33:10 2013 From: voldermort at hotmail.com (vold) Date: Wed, 7 Aug 2013 07:33:10 +0000 (UTC) Subject: [Haskell-beginners] Why is my GHC bigger than the distribution References: Message-ID: vold hotmail.com> writes: Sorry, that wasn't completely clear. It's both the GHC binary itself and everything build by GHC which is a few MB bigger. From voldermort at hotmail.com Wed Aug 7 10:00:15 2013 From: voldermort at hotmail.com (vold) Date: Wed, 7 Aug 2013 08:00:15 +0000 (UTC) Subject: [Haskell-beginners] Why is my GHC bigger than the distribution References: Message-ID: vold hotmail.com> writes: Now I've noticed something even weirder - if I replace the GHC binary from the binary distribution with the one I built, the executables I produce with it are the original size. From chris at christopher-schneider.com Wed Aug 7 19:04:15 2013 From: chris at christopher-schneider.com (Chris Schneider) Date: Wed, 7 Aug 2013 11:04:15 -0600 Subject: [Haskell-beginners] Showing a value, when there are many approaches? Message-ID: Hi, I'm writing a module that contains a data type for a MacAddress. Given that, I can do things like validate and format. But there are several ways you can display a MacAddress: 'aabbccddeeff' or '00:11:22:33:AA:BB' or 'aa:bb:cc:00:11:22'. Different external systems want the mac addresses in different formats, and I'd like to centralize that logic. ** So the design question: I can't just use a show function directly to do this, since there are options I need to pass. I could use separate functions that return a string. I could use newtype to wrap each display style of mac address in a type that has a specific show instance that spits out the right format. So a Pretty and Lower and similar types. --- Is there a best-practice here? Am I totally missing a better way to model this idea? -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Wed Aug 7 19:35:03 2013 From: toad3k at gmail.com (David McBride) Date: Wed, 7 Aug 2013 13:35:03 -0400 Subject: [Haskell-beginners] Showing a value, when there are many approaches? In-Reply-To: References: Message-ID: Show is not meant to necessarily be human readable. It is meant to be the exact opposite of Read. You show it, then you read it back in and it is unambiguous. Having different ways to show it kind of defeats the purpose of show. Most people just make a custom function that takes a macaddress and some other parameter to determine which format you want it to be output as and then just use that. On Wed, Aug 7, 2013 at 1:04 PM, Chris Schneider < chris at christopher-schneider.com> wrote: > Hi, I'm writing a module that contains a data type for a MacAddress. > > Given that, I can do things like validate and format. > > But there are several ways you can display a MacAddress: > > 'aabbccddeeff' or '00:11:22:33:AA:BB' or 'aa:bb:cc:00:11:22'. > > Different external systems want the mac addresses in different formats, > and I'd like to centralize that logic. > > ** So the design question: > > I can't just use a show function directly to do this, since there are > options I need to pass. > > I could use separate functions that return a string. > > I could use newtype to wrap each display style of mac address in a type > that has a specific show instance that spits out the right format. So a > Pretty and Lower and similar types. > > --- > > Is there a best-practice here? Am I totally missing a better way to model > this idea? > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike at fpcomplete.com Wed Aug 7 20:02:39 2013 From: mike at fpcomplete.com (Mike Meyer) Date: Wed, 7 Aug 2013 13:02:39 -0500 Subject: [Haskell-beginners] Looking for judges for haskell competition Message-ID: In order to foster commercial use of Haskell, FP Complete is running a competition for monthly cash prizes (details https://www.fpcomplete.com/blog/2013/07/competition-announcement). We are looking for judges from the community. People helping beginners would seem to be a good fit for this. If you're interested, could you please drop me a note along with pertinent information? Thanks, Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike at fpcomplete.com Wed Aug 7 20:16:44 2013 From: mike at fpcomplete.com (Mike Meyer) Date: Wed, 7 Aug 2013 13:16:44 -0500 Subject: [Haskell-beginners] Enterprise-quality XML library? Message-ID: I've been looking for an enterprise-grade XML library. My standard for comparison is Python's lxml library (a wrapper around libxml2 and libxslt). The only thing I've found that's even close is hxt, and it falls a bit short. Specifically, when I feed it invalid XML, I get this error: error: The content of element "school" must match ( "author"* ). Element "author" expected, but element "auther" found. error: Element "auther" not declared in DTD. Whereas from lxml I get: lxml.etree.XMLSyntaxError: No declaration for attribute name of element auther, line 24, column 19 This is shorter and clearer, and identifies the location of the error. It does have better error messages for ill-formed XML. Is there a library with a validating parser that provides better quality error messages? It also seems like mapping an XML Schema into a collection of Haskell types should be a function of the library. Is there on that does that, or is this completely untenable? -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Wed Aug 7 20:51:15 2013 From: allbery.b at gmail.com (Brandon Allbery) Date: Wed, 7 Aug 2013 14:51:15 -0400 Subject: [Haskell-beginners] Showing a value, when there are many approaches? In-Reply-To: References: Message-ID: On Wed, Aug 7, 2013 at 1:04 PM, Chris Schneider < chris at christopher-schneider.com> wrote: > I can't just use a show function directly to do this, since there are > options I need to pass. > And you shouldn't use show for this, because if it prints your MacAddress as anything other than an unambiguous representation of the Haskell MacAddress type then it has lost information useful for debugging. More to the point: if I cannot see the difference between your MacAddress and a String, then it's an unacceptable show. show should reflect the Haskell data structure so I can verify that my program is doing the right thing; if it shows what looks like a String, but I'm expecting to see a MacAddress, then I will suspect a type error somewhere. show is like Perl's Data::Dumper or Python's repr. I don't want pretty, I want accuracy. -- 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 byorgey at seas.upenn.edu Wed Aug 7 21:15:12 2013 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Wed, 7 Aug 2013 15:15:12 -0400 Subject: [Haskell-beginners] How to construct complex string In-Reply-To: <51FFFEEE.5050209@web.de> References: <51FFFEEE.5050209@web.de> Message-ID: <20130807191512.GA7929@seas.upenn.edu> On Mon, Aug 05, 2013 at 09:37:18PM +0200, martin wrote: > Hello all, > > recently I was working on a haskell program, which does some > calculations and the produces a "plot", i.e. a set of Tikz (a LaTeX > thing) commands. > > While this was not a problem in itself, it lacked composability. While > all my plots show a grid, a caption and some data points, some of them > additionally show a line with a legend, some of them show two. > > Now I clearly do not want to duplicate the entire function just to add > another line. I'd rather construct the Tikz commands (which at the end > of the day is just a String) in a stepwise fashion. > > When constructing the set of Tikz commands, I cannot rely that > additional commands are placed at the end. It is typically more an > inside-out thing. The last thing I need to do is wrap the whole thing in > \begin and \end directives. Hi Martin, I think the key thing you are missing is that a String is just a particular concrete representation of a TikZ program. That is not what a TikZ program really *is*. Instead, TikZ programs are trees. String is nice for storing a program in a file, but it is a terrible representation to use when working with programs, whether generating them, type-checking them, or whatever. As you have discovered, when working with Strings you have to insert stuff at various arbitrary places (at the beginning, the end, the middle), which is quite annoying and difficult (especially the middle!), whereas those same operations are simple on a tree representation of the program. To do what you are trying to do in a nice way would require (1) making an algebraic data type to represent the structure of TikZ programs (2) changing your program so that it generates values of this type, instead of Strings, and (3) making a single function to convert a value of this type into a String. This can be quite a bit of work up front, but well worth it if you are going to do more than just a bit of TikZ generation. With that said, however, did you know there is a TikZ backend for diagrams? [1] It should be possible for you to describe your plots using diagrams and then output them to TikZ (or any other format for which diagrams has a backend---SVG, PDF, PS, or PNG). I have not looked at it recently but would be happy to support it if you run into any problems (I will probably want it myself sooner or later). [1] http://hackage.haskell.org/package/diagrams%2Dtikz -Brent > > Additionally there may be "global" values (like the scale) which need to > be known at more than one step. I had a brief look at the "Diagrams" > package, which MUST have similar issues, and they "do everything with > monoids", but I fail to see the light. > > Could anyone point me in the right direction? > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners From chris at christopher-schneider.com Wed Aug 7 21:47:55 2013 From: chris at christopher-schneider.com (Chris Schneider) Date: Wed, 7 Aug 2013 13:47:55 -0600 Subject: [Haskell-beginners] Showing a value, when there are many approaches? In-Reply-To: References: Message-ID: Ok, that makes sense, I misinterpreted show since for integers & friends it is just the same as a toString in other languages. Is there a standard name for "render a human readable form of this data"? toString() in java, to_s in ruby, and similar? On Wed, Aug 7, 2013 at 12:51 PM, Brandon Allbery wrote: > On Wed, Aug 7, 2013 at 1:04 PM, Chris Schneider < > chris at christopher-schneider.com> wrote: > >> I can't just use a show function directly to do this, since there are >> options I need to pass. >> > > And you shouldn't use show for this, because if it prints your > MacAddress as anything other than an unambiguous representation of the > Haskell MacAddress type then it has lost information useful for debugging. > More to the point: if I cannot see the difference between your MacAddress > and a String, then it's an unacceptable show. show should reflect the > Haskell data structure so I can verify that my program is doing the right > thing; if it shows what looks like a String, but I'm expecting to see a > MacAddress, then I will suspect a type error somewhere. > > show is like Perl's Data::Dumper or Python's repr. I don't want pretty, > I want accuracy. > > -- > brandon s allbery kf8nh sine nomine > associates > allbery.b at gmail.com > ballbery at sinenomine.net > unix, openafs, kerberos, infrastructure, xmonad > http://sinenomine.net > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Thu Aug 8 22:38:25 2013 From: martin.drautzburg at web.de (martin) Date: Thu, 08 Aug 2013 22:38:25 +0200 Subject: [Haskell-beginners] How to construct complex string In-Reply-To: References: <51FFFEEE.5050209@web.de> Message-ID: <520401C1.6070504@web.de> Am 08/06/2013 07:01 PM, schrieb Stephen Tetley: > Hi Martin > > If you are building syntax as a sequence of commands (or statements) a > common idiom is to collect them with a Writer monad. > > Andy Gill's Dotgen on Hackage is a nice realization of this idiom. See > the how example included in the package has acceptably nice syntax > without obliging the implementation to use complex facilities such as > Template Haskell. Thanks Stephen, exactly the nudge I was looking for, except I could not find any examples in the package. I had a brief look at the source code and it did not instantly reveal itself. Actually I already got stuck here: data Dot a = Dot { unDot :: Int -> ([GraphElement],Int,a) } Thanks Brent for you detailed explanation. From stephen.tetley at gmail.com Fri Aug 9 00:18:28 2013 From: stephen.tetley at gmail.com (Stephen Tetley) Date: Thu, 8 Aug 2013 23:18:28 +0100 Subject: [Haskell-beginners] How to construct complex string In-Reply-To: <520401C1.6070504@web.de> References: <51FFFEEE.5050209@web.de> <520401C1.6070504@web.de> Message-ID: Hi Martin The example is actually in the test directory - DotTest.hs. > data Dot a = Dot { unDot :: Int -> ([GraphElement],Int,a) } This is the monad in which you build syntax - when the code is run it is pretty printed into a String. This particular monad is a combination of the Writer monad - it accumulates a list of GraphicElement and a state monad - Int is passed around and incremented so it can generate variable names: As separate pieces the monads are: > data State a = State { unState :: Int -> (Int, a) } i.e. a function from state of type Int to a tuple of state and a polymorphic answer (Int,a). > data Writer a = Writer { unWriter :: ([GraphElement],a) } i.e. a tuple of GraphElement's accumulated in a list and a polymorphic answer. Once you have a "declaration" of a monad you also have to provide an instance of the monad class so you can use the do-notation, in the Dotgen code the instance is: instance Monad Dot where return a = Dot$ \ uq -> ([],uq,a) m >>= k = Dot $\ uq -> case unDot m uq of (g1,uq',r) -> case unDot (k r) uq' of (g2,uq2,r2) -> (g1 ++ g2,uq2,r2) This is a bit complicated as it is a combination of the monadic operation of both the State and Writer monad. With luck for just generating commands (and not generating fresh variables) you should be able to manage with only a Writer monad. There is one already in the monads package (mtl) in the Platform. The main part of the Dotgen library are the functions edge, node, (.->.) etc. which build Dot commands. In edge you can see a single command being built [GraphEdge from to attrs] in the first cell of the answer tuple: -- | 'edge' generates an edge between two 'NodeId's, with attributes. edge :: NodeId -> NodeId -> [(String,String)] -> Dot () edge from to attrs = Dot (\ uq -> ( [ GraphEdge from to attrs ],uq,())) Because no fresh variables are generated, the state uq (read as "unique") is returned unaltered in the answer tuple along with the void answer (). The other key part of the library is the so-called "run function" which evaluates monadic expressions - here the run function is called showDot: -- 'showDot' renders a dot graph as a 'String'. showDot :: Dot a -> String showDot (Dot dm) = case dm 0 of (elems,_,_) -> "digraph G {\n" ++ unlines (map showGraphElement elems) ++ "\n}\n" showDot unwraps dm from the Dot data type. As dm is a function  Int -> ([GraphElement],Int,a)  it needs to be applied to the initial state - here 0. This produces the answer 3-tuple, where we are only interested in the accumulated list of dot commands (the first cell). This list of commands is pretty printed into legal Dot syntax. Hope this helps somewhat. -------------- next part -------------- An HTML attachment was scrubbed... URL: From eleventynine at gmail.com Fri Aug 9 08:38:37 2013 From: eleventynine at gmail.com (Mike Ledger) Date: Fri, 9 Aug 2013 16:38:37 +1000 Subject: [Haskell-beginners] maybe in IO In-Reply-To: <51FA827E.8070609@orlitzky.com> References: <51FA827E.8070609@orlitzky.com> Message-ID: With Data.Foldable, it's quite nice: check x assoc = lookup x assoc for_ \f -> putStrLn ("found " ++ f) On Fri, Aug 2, 2013 at 1:45 AM, Michael Orlitzky wrote: > On 08/01/2013 11:00 AM, vold wrote: > > I've defined a function similar to > > > > check x assoc = let found = lookup x assoc in > > when (isJust found)$ putStrLn $"found " ++ > fromJust found > > > > which I've used several times from within the IO monad. Is there a more > > compact way of doing this? > > > > maybe (return ()) (putStrLn . ("found " ++)) found > > is the best I could do. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From k.bleijenberg at lijbrandt.nl Fri Aug 9 12:00:42 2013 From: k.bleijenberg at lijbrandt.nl (Kees Bleijenberg) Date: Fri, 9 Aug 2013 12:00:42 +0200 Subject: [Haskell-beginners] alternative sourcegraph Message-ID: <000001ce94e7$4f2516b0$ed6f4410$@bleijenberg@lijbrandt.nl> I want to remove 'dead' code and unnecessary exports out of modules. I tried sourceGraph with sourceGraph tbGlasDll.hs and I got: Could not parse source file ./Toetsing.hs Could not parse source file ./TestGlas.hs Could not parse source file ./TBGlasDll.hs Could not parse source file ./Glas.hs Could not parse source file ./CalcGlas.hs Could not parse source file ./calc.hs Could not parse source file ./BelastingFactoren.hs sourceGraph: Map.findMin: empty map has no minimal element The files above compile without errors with ghc. Maybe it has to do with Template Haskell code? Is there an alternative to sourceGraph? Kees -------------- next part -------------- An HTML attachment was scrubbed... URL: From byorgey at seas.upenn.edu Fri Aug 9 13:29:29 2013 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Fri, 9 Aug 2013 07:29:29 -0400 Subject: [Haskell-beginners] alternative sourcegraph In-Reply-To: <000001ce94e7$4f2516b0$ed6f4410$@bleijenberg@lijbrandt.nl> References: <000001ce94e7$4f2516b0$ed6f4410$@bleijenberg@lijbrandt.nl> Message-ID: <20130809112929.GA17085@seas.upenn.edu> On Fri, Aug 09, 2013 at 12:00:42PM +0200, Kees Bleijenberg wrote: > I want to remove 'dead' code and unnecessary exports out of modules. I tried > sourceGraph with sourceGraph tbGlasDll.hs and I got: > > Could not parse source file ./Toetsing.hs > > Could not parse source file ./TestGlas.hs > > Could not parse source file ./TBGlasDll.hs > > Could not parse source file ./Glas.hs > > Could not parse source file ./CalcGlas.hs > > Could not parse source file ./calc.hs > > Could not parse source file ./BelastingFactoren.hs > > sourceGraph: Map.findMin: empty map has no minimal element > > The files above compile without errors with ghc. > > Maybe it has to do with Template Haskell code? Is there an alternative to > sourceGraph? I don't know of any alternatives to sourceGraph. Why don't you file a bug report with the maintainer? -Brent From martin.drautzburg at web.de Fri Aug 9 19:41:57 2013 From: martin.drautzburg at web.de (martin) Date: Fri, 09 Aug 2013 19:41:57 +0200 Subject: [Haskell-beginners] How to construct complex string In-Reply-To: References: <51FFFEEE.5050209@web.de> <520401C1.6070504@web.de> Message-ID: <520529E5.9020901@web.de> Am 08/09/2013 12:18 AM, schrieb Stephen Tetley: > Hi Martin > instance Monad Dot where > return a = Dot $\ uq -> ([],uq,a) > m >>= k = Dot$ \ uq -> case unDot m uq of > (g1,uq',r) -> case unDot (k r) uq' of > (g2,uq2,r2) -> (g1 ++ g2,uq2,r2) Thanks Stephen I have a related question to the one above: The "case .. of" is just required to bind the variables left of the "->", as there is only one alternative, right? I tried to rewrite this using "where" and was bitten badly, because inside the "where" uq would not be defined. I found a way to write (a simplified version of) this using "let .. in", but I had to put the entire "let .. in" after the "->" in the lambda and it ended up equally ugly. So my question is: is "case .. of" the the "where" of lambdas? Are there alternatives? I find this confusing because "case .. of" looks like a decision between alternatives, rather than a way to bind variables. From stephen.tetley at gmail.com Fri Aug 9 20:27:44 2013 From: stephen.tetley at gmail.com (Stephen Tetley) Date: Fri, 9 Aug 2013 19:27:44 +0100 Subject: [Haskell-beginners] How to construct complex string In-Reply-To: <520529E5.9020901@web.de> References: <51FFFEEE.5050209@web.de> <520401C1.6070504@web.de> <520529E5.9020901@web.de> Message-ID: Hi Martin I think case ... of here is equivalent to let ... in the only difference is that it can avoid growing rightwards. The declaration and body of let would have to be indented to the same level as the let keyword. With case ... of the consequent expression doesn't have to be indented to the level of case provided it is on a new line. I don't think I've ever noticed this "typographical trick" of a single case _case_ in other code. -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Fri Aug 9 21:29:32 2013 From: martin.drautzburg at web.de (martin) Date: Fri, 09 Aug 2013 21:29:32 +0200 Subject: [Haskell-beginners] How to construct complex string In-Reply-To: References: <51FFFEEE.5050209@web.de> <520401C1.6070504@web.de> <520529E5.9020901@web.de> Message-ID: <5205431C.5040609@web.de> Am 08/09/2013 08:27 PM, schrieb Stephen Tetley: > I don't think I've ever noticed this "typographical trick" of a single > case _case_ in other code. Are there other ways of doing this? What do you guys do, when you are tempted to write "where" but you are behind the "->" of a lambda and you want to refer to the arguments? From ky3 at atamo.com Fri Aug 9 23:11:17 2013 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Sat, 10 Aug 2013 04:11:17 +0700 Subject: [Haskell-beginners] How to construct complex string In-Reply-To: <520529E5.9020901@web.de> References: <51FFFEEE.5050209@web.de> <520401C1.6070504@web.de> <520529E5.9020901@web.de> Message-ID: On Sat, Aug 10, 2013 at 12:41 AM, martin wrote: > > instance Monad Dot where > > return a = Dot $\ uq -> ([],uq,a) > > m >>= k = Dot$ \ uq -> case unDot m uq of > > (g1,uq',r) -> case unDot (k r) uq' of > > (g2,uq2,r2) -> (g1 ++ g2,uq2,r2) > > I tried to rewrite this using "where" and was bitten badly, because > inside the "where" uq would not be defined. > You could write: m >>= k = Dot f where f uq = (g1 ++ g2, uq2, r2) where (g1, uq', r) = unDot m uq (g2, uq2, r2) = unDot (k r) uq' Doubtless, there has to be a way of revealing the inner structure, which looks like some state monad with icing on top. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From psismondi at arqux.com Sat Aug 10 16:22:06 2013 From: psismondi at arqux.com (Philippe Sismondi) Date: Sat, 10 Aug 2013 10:22:06 -0400 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment Message-ID: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> I am interested in tracking down discussions on how Haskell fits into an operating system environment. That is probably not a very clear question, so let me explain. One of the great obstacles I have faced in using two of my favourite languages (Common Lisp and Haskell) for anything practical is that I am constantly frustrated by their relationship with the host OS, or perhaps more accurately with the APIs provided by the OS. For example, I tend to program mostly on OS X. I have a reasonable knowledge of Cocoa, and can get quite a lot done with Objective-C. So, if I want to use Haskell on OS X, I can run off and learn about Haskell's FFI, or some hand-rolled widget package, etc. But here is the problem: Cocoa et al provide an entire ecosystem that includes data structures, error handling, and so on. So, when trying to use Haskell with a GUI, or perhaps to do some audio processing, or other things that are provided by the OS X APIs, I feel that I am layering two quite incompatible worlds together: Haskell and its host environment. I ran into the same dilemma with Common Lisp. Clozure Common Lisp provides an excellent Cocoa binding. But using it feels (to me) like communications between alien races. The OS APIs want to do things the Objective-C way, and that is (clearly) not the Haskell or Lisp way. One soon notices that books on Haskell pay virtually no attention to this issue. At least, the ones I have don't. Maybe what I am really experiencing is that OS X just "wants" to be programmed in its native language. I had something of a better feeling about using F# on Windows, because that architecture does leverage the native stuff much better. The upshot is that I remain skeptical that Haskell is actually a practical language for many kinds of development. Can anyone point me to discussions on this? I may be having a dimwitted interval here, but I don't know what to search to find this. - P - From magnus at therning.org Sat Aug 10 22:06:02 2013 From: magnus at therning.org (Magnus Therning) Date: Sat, 10 Aug 2013 22:06:02 +0200 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> Message-ID: <20130810200602.GA7446@mteis.lan> On Sat, Aug 10, 2013 at 10:22:06AM -0400, Philippe Sismondi wrote: > I am interested in tracking down discussions on how Haskell fits > into an operating system environment. That is probably not a very > clear question, so let me explain. > > One of the great obstacles I have faced in using two of my favourite > languages (Common Lisp and Haskell) for anything practical is that I > am constantly frustrated by their relationship with the host OS, or > perhaps more accurately with the APIs provided by the OS. > > For example, I tend to program mostly on OS X. I have a reasonable > knowledge of Cocoa, and can get quite a lot done with Objective-C. > So, if I want to use Haskell on OS X, I can run off and learn about > Haskell's FFI, or some hand-rolled widget package, etc. But here is > the problem: Cocoa et al provide an entire ecosystem that includes > data structures, error handling, and so on. So, when trying to use > Haskell with a GUI, or perhaps to do some audio processing, or other > things that are provided by the OS X APIs, I feel that I am layering > two quite incompatible worlds together: Haskell and its host > environment. > > I ran into the same dilemma with Common Lisp. Clozure Common Lisp > provides an excellent Cocoa binding. But using it feels (to me) like > communications between alien races. The OS APIs want to do things > the Objective-C way, and that is (clearly) not the Haskell or Lisp > way. I'm not sure there are a lot of discussions or texts on this issue, but maybe you can find some solace in me thinking that this problem pops up whenever one tries to combine components written in different languages. For instance C++ is able to call straight to C libraries, but that doesn't mean that C APIs fit well into "idiomatic C++" (or maybe I should say one of the many "idiomatic C++s"). The same goes for all other combinations I've tried out myself, Python+C, Python+C++, Java+C, Haskell+C... I'm fairly sure it is the case with *every* combination. I'm also fairly sure that the friction becomes higher the more different the languages are, i.e. combining two procedural (non-OO) languages is most likely easier than combining a procedural (non-OO) with an OO language, even if both are imperative. If the languages have different paradigms, e.g. imperative vs. functional, the friction becomes higher still. > One soon notices that books on Haskell pay virtually no attention to > this issue. At least, the ones I have don't. I believe the FFI is touched upon, but providing an idiomatic Haskell API for a C library is most likely an art (maybe a black one ;) at this point. So in short, you are right. (I'd love to be proven wrong here and be pointed to some recipe book for how to wrap C in Haskell, or C in Python, and do it well.) /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus I invented the term Object-Oriented, and I can tell you I did not have C++ in mind. -- Alan Kay -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 230 bytes Desc: not available URL: From orblivion at gmail.com Sun Aug 11 02:16:58 2013 From: orblivion at gmail.com (Dan Krol) Date: Sat, 10 Aug 2013 17:16:58 -0700 Subject: [Haskell-beginners] HTTP Download -> Save File - non-strict Message-ID: Hi, I'm working on an rss file getter. I was wondering if I could get some help getting files to download and save without holding the entire file in memory in between. I chose Conduit's version of SimpleHttp only because it was recommended, and it was the quickest thing I could get to work correctly because I was eager to get started on this project, so I'd be happy to switch. Here's where I define the download and save functions: https://github.com/orblivion/feedGetter/blob/master/rss.hs#L107 And here's where I use them, getting multiple at a time with async: https://github.com/orblivion/feedGetter/blob/master/rss.hs#L208 What happens when I run this is that it outputs that it's "Getting" the file, waits a while (presumably to download the whole thing), then says it's "Saving". And I checked the file system, it's not there during the pause. I'm not entirely sure why. Is it my choice of libraries, or the way I'm using them? Perhaps something to do with async? I just tried content <- simpleHttp "http://google.com" in ghci, and it does pause for a second, so I'm guessing this is strict from the getgo. But I've done almost no I/O before. Is there a straightforward, canonical option? It seems like there perhaps should be. But if it comes down to using pipes or conduit, what the heck I'll try it out, I'd like to learn pipes eventually. Thanks a lot, Dan -------------- next part -------------- An HTML attachment was scrubbed... URL: From magnus at therning.org Sun Aug 11 08:30:30 2013 From: magnus at therning.org (Magnus Therning) Date: Sun, 11 Aug 2013 08:30:30 +0200 Subject: [Haskell-beginners] HTTP Download -> Save File - non-strict In-Reply-To: References: Message-ID: <20130811063030.GA1513@mteis.lan> On Sat, Aug 10, 2013 at 05:16:58PM -0700, Dan Krol wrote: > Hi, > > I'm working on an rss file getter. I was wondering if I could get > some help getting files to download and save without holding the > entire file in memory in between. I chose Conduit's version of > SimpleHttp only because it was recommended, and it was the quickest > thing I could get to work correctly because I was eager to get > started on this project, so I'd be happy to switch. > > Here's where I define the download and save functions: > > https://github.com/orblivion/feedGetter/blob/master/rss.hs#L107 > > And here's where I use them, getting multiple at a time with async: > > https://github.com/orblivion/feedGetter/blob/master/rss.hs#L208 > > What happens when I run this is that it outputs that it's "Getting" > the file, waits a while (presumably to download the whole thing), > then says it's "Saving". And I checked the file system, it's not > there during the pause. I'm not entirely sure why. Is it my choice > of libraries, or the way I'm using them? Perhaps something to do > with async? I just tried content <- simpleHttp "http://google.com" > in ghci, and it does pause for a second, so I'm guessing this is > strict from the getgo. But I've done almost no I/O before. > > Is there a straightforward, canonical option? It seems like there > perhaps should be. But if it comes down to using pipes or conduit, > what the heck I'll try it out, I'd like to learn pipes eventually. Michael is very good with documenting his packages, this is what I found in the docs for http-conduit (http://is.gd/WkDb7G): Note: Even though this function returns a lazy bytestring, it does not utilize lazy I/O, and therefore the entire response body will live in memory. If you want constant memory usage, you'll need to use the conduit package and http directly. /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus I invented the term Object-Oriented, and I can tell you I did not have C++ in mind. -- Alan Kay -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 230 bytes Desc: not available URL: From apfelmus at quantentunnel.de Sun Aug 11 10:58:15 2013 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Sun, 11 Aug 2013 10:58:15 +0200 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> Message-ID: Philippe Sismondi wrote: > I am interested in tracking down discussions on how Haskell fits into > an operating system environment. That is probably not a very clear > question, so let me explain. > > One of the great obstacles I have faced in using two of my favourite > languages (Common Lisp and Haskell) for anything practical is that I > am constantly frustrated by their relationship with the host OS, or > perhaps more accurately with the APIs provided by the OS. > > For example, I tend to program mostly on OS X. I have a reasonable > knowledge of Cocoa, and can get quite a lot done with Objective-C. > So, if I want to use Haskell on OS X, I can run off and learn about > Haskell's FFI, or some hand-rolled widget package, etc. But here is > the problem: Cocoa et al provide an entire ecosystem that includes > data structures, error handling, and so on. So, when trying to use > Haskell with a GUI, or perhaps to do some audio processing, or other > things that are provided by the OS X APIs, I feel that I am layering > two quite incompatible worlds together: Haskell and its host > environment. > > I ran into the same dilemma with Common Lisp. Clozure Common Lisp > provides an excellent Cocoa binding. But using it feels (to me) like > communications between alien races. The OS APIs want to do things the > Objective-C way, and that is (clearly) not the Haskell or Lisp way. > > One soon notices that books on Haskell pay virtually no attention to > this issue. At least, the ones I have don't. > > Maybe what I am really experiencing is that OS X just "wants" to be > programmed in its native language. I had something of a better > feeling about using F# on Windows, because that architecture does > leverage the native stuff much better. > > The upshot is that I remain skeptical that Haskell is actually a > practical language for many kinds of development. > > Can anyone point me to discussions on this? I may be having a > dimwitted interval here, but I don't know what to search to find > this. I'm not entirely sure I understand your question. The fact that, say, Objective-C uses quite a different way of speech than Haskell is not surprising, these are two different languages after all. You would have similar problems in an imaginary world where Haskell were the norm and Objective-C the exception. If you want to use both at once, you have to invest work in building a bridge. For instance, you can present Haskell in a more Objective-C-y fashion, or the other way round, or some middle ground. That's just how it is and it applies to all languages. Concerning Objective-C specifically, there was a very nice project implementing a slick FFI for Cocoa in Haskell. Unfortunately, it has been dead for years now. http://hoc.sourceforge.net/ Somewhat related, there is actually an (experimental) OS written in Haskell, see http://stackoverflow.com/a/6638207/403805 In case you're not that interested in integrating with the entire OS, but are just looking for a GUI library in Haskell anyway, I would like to toot my own horn and point to threepenny-gui, which uses the web browser as a display. https://github.com/HeinrichApfelmus/threepenny-gui Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com From psismondi at arqux.com Sun Aug 11 17:10:48 2013 From: psismondi at arqux.com (Philippe Sismondi) Date: Sun, 11 Aug 2013 11:10:48 -0400 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> Message-ID: <105AED40-8115-4480-B039-E58C7A013D1C@arqux.com> On 2013-08-11, at 4:58 AM, Heinrich Apfelmus wrote: > Philippe Sismondi wrote: >> I am interested in tracking down discussions on how Haskell fits into > I'm not entirely sure I understand your question. Well, I admit that I am having trouble formulating my question clearly. It was probably not even clear in my own mind. However, posting and clarifying here have served a purpose for me; read on. Upon reflection, probably my real concern is not about mixing dissimilar programming languages, but about the frequently discussed issue of finding production-quality libraries for a language. This issue is a serious one for Common Lisp, Scheme, ML and OCaml, and other languages I like. It is perhaps less of a problem for languages built on a substrate such as the JVM or .NET. For most of the software that I am interested in working on, there is a vast collection of "native" stuff available in both OS X and Windows. This includes, just as an example, Core Audio in OS X. As a result of posting my (vague) question, and thinking about this, I have decided that it makes more sense to just stick to Objective-C or C when the vendor of the OS has provided a good library in their language of choice. I like Haskell and Lisp better than I like flavours of C. But for now I am going to abandon the forlorn hope of doing everything in my favourite languages when the OS ecosystem favours something else. Moreover, I am dissatisfied with the quality of Haskell libraries even for those things that are not already supplied by OS vendors. In my opinion (and I may be wrong), hackage is littered with half-baked stuff, poorly documented projects started by extremely bright grad students and then abandoned after a year or two. (Of course, there is some great stuff on there too.) As a result of this little thread I have come to another conclusion, and this is just my subjective view. Most of the software that I am interested in seems to live most comfortably with a stateful conception of the world. (The native libraries I find most useful certainly are stateful.) I am reasonably competent with monads and monad transformers in Haskell. But, to be honest, after three years of pluggin away at Haskell, I am not the least convinced that the problem of handling a changing external world in a pure functional language has been successfully solved by those techniques. I always feel as though I am using the robot arm on a space shuttle when a screwdriver would do. (Again, no need to rebut this - I may be wrong or just to stupid to use Haskell effectively - so be it.) Perhaps in the end I do not really believe that functional programming is the panacea that its devotees claim it to be. I think this post may mark the beginning of my abandonment of Haskell for many purposes. So long?. - P - From stephen.tetley at gmail.com Sun Aug 11 17:45:20 2013 From: stephen.tetley at gmail.com (Stephen Tetley) Date: Sun, 11 Aug 2013 16:45:20 +0100 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: <105AED40-8115-4480-B039-E58C7A013D1C@arqux.com> References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> <105AED40-8115-4480-B039-E58C7A013D1C@arqux.com> Message-ID: I tend to see OO subtyping and heterogeneous collections as more an impediment to (pure) functional integration with the "rest-of-the-world" than state. There are a lot of quality wrappers to stateful C libraries from Haskell, but few to object oriented C++ or Objective C libraries. On 11 August 2013 16:10, Philippe Sismondi wrote: > > > As a result of this little thread I have come to another conclusion, and > this is just my subjective view. Most of the software that I am interested > in seems to live most comfortably with a stateful conception of the world. > (The native libraries I find most useful certainly are stateful.) I am > reasonably competent with monads and monad transformers in Haskell. But, to > be honest, after three years of pluggin away at Haskell, I am not the least > convinced that the problem of handling a changing external world in a pure > functional language has been successfully solved by those techniques. I > always feel as though I am using the robot arm on a space shuttle when a > screwdriver would do. (Again, no need to rebut this - I may be wrong or > just to stupid to use Haskell effectively - so be it.) > > Perhaps in the end I do not really believe that functional programming is > the panacea that its devotees claim it to be. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From psismondi at arqux.com Sun Aug 11 18:42:08 2013 From: psismondi at arqux.com (Philippe Sismondi) Date: Sun, 11 Aug 2013 12:42:08 -0400 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> <105AED40-8115-4480-B039-E58C7A013D1C@arqux.com> Message-ID: On 2013-08-11, at 11:45 AM, Stephen Tetley wrote: > I tend to see OO subtyping and heterogeneous collections as more an impediment to (pure) functional integration with the "rest-of-the-world" than state. There are a lot of quality wrappers to stateful C libraries from Haskell, but few to object oriented C++ or Objective C libraries. That may be true. And, state and OO types are different issues. I guess I conflated the two because the stateful OS X libraries I use are largely implemented using Cocoa or sometimes C data structures. So, do I make my own Haskell list or record or type representing something in the API, or just access the Cocoa one? etc. etc. Also, in truth I introduced a totally separate gripe, which is that I find monads and monad transformers to be a hell of a messy and difficult way to deal with state. Sometimes I get sick of all the layering in monad transformers and hand-roll my own monad with all the stuff. But it just seems baroquely difficult. Perhaps I was just to set in my ways when I came to FP, and cannot really "get it". There are things I have never looked into such as FRP, but maybe my poor old brain is just not up to it. Maybe I should have been a janitor or a car salesman. - P - > > > On 11 August 2013 16:10, Philippe Sismondi wrote: > > > As a result of this little thread I have come to another conclusion, and this is just my subjective view. Most of the software that I am interested in seems to live most comfortably with a stateful conception of the world. (The native libraries I find most useful certainly are stateful.) I am reasonably competent with monads and monad transformers in Haskell. But, to be honest, after three years of pluggin away at Haskell, I am not the least convinced that the problem of handling a changing external world in a pure functional language has been successfully solved by those techniques. I always feel as though I am using the robot arm on a space shuttle when a screwdriver would do. (Again, no need to rebut this - I may be wrong or just to stupid to use Haskell effectively - so be it.) > > Perhaps in the end I do not really believe that functional programming is the panacea that its devotees claim it to be. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From voldermort at hotmail.com Sun Aug 11 19:45:05 2013 From: voldermort at hotmail.com (harry) Date: Sun, 11 Aug 2013 17:45:05 +0000 (UTC) Subject: [Haskell-beginners] cabal install relative to $topdir Message-ID: I would like cabal install to create paths in the package database relative to$topdir, so that I can mount it on a different machine (where the absolute path will obviously be different). Is there any way of automating this? From orblivion at gmail.com Sun Aug 11 20:44:24 2013 From: orblivion at gmail.com (Dan Krol) Date: Sun, 11 Aug 2013 11:44:24 -0700 Subject: [Haskell-beginners] HTTP Download -> Save File - non-strict In-Reply-To: <20130811063030.GA1513@mteis.lan> References: <20130811063030.GA1513@mteis.lan> Message-ID: Ah yes, the actual docs. Somehow didn't think to check that, sorry. Alright, I'll try to figure that one out, thanks. Any particular reason nobody just offers http over lazy I/O? Is it just because lazy I/O is generally discouraged? Or just particularly bad over a network? And is this an area where Conduit is better than Pipes? There doesn't seem to be a similar http for Pipes. On Sat, Aug 10, 2013 at 11:30 PM, Magnus Therning wrote: > On Sat, Aug 10, 2013 at 05:16:58PM -0700, Dan Krol wrote: > > Hi, > > > > I'm working on an rss file getter. I was wondering if I could get > > some help getting files to download and save without holding the > > entire file in memory in between. I chose Conduit's version of > > SimpleHttp only because it was recommended, and it was the quickest > > thing I could get to work correctly because I was eager to get > > started on this project, so I'd be happy to switch. > > > > Here's where I define the download and save functions: > > > > https://github.com/orblivion/feedGetter/blob/master/rss.hs#L107 > > > > And here's where I use them, getting multiple at a time with async: > > > > https://github.com/orblivion/feedGetter/blob/master/rss.hs#L208 > > > > What happens when I run this is that it outputs that it's "Getting" > > the file, waits a while (presumably to download the whole thing), > > then says it's "Saving". And I checked the file system, it's not > > there during the pause. I'm not entirely sure why. Is it my choice > > of libraries, or the way I'm using them? Perhaps something to do > > with async? I just tried content <- simpleHttp "http://google.com" > > in ghci, and it does pause for a second, so I'm guessing this is > > strict from the getgo. But I've done almost no I/O before. > > > > Is there a straightforward, canonical option? It seems like there > > perhaps should be. But if it comes down to using pipes or conduit, > > what the heck I'll try it out, I'd like to learn pipes eventually. > > Michael is very good with documenting his packages, this is what I > found in the docs for http-conduit (http://is.gd/WkDb7G): > > Note: Even though this function returns a lazy bytestring, it does > not utilize lazy I/O, and therefore the entire response body will > live in memory. If you want constant memory usage, you'll need to > use the conduit package and http directly. > > /M > > -- > Magnus Therning OpenPGP: 0xAB4DFBA4 > email: magnus at therning.org jabber: magnus at therning.org > twitter: magthe http://therning.org/magnus > > I invented the term Object-Oriented, and I can tell you I did not have > C++ in mind. > -- Alan Kay > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mle+hs at mega-nerd.com Sun Aug 11 22:47:13 2013 From: mle+hs at mega-nerd.com (Erik de Castro Lopo) Date: Mon, 12 Aug 2013 06:47:13 +1000 Subject: [Haskell-beginners] HTTP Download -> Save File - non-strict In-Reply-To: References: <20130811063030.GA1513@mteis.lan> Message-ID: <20130812064713.b8ec626e4553316c16246d46@mega-nerd.com> Dan Krol wrote: > Ah yes, the actual docs. Somehow didn't think to check that, sorry. > > Alright, I'll try to figure that one out, thanks. Any particular reason > nobody just offers http over lazy I/O? Is it just because lazy I/O is > generally discouraged? Or just particularly bad over a network? Lazy I/O is particularly problematic when implmenting network servers and generally discouraged for networking code. > And is this an area where Conduit is better than Pipes? Conduit has been around longer and is thus more mature and complete. > There doesn't seem to be a similar http for Pipes. I believe Andrew Cowie, author of http-streams (on top of io-streams) is working on a Pipes version. HTH, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/ From voldermort at hotmail.com Mon Aug 12 09:35:10 2013 From: voldermort at hotmail.com (vold) Date: Mon, 12 Aug 2013 07:35:10 +0000 (UTC) Subject: [Haskell-beginners] cabal logs Message-ID: If I set build-summary in cabal's config file, cabal will create duplicate logs - the one specified in build-summary and the default build-reports.log in the packages directory. There's also a log-dir option in the config file which doesn't seem to do anything. Are these bugs, or intended behaviour? From apfelmus at quantentunnel.de Mon Aug 12 11:23:14 2013 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Mon, 12 Aug 2013 11:23:14 +0200 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: <105AED40-8115-4480-B039-E58C7A013D1C@arqux.com> References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> <105AED40-8115-4480-B039-E58C7A013D1C@arqux.com> Message-ID: Philippe Sismondi wrote: > > Upon reflection, probably my real concern is not about mixing > dissimilar programming languages, but about the frequently discussed > issue of finding production-quality libraries for a language. [..] > > For most of the software that I am interested in working on, there is > a vast collection of "native" stuff available in both OS X and > Windows. This includes, just as an example, Core Audio in OS X. [..] > > Moreover, I am dissatisfied with the quality of Haskell libraries > even for those things that are not already supplied by OS vendors. In > my opinion (and I may be wrong), hackage is littered with half-baked > stuff, poorly documented projects started by extremely bright grad > students and then abandoned after a year or two. (Of course, there is > some great stuff on there too.) Well, there are a lot of magazines at the news kiosk, too, while only a few are of outstanding quality. That is just how a news kiosk works. Speaking of quality, what I like most about Haskell libraries, even the half-baked ones, is that they have very few bugs. I've been programming functionally for a decade now, and whenever I venture into the world of imperative languages, I always trip up bugs that just shouldn't be there. Here two recent examples: * HTML 5 drag and drop. Apart from the fact that the specification is overcomplicated, Chrome doesn't even implement the spec correctly. When the mouse enters a child element of a "dropzone'd" element, the latter receives a "dragleave" event, but will not receive a "dragenter" event again when the mouse moves away from the child element. Argh! * HTML 5 WebSockets. Chrome or Safari. After a certain amount of inactivity on the server side, the browser will close the WebSocket. However, it will only close the client side, so the client cannot send messages anymore. The connection to the server is still *open*, though, and the server can happily send data. What? Also, if you connect with a WebSocket and then reload the page and connect again, the old connection will be reused. WTF? These are just examples, this happens to me all the time. Curiously, whenever I use state, my programs start to become similarly brittle. There is no reason why state should be a fundamental element of a programming language, and as a design pattern, state is best avoided at all cost. > As a result of this little thread I have come to another conclusion, > and this is just my subjective view. Most of the software that I am > interested in seems to live most comfortably with a stateful > conception of the world. (The native libraries I find most useful > certainly are stateful.) I am reasonably competent with monads and > monad transformers in Haskell. But, to be honest, after three years > of pluggin away at Haskell, I am not the least convinced that the > problem of handling a changing external world in a pure functional > language has been successfully solved by those techniques. I always > feel as though I am using the robot arm on a space shuttle when a > screwdriver would do. (Again, no need to rebut this - I may be wrong > or just to stupid to use Haskell effectively - so be it.) > > Perhaps in the end I do not really believe that functional > programming is the panacea that its devotees claim it to be. > > I think this post may mark the beginning of my abandonment of Haskell > for many purposes. Haskell may not be easy to learn, but it's definitely worth the effort. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com From alanbuxton at gmail.com Mon Aug 12 22:35:30 2013 From: alanbuxton at gmail.com (Alan Buxton) Date: Mon, 12 Aug 2013 21:35:30 +0100 Subject: [Haskell-beginners] Text.XML.writeFile question Message-ID: <004001ce979b$7d5b8d00$7812a700$@gmail.com> Hi I am trying to write an XML file where the filename is created based on a timestamp. Simplified version below. This won't compile - I get this error in doWrite2 filepathtest.hs|24 col 17 error| Couldn't match expected type system-filepath-0.4.7:Filesystem.Path.Internal.FilePath' || with actual type String' || In the second argument of writeFile', namely t1' || In a stmt of a 'do' block: writeFile def t1 doc || In the expression: || do { t1 <- tsString; || writeFile def t1 doc } Somehow the String "text.xml" in doWrite1 is converted into a FilePath, but not the String t1 in doWrite2. What am I doing wrong? {-# LANGUAGE OverloadedStrings #-} module Filepathtest where import Text.XML import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds) import Data.Time.Clock (getCurrentTime) import Prelude hiding (writeFile, FilePath) tsString :: IO String tsString = do x <- getCurrentTime let x' = show$ floor $utcTimeToPOSIXSeconds x return x' doWrite1 :: Document -> IO () doWrite1 doc = writeFile def "test1.xml" doc doWrite2 :: Document -> IO () doWrite2 doc = do t1 <- tsString writeFile def t1 doc -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Mon Aug 12 22:52:06 2013 From: toad3k at gmail.com (David McBride) Date: Mon, 12 Aug 2013 16:52:06 -0400 Subject: [Haskell-beginners] Text.XML.writeFile question In-Reply-To: <004001ce979b$7d5b8d00$7812a700$@gmail.com> References: <004001ce979b$7d5b8d00$7812a700$@gmail.com> Message-ID: When you use overloadedstrings, it will type all literal strings as IsString a => a as a type. Unfortunately your tsString is not a literal, it is a run time function that always returns a string and a string is not a filepath. You should be able to do fmap fromString tsString, provided you import Data.String. On Mon, Aug 12, 2013 at 4:35 PM, Alan Buxton wrote: > Hi**** > > ** ** > > I am trying to write an XML file where the filename is created based on a > timestamp. Simplified version below. This won?t compile ? I get this error > in doWrite2 **** > > ** ** > > *filepathtest.hs|24 col 17 error| Couldn't match expected type > system-filepath-0.4.7:Filesystem.Path.Internal.FilePath' > * > > *|| with actual type String'* > > *|| In the second argument of writeFile', namely t1'* > > *|| In a stmt of a 'do' block: writeFile def t1 doc* > > *|| In the expression:* > > *|| do { t1 <- tsString;* > > *|| writeFile def t1 doc }* > > * * > > Somehow the String ?text.xml? in doWrite1 is converted into a FilePath, > but not the String t1 in doWrite2. What am I doing wrong?**** > > ** ** > > {-# LANGUAGE OverloadedStrings #-}**** > > module Filepathtest where**** > > **** > > import Text.XML**** > > import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds)**** > > import Data.Time.Clock (getCurrentTime)**** > > import Prelude hiding (writeFile, FilePath)**** > > **** > > tsString :: IO String**** > > tsString = do**** > > x <- getCurrentTime**** > > let x' = show$ floor $utcTimeToPOSIXSeconds x**** > > return x'**** > > **** > > doWrite1 :: Document -> IO ()**** > > doWrite1 doc =**** > > writeFile def "test1.xml" doc**** > > **** > > doWrite2 :: Document -> IO ()**** > > doWrite2 doc = do**** > > t1 <- tsString**** > > writeFile def t1 doc**** > > ** ** > > ** ** > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kdamodar2000 at gmail.com Tue Aug 13 06:45:07 2013 From: kdamodar2000 at gmail.com (damodar kulkarni) Date: Tue, 13 Aug 2013 10:15:07 +0530 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> <105AED40-8115-4480-B039-E58C7A013D1C@arqux.com> Message-ID: > Curiously, whenever I use state, my programs start to become similarly > brittle. There is no reason why state should be a fundamental element of a > programming language, and as a design pattern, state is best avoided at all > cost. Just as a curiosity, how would one avoid state in cases like protocol design? e.g. protocols specifications (like TCP/IP) do have a large element of state dependent behavior that "seems essential" to the problem. How would one deal with such cases? @Philippe Sismondi: I always feel as though I am using the robot arm on a space shuttle when a > screwdriver would do. +1 for this remark. Thanks and regards, -Damodar Kulkarni On Mon, Aug 12, 2013 at 2:53 PM, Heinrich Apfelmus < apfelmus at quantentunnel.de> wrote: > Philippe Sismondi wrote: > >> >> Upon reflection, probably my real concern is not about mixing >> dissimilar programming languages, but about the frequently discussed >> issue of finding production-quality libraries for a language. [..] >> >> >> For most of the software that I am interested in working on, there is >> a vast collection of "native" stuff available in both OS X and >> Windows. This includes, just as an example, Core Audio in OS X. [..] >> >> >> Moreover, I am dissatisfied with the quality of Haskell libraries >> even for those things that are not already supplied by OS vendors. In >> my opinion (and I may be wrong), hackage is littered with half-baked >> stuff, poorly documented projects started by extremely bright grad >> students and then abandoned after a year or two. (Of course, there is >> some great stuff on there too.) >> > > Well, there are a lot of magazines at the news kiosk, too, while only a > few are of outstanding quality. That is just how a news kiosk works. > > Speaking of quality, what I like most about Haskell libraries, even the > half-baked ones, is that they have very few bugs. I've been programming > functionally for a decade now, and whenever I venture into the world of > imperative languages, I always trip up bugs that just shouldn't be there. > Here two recent examples: > > * HTML 5 drag and drop. Apart from the fact that the specification is > overcomplicated, Chrome doesn't even implement the spec correctly. When the > mouse enters a child element of a "dropzone'd" element, the latter receives > a "dragleave" event, but will not receive a "dragenter" event again when > the mouse moves away from the child element. Argh! > > * HTML 5 WebSockets. Chrome or Safari. After a certain amount of > inactivity on the server side, the browser will close the WebSocket. > However, it will only close the client side, so the client cannot send > messages anymore. The connection to the server is still *open*, though, and > the server can happily send data. What? Also, if you connect with a > WebSocket and then reload the page and connect again, the old connection > will be reused. WTF? > > These are just examples, this happens to me all the time. Curiously, > whenever I use state, my programs start to become similarly brittle. There > is no reason why state should be a fundamental element of a programming > language, and as a design pattern, state is best avoided at all cost. > > > As a result of this little thread I have come to another conclusion, >> and this is just my subjective view. Most of the software that I am >> interested in seems to live most comfortably with a stateful >> conception of the world. (The native libraries I find most useful >> certainly are stateful.) I am reasonably competent with monads and >> monad transformers in Haskell. But, to be honest, after three years >> of pluggin away at Haskell, I am not the least convinced that the >> problem of handling a changing external world in a pure functional >> language has been successfully solved by those techniques. I always >> feel as though I am using the robot arm on a space shuttle when a >> screwdriver would do. (Again, no need to rebut this - I may be wrong >> or just to stupid to use Haskell effectively - so be it.) >> >> Perhaps in the end I do not really believe that functional >> programming is the panacea that its devotees claim it to be. >> >> I think this post may mark the beginning of my abandonment of Haskell >> for many purposes. >> > > Haskell may not be easy to learn, but it's definitely worth the effort. > > > > Best regards, > Heinrich Apfelmus > > -- > http://apfelmus.nfshost.com > > > ______________________________**_________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/**mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dedgrant at gmail.com Tue Aug 13 07:30:37 2013 From: dedgrant at gmail.com (Darren Grant) Date: Mon, 12 Aug 2013 22:30:37 -0700 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> <105AED40-8115-4480-B039-E58C7A013D1C@arqux.com> Message-ID: On Mon, Aug 12, 2013 at 9:45 PM, damodar kulkarni wrote: > > Curiously, whenever I use state, my programs start to become similarly >> brittle. There is no reason why state should be a fundamental element of a >> programming language, and as a design pattern, state is best avoided at all >> cost. > > > Just as a curiosity, how would one avoid state in cases like protocol > design? e.g. protocols specifications (like TCP/IP) do have a large element > of state dependent behavior that "seems essential" to the problem. How > would one deal with such cases? > State can be achieved in pure functional languages. The difference is that the state management is not directly accessible to the programmer as it is hidden behind a highly declarative set of abstractions. This provides the benefits of consistency, and sometimes frustration when the resulting machine code doesn't perform as expected. Cheers, Darren -------------- next part -------------- An HTML attachment was scrubbed... URL: From alanbuxton at gmail.com Tue Aug 13 10:06:14 2013 From: alanbuxton at gmail.com (Alan Buxton) Date: Tue, 13 Aug 2013 09:06:14 +0100 Subject: [Haskell-beginners] Text.XML.writeFile question In-Reply-To: References: <004001ce979b$7d5b8d00$7812a700$@gmail.com> Message-ID: <01a301ce97fb$fba31ec0$f2e95c40$@gmail.com> Thanks David. Spot on. a From: Beginners [mailto:beginners-bounces at haskell.org] On Behalf Of David McBride Sent: 12 August 2013 21:52 To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell Subject: Re: [Haskell-beginners] Text.XML.writeFile question When you use overloadedstrings, it will type all literal strings as IsString a => a as a type. Unfortunately your tsString is not a literal, it is a run time function that always returns a string and a string is not a filepath. You should be able to do fmap fromString tsString, provided you import Data.String. On Mon, Aug 12, 2013 at 4:35 PM, Alan Buxton wrote: Hi I am trying to write an XML file where the filename is created based on a timestamp. Simplified version below. This won't compile - I get this error in doWrite2 filepathtest.hs|24 col 17 error| Couldn't match expected type system-filepath-0.4.7:Filesystem.Path.Internal.FilePath' || with actual type String' || In the second argument of writeFile', namely t1' || In a stmt of a 'do' block: writeFile def t1 doc || In the expression: || do { t1 <- tsString; || writeFile def t1 doc } Somehow the String "text.xml" in doWrite1 is converted into a FilePath, but not the String t1 in doWrite2. What am I doing wrong? {-# LANGUAGE OverloadedStrings #-} module Filepathtest where import Text.XML import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds) import Data.Time.Clock (getCurrentTime) import Prelude hiding (writeFile, FilePath) tsString :: IO String tsString = do x <- getCurrentTime let x' = show$ floor $utcTimeToPOSIXSeconds x return x' doWrite1 :: Document -> IO () doWrite1 doc = writeFile def "test1.xml" doc doWrite2 :: Document -> IO () doWrite2 doc = do t1 <- tsString writeFile def t1 doc _______________________________________________ Beginners mailing list Beginners at haskell.org http://www.haskell.org/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From apfelmus at quantentunnel.de Tue Aug 13 11:33:38 2013 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Tue, 13 Aug 2013 11:33:38 +0200 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> <105AED40-8115-4480-B039-E58C7A013D1C@arqux.com> Message-ID: damodar kulkarni wrote: >> Curiously, whenever I use state, my programs start to become similarly >> brittle. There is no reason why state should be a fundamental element of a >> programming language, and as a design pattern, state is best avoided at all >> cost. > > > Just as a curiosity, how would one avoid state in cases like protocol > design? e.g. protocols specifications (like TCP/IP) do have a large element > of state dependent behavior that "seems essential" to the problem. How > would one deal with such cases? Well, in a protocol like TCP/IP, the response of a participant does depend on the history of the communication, and that history can neatly be summarized in a small amount of state. I don't think it's possible to avoid state in this case. But I meant something else, actually, and should have been more precise. Namely, it is best to avoid *mutable* state as a *design pattern*, i.e. the use of IORef and thelike. Pure functions State -> State are fine, but anything were the meaning of an expression depends heavily on the context (the program state) is prone to bugs. The problem is more about source code than it is about state. To avoid bugs, each piece of source code should be understandable in isolation, i.e. it should give the same results in all contexts ("code paths"). This way, it is a lot easier to determine its correctness. Of course, "source code" has different scales, and can include protocol design. After all, protocols are made by humans, and clever design can prevent headaches later. For instance, HTTP GET requests were designed to be stateless, and that makes the protocol a lot more robust. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com From lehner.lukas at gmail.com Tue Aug 13 16:46:04 2013 From: lehner.lukas at gmail.com (Lukas Lehner) Date: Tue, 13 Aug 2013 16:46:04 +0200 Subject: [Haskell-beginners] print [] Message-ID: Hello, This code runs ok http://lpaste.net/91814 but only thanks to enforcing [()] on line 12. In GHCI *Main> :t (List []) (List []) :: NestedList a and *Main> :t flatten (List []) flatten (List []) :: [a] That means ghc cannot infer the type. Is there a way how to # print flatten (List []) ? Or even more general, print [] without enforcing the type? Thank you Lukas -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Tue Aug 13 16:59:09 2013 From: allbery.b at gmail.com (Brandon Allbery) Date: Tue, 13 Aug 2013 10:59:09 -0400 Subject: [Haskell-beginners] print [] In-Reply-To: References: Message-ID: On Tue, Aug 13, 2013 at 10:46 AM, Lukas Lehner wrote: > That means ghc cannot infer the type. > Is there a way how to # print flatten (List []) ? > Or even more general, print [] without enforcing the type? > If you turn on the ExtendedDefaultRules extension ( {-# LANGUAGE ExtendedDefaultRules #-} pragma or -X ExtendedDefaultRules ghc option), ghc will infer () for the type just as ghci does. Note that this reduces type safety a bit, since ghc will now accept programs that have what otherwise would be type errors. -- 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 nadavchernin at gmail.com Tue Aug 13 17:05:15 2013 From: nadavchernin at gmail.com (Nadav Chernin) Date: Tue, 13 Aug 2013 18:05:15 +0300 Subject: [Haskell-beginners] Sorting Bank Accounts problem in Haskell Message-ID: Hi all, I learn Haskell and i try to solve questions from SPOJ. Currently, i try to solve problem *Sorting Bank Accounts* Here is my code: *import qualified Data.Map as M* * * *extractTest []=[]* *extractTest (x:xs)=(take n xs):(extractTest (drop (n+1) xs)) where* * n=read x* * * *emp=M.empty* * * *collect m []=m* *collect m (x:xs)* * |M.member x m =collect (M.insert x (amount+1) m) xs* * |otherwise=collect (M.insert x 1 m) xs* * where* * Just amount=M.lookup x m* * * *getList m=map (\(x,k)->x++" "++(show k)) (M.toList m)* *f x=unlines$(getList (collect emp x))++[""]* *main=getLine>>=(\x->interact$unlines.map f.take (read x).extractTest.lines) * * * The problem is that i can't finish it during 7 sec. So i want to know is there more quick solution/method for this problem. Thanks, Nadav -------------- next part -------------- An HTML attachment was scrubbed... URL: From lehner.lukas at gmail.com Tue Aug 13 17:08:45 2013 From: lehner.lukas at gmail.com (Lukas Lehner) Date: Tue, 13 Aug 2013 17:08:45 +0200 Subject: [Haskell-beginners] print [] In-Reply-To: References: Message-ID: Good to know extension. And without it? On Tue, Aug 13, 2013 at 4:59 PM, Brandon Allbery wrote: > On Tue, Aug 13, 2013 at 10:46 AM, Lukas Lehner wrote: > >> That means ghc cannot infer the type. >> Is there a way how to # print flatten (List []) ? >> Or even more general, print [] without enforcing the type? >> > > If you turn on the ExtendedDefaultRules extension ( {-# LANGUAGE > ExtendedDefaultRules #-} pragma or -X ExtendedDefaultRules ghc option), > ghc will infer () for the type just as ghci does. Note that this reduces > type safety a bit, since ghc will now accept programs that have what > otherwise would be type errors. > > -- > brandon s allbery kf8nh sine nomine > associates > allbery.b at gmail.com > ballbery at sinenomine.net > unix, openafs, kerberos, infrastructure, xmonad > http://sinenomine.net > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidleothomas at gmail.com Tue Aug 13 17:21:25 2013 From: davidleothomas at gmail.com (David Thomas) Date: Tue, 13 Aug 2013 08:21:25 -0700 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> <105AED40-8115-4480-B039-E58C7A013D1C@arqux.com> Message-ID: It seems like it would be roughly as easy to encode TCP with continuations as with the usual imperative approaches, though I'll certainly admit I haven't tried. On Mon, Aug 12, 2013 at 9:45 PM, damodar kulkarni wrote: > > Curiously, whenever I use state, my programs start to become similarly >> brittle. There is no reason why state should be a fundamental element of a >> programming language, and as a design pattern, state is best avoided at all >> cost. > > > Just as a curiosity, how would one avoid state in cases like protocol > design? e.g. protocols specifications (like TCP/IP) do have a large element > of state dependent behavior that "seems essential" to the problem. How > would one deal with such cases? > > @Philippe Sismondi: > > > I always feel as though I am using the robot arm on a space shuttle when a >> screwdriver would do. > > > +1 for this remark. > > Thanks and regards, > -Damodar Kulkarni > > > On Mon, Aug 12, 2013 at 2:53 PM, Heinrich Apfelmus < > apfelmus at quantentunnel.de> wrote: > >> Philippe Sismondi wrote: >> >>> >>> Upon reflection, probably my real concern is not about mixing >>> dissimilar programming languages, but about the frequently discussed >>> issue of finding production-quality libraries for a language. [..] >>> >>> >>> For most of the software that I am interested in working on, there is >>> a vast collection of "native" stuff available in both OS X and >>> Windows. This includes, just as an example, Core Audio in OS X. [..] >>> >>> >>> Moreover, I am dissatisfied with the quality of Haskell libraries >>> even for those things that are not already supplied by OS vendors. In >>> my opinion (and I may be wrong), hackage is littered with half-baked >>> stuff, poorly documented projects started by extremely bright grad >>> students and then abandoned after a year or two. (Of course, there is >>> some great stuff on there too.) >>> >> >> Well, there are a lot of magazines at the news kiosk, too, while only a >> few are of outstanding quality. That is just how a news kiosk works. >> >> Speaking of quality, what I like most about Haskell libraries, even the >> half-baked ones, is that they have very few bugs. I've been programming >> functionally for a decade now, and whenever I venture into the world of >> imperative languages, I always trip up bugs that just shouldn't be there. >> Here two recent examples: >> >> * HTML 5 drag and drop. Apart from the fact that the specification is >> overcomplicated, Chrome doesn't even implement the spec correctly. When the >> mouse enters a child element of a "dropzone'd" element, the latter receives >> a "dragleave" event, but will not receive a "dragenter" event again when >> the mouse moves away from the child element. Argh! >> >> * HTML 5 WebSockets. Chrome or Safari. After a certain amount of >> inactivity on the server side, the browser will close the WebSocket. >> However, it will only close the client side, so the client cannot send >> messages anymore. The connection to the server is still *open*, though, and >> the server can happily send data. What? Also, if you connect with a >> WebSocket and then reload the page and connect again, the old connection >> will be reused. WTF? >> >> These are just examples, this happens to me all the time. Curiously, >> whenever I use state, my programs start to become similarly brittle. There >> is no reason why state should be a fundamental element of a programming >> language, and as a design pattern, state is best avoided at all cost. >> >> >> As a result of this little thread I have come to another conclusion, >>> and this is just my subjective view. Most of the software that I am >>> interested in seems to live most comfortably with a stateful >>> conception of the world. (The native libraries I find most useful >>> certainly are stateful.) I am reasonably competent with monads and >>> monad transformers in Haskell. But, to be honest, after three years >>> of pluggin away at Haskell, I am not the least convinced that the >>> problem of handling a changing external world in a pure functional >>> language has been successfully solved by those techniques. I always >>> feel as though I am using the robot arm on a space shuttle when a >>> screwdriver would do. (Again, no need to rebut this - I may be wrong >>> or just to stupid to use Haskell effectively - so be it.) >>> >>> Perhaps in the end I do not really believe that functional >>> programming is the panacea that its devotees claim it to be. >>> >>> I think this post may mark the beginning of my abandonment of Haskell >>> for many purposes. >>> >> >> Haskell may not be easy to learn, but it's definitely worth the effort. >> >> >> >> Best regards, >> Heinrich Apfelmus >> >> -- >> http://apfelmus.nfshost.com >> >> >> ______________________________**_________________ >> Beginners mailing list >> Beginners at haskell.org >> http://www.haskell.org/**mailman/listinfo/beginners >> > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From voldermort at hotmail.com Tue Aug 13 20:55:22 2013 From: voldermort at hotmail.com (harry) Date: Tue, 13 Aug 2013 18:55:22 +0000 (UTC) Subject: [Haskell-beginners] cabal binary packages Message-ID: I need to build some software on a server, but it doesn't have enough spare memory for compiling all the dependencies. I would like to create a binary distribution of e.g. snap including all of its dependencies (other than those which come with ghc), so that the server can just install them. I found http://www.haskell.org/cabal/users-guide/installing-packages.html#creating-a-binary-package, but this seems to have two deficiencies - the destination prefix needs to be know in advance (which might be OK if it can be a relative path), and it has to be done individually for each package. From bryanvick at gmail.com Wed Aug 14 11:25:02 2013 From: bryanvick at gmail.com (Bryan Vicknair) Date: Wed, 14 Aug 2013 02:25:02 -0700 Subject: [Haskell-beginners] Compiler can't deduce Bool as instance of ToField Message-ID: <20130814092502.GA4017@x220.att.net> postgresql-simple declares Bool as an instance of the ToField class. The compiler can't deduce that given this simple code however: import Database.PostgreSQL.Simple.ToField (ToField(..)) foo :: (ToField a) => a foo = True It fails with this error: Db.hs:64:7: Could not deduce (a ~ Bool) from the context (ToField a) bound by the type signature for foo :: ToField a => a at Db.hs:63:8-23 a' is a rigid type variable bound by the type signature for foo :: ToField a => a at Db.hs:63:8 In the expression: True In an equation for foo': foo = True Failed, modules loaded: none. What am I missing? From dav.vire+haskell at gmail.com Wed Aug 14 12:08:39 2013 From: dav.vire+haskell at gmail.com (David Virebayre) Date: Wed, 14 Aug 2013 12:08:39 +0200 Subject: [Haskell-beginners] print [] In-Reply-To: References: Message-ID: 2013/8/13 Lukas Lehner : > Good to know extension. And without it? Someone correct me if I'm wrong, here's how I understand it: To execute print [], ghc has to find which instance of Show to call. How could it find an instance without knowing the type ? [] could be a list of anything, and while in theory we know that in all cases it should print "[]", in practice ghc can't call that code if it doesn't know the type of the list. David. From lehner.lukas at gmail.com Wed Aug 14 12:15:11 2013 From: lehner.lukas at gmail.com (Lukas Lehner) Date: Wed, 14 Aug 2013 12:15:11 +0200 Subject: [Haskell-beginners] print [] In-Reply-To: References: Message-ID: That I understand. My question is that I have to enforce the type that specific way (don't want to use ExtendedDefaultRules) or is there some more generic way? On Wed, Aug 14, 2013 at 12:08 PM, David Virebayre < dav.vire+haskell at gmail.com> wrote: > 2013/8/13 Lukas Lehner : > > Good to know extension. And without it? > > Someone correct me if I'm wrong, here's how I understand it: > > To execute print [], ghc has to find which instance of Show to call. > How could it find an instance without knowing the type ? > [] could be a list of anything, and while in theory we know that in > all cases it should print "[]", in practice ghc can't call that code > if it doesn't know the type of the list. > > David. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dav.vire+haskell at gmail.com Wed Aug 14 12:17:48 2013 From: dav.vire+haskell at gmail.com (David Virebayre) Date: Wed, 14 Aug 2013 12:17:48 +0200 Subject: [Haskell-beginners] Sorting Bank Accounts problem in Haskell In-Reply-To: References: Message-ID: You should probably start by switching strings to Data.Text. David. 2013/8/13 Nadav Chernin : > Hi all, > I learn Haskell and i try to solve questions from SPOJ. > > Currently, i try to solve problem Sorting Bank Accounts > > Here is my code: > > import qualified Data.Map as M > > extractTest []=[] > extractTest (x:xs)=(take n xs):(extractTest (drop (n+1) xs)) where > n=read x > > emp=M.empty > > collect m []=m > collect m (x:xs) > |M.member x m =collect (M.insert x (amount+1) m) xs > |otherwise=collect (M.insert x 1 m) xs > where > Just amount=M.lookup x m > > getList m=map (\(x,k)->x++" "++(show k)) (M.toList m) > f x=unlines$(getList (collect emp x))++[""] > main=getLine>>=(\x->interact$unlines.map f.take (read x).extractTest.lines) > > The problem is that i can't finish it during 7 sec. > So i want to know is there more quick solution/method for this problem. > Thanks, Nadav > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > From dav.vire+haskell at gmail.com Wed Aug 14 12:24:29 2013 From: dav.vire+haskell at gmail.com (David Virebayre) Date: Wed, 14 Aug 2013 12:24:29 +0200 Subject: [Haskell-beginners] print [] In-Reply-To: References: Message-ID: 2013/8/14 Lukas Lehner : > That I understand. My question is that I have to enforce the type that > specific way (don't want to use ExtendedDefaultRules) or is there some more > generic way? Ah, sorry, I don't know of a more generic way. But I'm not experienced enough to be sure. My experience is than in real world code, most of the time, the way you use the values gives enough info for ghc to infer a type. Sometimes, you can avoid adding type information by using aTypeOf from the Prelude. David. From ollie at ocharles.org.uk Wed Aug 14 14:16:49 2013 From: ollie at ocharles.org.uk (Oliver Charles) Date: Wed, 14 Aug 2013 13:16:49 +0100 Subject: [Haskell-beginners] Compiler can't deduce Bool as instance of ToField In-Reply-To: <20130814092502.GA4017@x220.att.net> References: <20130814092502.GA4017@x220.att.net> Message-ID: You have declared that foo is *any* type that has a ToField instance, allowing the caller of foo to determine the type at their will. However, your implementation of foo is more specific and requires a is actually Bool and nothing else. On 14 Aug 2013 10:24, "Bryan Vicknair" wrote: > postgresql-simple declares Bool as an instance of the ToField class. The > compiler can't deduce that given this simple code however: > > import Database.PostgreSQL.Simple.ToField (ToField(..)) > > foo :: (ToField a) => a > foo = True > > > It fails with this error: > > Db.hs:64:7: > Could not deduce (a ~ Bool) > from the context (ToField a) > bound by the type signature for foo :: ToField a => a > at Db.hs:63:8-23 > a' is a rigid type variable bound by > the type signature for foo :: ToField a => a at Db.hs:63:8 > In the expression: True > In an equation for foo': foo = True > Failed, modules loaded: none. > > What am I missing? > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From giacomo at tesio.it Wed Aug 14 15:21:13 2013 From: giacomo at tesio.it (Giacomo Tesio) Date: Wed, 14 Aug 2013 15:21:13 +0200 Subject: [Haskell-beginners] Heterogeneous Lists In-Reply-To: <20130528190810.30335234@tritium.ertes.de> References: <20130528134923.GA8721@seas.upenn.edu> <20130528190810.30335234@tritium.ertes.de> Message-ID: > > I recently ran into this with a GUI application, where I needed to > > process a list of widgets that were members of the same typeclass, but > > I had to wrap them all because they were different types. > > Your misconception is likely that you need to /store/ widgets, because > you think in terms of memory. What you really need is /definitions/ of > widgets, which can very well have different types. Then you can combine > them using the usual monadic or applicative interface. > > Ertugrul, can you please expand on this? Giacomo -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathan.huesken at posteo.de Wed Aug 14 17:03:48 2013 From: nathan.huesken at posteo.de (=?ISO-8859-1?Q?Nathan_H=FCsken?=) Date: Wed, 14 Aug 2013 17:03:48 +0200 Subject: [Haskell-beginners] Trouble with layout in wxHaskell Message-ID: <520B9C54.1040806@posteo.de> Hey, I am trying to understand how do a layout in wxHaskell. I am trying to make a frame with 2 text entries. One single lined at the top and one multiline below it. Both should expand with the window size horizontal. When the window is expanded vertical, only the multiline text entry should expand. Her is what I wrote: main = start mainFrame mainFrame = do f <- frame [text := "BiVision"] buffer <- textEntry f [] mainArea <- textCtrl f [] set f [layout := expand$ column 2 [hstretch $widget buffer, stretch$ widget mainArea]] This gives me a window with the desired controls. But they are not expanding. Why? I tried different combinations of expand and stretch (I do not really understand the difference?). But nothing works. I am guessing there is something simple I do not yet understand :). Thanks for any help! Nathan From michael.peternell at gmx.at Wed Aug 14 20:30:01 2013 From: michael.peternell at gmx.at (Michael Peternell) Date: Wed, 14 Aug 2013 20:30:01 +0200 Subject: [Haskell-beginners] print [] In-Reply-To: References: Message-ID: There is a way. It's print "[]" if the compiler cannot infer the type of an empty list, it's because you wrote a literal empty list []. Sorry for giving such a practical (non-theoretical) answer ;) Michael From KKelleher at homesite.com Wed Aug 14 21:04:43 2013 From: KKelleher at homesite.com (Kelleher, Kevin) Date: Wed, 14 Aug 2013 19:04:43 +0000 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> <105AED40-8115-4480-B039-E58C7A013D1C@arqux.com> Message-ID: <644E83C9A0C2C54A9F40341B5F63393716B8E184@CAMBOSEXC06.camelot.local> I have had the same frustration. It feels like you're learning a foreign language that doesn't have any vocabulary for walking directions, prices, or ordering food. So, while you could discuss philosophy, say, you wouldn't be able to ask for a drink of water, or how to find the bathroom. I do believe there is a payoff to studying Haskell, and I do keep plugging away, rather inconstantly. It's difficult, because I don't really have the time now, but hopefully I can devote some of an upcoming vacation to make what I know of Haskell finally touch the ground. Kevin From: Beginners [mailto:beginners-bounces at haskell.org] On Behalf Of Stephen Tetley Sent: Sunday, August 11, 2013 11:45 AM To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell Subject: Re: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment I tend to see OO subtyping and heterogeneous collections as more an impediment to (pure) functional integration with the "rest-of-the-world" than state. There are a lot of quality wrappers to stateful C libraries from Haskell, but few to object oriented C++ or Objective C libraries. On 11 August 2013 16:10, Philippe Sismondi > wrote: As a result of this little thread I have come to another conclusion, and this is just my subjective view. Most of the software that I am interested in seems to live most comfortably with a stateful conception of the world. (The native libraries I find most useful certainly are stateful.) I am reasonably competent with monads and monad transformers in Haskell. But, to be honest, after three years of pluggin away at Haskell, I am not the least convinced that the problem of handling a changing external world in a pure functional language has been successfully solved by those techniques. I always feel as though I am using the robot arm on a space shuttle when a screwdriver would do. (Again, no need to rebut this - I may be wrong or just to stupid to use Haskell effectively - so be it.) Perhaps in the end I do not really believe that functional programming is the panacea that its devotees claim it to be. This message (including any attachments) is intended only for the use of the individual or entity to which it is addressed and may contain information that is non-public, proprietary, privileged, confidential, and exempt from disclosure under applicable law or may constitute as attorney work product. If you are not the intended recipient, you are hereby notified that any use, dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, notify us immediately by telephone and (i) destroy this message if a facsimile or (ii) delete this message immediately if this is an electronic communication. Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathan.huesken at posteo.de Thu Aug 15 13:56:25 2013 From: nathan.huesken at posteo.de (=?ISO-8859-1?Q?Nathan_H=FCsken?=) Date: Thu, 15 Aug 2013 13:56:25 +0200 Subject: [Haskell-beginners] Trouble with layout in wxHaskell In-Reply-To: <520B9C54.1040806@posteo.de> References: <520B9C54.1040806@posteo.de> Message-ID: <520CC1E9.6090101@posteo.de> Ok, I need to use fill und hfill. I personally think the documentation is little confusing, but I will take this to the developers. Regards, Nathan On 08/14/2013 05:03 PM, Nathan H?sken wrote: > Hey, > > I am trying to understand how do a layout in wxHaskell. I am trying to > make a frame with 2 text entries. One single lined at the top and one > multiline below it. Both should expand with the window size > horizontal. When the window is expanded vertical, only the multiline > text entry should expand. > > Her is what I wrote: > > main = start mainFrame > > mainFrame = do > f <- frame [text := "BiVision"] > buffer <- textEntry f [] > mainArea <- textCtrl f [] > set f [layout := expand $column 2 [hstretch$ widget buffer, > stretch $widget mainArea]] > > This gives me a window with the desired controls. But they are not > expanding. > Why? > I tried different combinations of expand and stretch (I do not really > understand the difference?). But nothing works. > > I am guessing there is something simple I do not yet understand :). > > Thanks for any help! > Nathan > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners From bryanvick at gmail.com Thu Aug 15 19:49:54 2013 From: bryanvick at gmail.com (Bryan Vicknair) Date: Thu, 15 Aug 2013 10:49:54 -0700 Subject: [Haskell-beginners] Compiler can't deduce Bool as instance of ToField In-Reply-To: References: Message-ID: <20130815174954.GB3349@bry-m6300> > > Bryan Vicknair: > > postgresql-simple declares Bool as an instance of the ToField class. The > > compiler can't deduce that given this simple code however: > > > > import Database.PostgreSQL.Simple.ToField (ToField(..)) > > > > foo :: (ToField a) => a > > foo = True > > > > > > It fails with this error: > > > > Db.hs:64:7: > > Could not deduce (a ~ Bool) > > from the context (ToField a) > > bound by the type signature for foo :: ToField a => a > > at Db.hs:63:8-23 > > a' is a rigid type variable bound by > > the type signature for foo :: ToField a => a at Db.hs:63:8 > > In the expression: True > > In an equation for foo': foo = True > > Failed, modules loaded: none. > > > > What am I missing? > > > Oliver Charles > You have declared that foo is *any* type that has a ToField instance, > allowing the caller of foo to determine the type at their will. However, > your implementation of foo is more specific and requires a is actually Bool > and nothing else. > On 14 Aug 2013 10:24, "Bryan Vicknair" wrote: I see. I was confused, because the following works: bar :: (Num a) => a bar = 5 I guess it is because the literal '5' could be an Int or a Float, and the type system doesn't know. When I saw that the following does not work...:: bar :: (Show a) => a bar = False ...it made a bit more sense. It seems that if a literal can be considered part of a typeclass in more than one way, you can declare that literal to be of that typeclass. However, if there is only one way for a literal to belong to a typeclass, then you can't. Are there other literals (besides (Num a) => [a]) that don't have a concrete type like literal numbers? If I understand correctly, -XOverloadedStrings turns all literal strings into IsString instead of [Char], so that seems to be another case. I don't have a need for this, but now I'm curious: is there a way to declare that all literal numbers in a module are of a certain concrete type? Something like -XAllNumbersAreInt8? From tom.davie at gmail.com Thu Aug 15 20:11:28 2013 From: tom.davie at gmail.com (Tom Davie) Date: Thu, 15 Aug 2013 20:11:28 +0200 Subject: [Haskell-beginners] Compiler can't deduce Bool as instance of ToField In-Reply-To: <20130815174954.GB3349@bry-m6300> References: <20130815174954.GB3349@bry-m6300> Message-ID: <40F23FAC-C0F7-4C35-BAD2-6591EEF31922@gmail.com> On 15 Aug 2013, at 19:49, Bryan Vicknair wrote: >>> Bryan Vicknair: >>> postgresql-simple declares Bool as an instance of the ToField class. The >>> compiler can't deduce that given this simple code however: >>> >>> import Database.PostgreSQL.Simple.ToField (ToField(..)) >>> >>> foo :: (ToField a) => a >>> foo = True >>> >>> >>> It fails with this error: >>> >>> Db.hs:64:7: >>> Could not deduce (a ~ Bool) >>> from the context (ToField a) >>> bound by the type signature for foo :: ToField a => a >>> at Db.hs:63:8-23 >>> a' is a rigid type variable bound by >>> the type signature for foo :: ToField a => a at Db.hs:63:8 >>> In the expression: True >>> In an equation for foo': foo = True >>> Failed, modules loaded: none. >>> >>> What am I missing? >>> > >> Oliver Charles >> You have declared that foo is *any* type that has a ToField instance, >> allowing the caller of foo to determine the type at their will. However, >> your implementation of foo is more specific and requires a is actually Bool >> and nothing else. >> On 14 Aug 2013 10:24, "Bryan Vicknair" wrote: > > I see. I was confused, because the following works: > > bar :: (Num a) => a > bar = 5 > > I guess it is because the literal '5' could be an Int or a Float, and the type > system doesn't know. > > When I saw that the following does not work...:: > > bar :: (Show a) => a > bar = False > > ...it made a bit more sense. It seems that if a literal can be considered part > of a typeclass in more than one way, you can declare that literal to be of that > typeclass. However, if there is only one way for a literal to belong to a > typeclass, then you can't. That?s not it here. What you?re saying in the first case is ?no matter what numeric type you want, I can provide it?. This is true, because the compiler can decide that 5 can indeed be any numeric type. In the latter case you make the promise ?no matter what type you want, as long as you can show it, I can provide it?, but it?s false. I can say ?well okay, give me an Int? and your function can not provide it to me, despite telling me in its type signature that it can. Tom Davie From toad3k at gmail.com Thu Aug 15 23:19:16 2013 From: toad3k at gmail.com (David McBride) Date: Thu, 15 Aug 2013 17:19:16 -0400 Subject: [Haskell-beginners] Compiler can't deduce Bool as instance of ToField In-Reply-To: <20130815174954.GB3349@bry-m6300> References: <20130815174954.GB3349@bry-m6300> Message-ID: The type of 5: Prelude> :t 5 5 :: Num a => a That's why it works. The literal's type uses the type class. Other fun stuff: Prelude> :t "asdf" "asdf" :: [Char] Prelude> :set -XOverloadedStrings Prelude> :t "asdf" "asdf" :: Data.String.IsString a => a -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Thu Aug 15 23:27:55 2013 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Fri, 16 Aug 2013 04:27:55 +0700 Subject: [Haskell-beginners] Compiler can't deduce Bool as instance of ToField In-Reply-To: <20130815174954.GB3349@bry-m6300> References: <20130815174954.GB3349@bry-m6300> Message-ID: On Fri, Aug 16, 2013 at 12:49 AM, Bryan Vicknair wrote: > I guess it is because the literal '5' could be an Int or a Float, and the > type > system doesn't know. > The literal '5' is *known* to be of the *polymorphic* type (Num a => a). Ints and Floats are monomorphic instances of this polymorphic type. See http://www.haskell.org/onlinereport/basic.html#numeric-literals > When I saw that the following does not work...:: > > bar :: (Show a) => a > bar = False > > ...it made a bit more sense. It seems that if a literal can be considered > part > of a typeclass in more than one way, you can declare that literal to be of > that > typeclass. However, if there is only one way for a literal to belong to a > typeclass, then you can't. > The part "if a literal can be considered part of a typeclass in more than one way" isn't how you want to think about them (see link). Good attempt though. > I don't have a need for this, but now I'm curious: is there a way to declare that all literal numbers in a module are of a certain concrete type? Something like -XAllNumbersAreInt8? You enforce monomorphism by specifying type signatures where appropriate. In some cases, a light touch is all that's needed because type inference does the rest. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From psismondi at arqux.com Sat Aug 17 23:10:26 2013 From: psismondi at arqux.com (Philippe Sismondi) Date: Sat, 17 Aug 2013 17:10:26 -0400 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> Message-ID: I am the original poster on this. I have not checked the thread for some time - I had decided to sign off on it because seemed to be veering off in the direction of a religious dispute. (That is probably my fault; my observations were perhaps too caustic.) But I seem unable to resist. Sorry if this post makes you go "TLDR". We seem to be revisiting the whole "state/mutability is evil" thing for the umpteenth time. There is an obvious dichotomy between algorithms that are stateful (but entirely internal to the program) and those that require state + IO. (There is probably some proper terminology for this difference, but I don't know what it is.) Anyway, my main frustration with pure FP is in respect of interacting with the "outside world", i.e. IO. I suppose that in part is what what drove my question of operating systems and their native libraries, all of which (in the case of OS X) rely on mutability and state. One of the commonest claims made about pure functional languages, and Haskell in particular, is that programs written in pure functional languages contain fewer bugs than?"other stuff". The claim seems largely to be about (a) avoiding mutability, and (b) type safety and static type checking. (I have no quibble with the typing part of the claim; I love this in Haskell.) In the same spirit, Haskell programmers are wont to assert that they are confident that a program that compiles is a correct program. However, these claims (as made in books on Haskell, and on mailing lists such as this) are no more than anecdotal. At the risk of pouring fuel on the fire, I would ask: Can anyone point me to scientific studies quantifying the benefits of pure functional languages? I expect they exist, but I am interested not just in lack of errors, but in overall productivity. (It's easy to avoid program bugs: just write programs that don't do anything, or don't write any software at all.) The value of being able to produce correct programs is, no doubt enormous. But that is hardly the end of the matter. My sense is that most of us who produce software are less interested in error-free software than in overall productivity. There is an enormous amount of highly useful software out there that contains all kinds of both known and as yet undiscovered bugs. In other words, I propose that the perfect is the enemy of the good here. We are all most likely exchanging our thoughts on the topic on this mailing list using buggy operating systems, buggy email software, buggy hardware, and buggy human brains. But somehow we soldier bravely on ;-) Somebody may be writing an experimental OS in Haskell, but I ain't using it at the moment, and neither are you (probably). Moreover, whenever a list appears of Haskell systems in production, it is woefully tiny. I am reminded of the same kind of lists of Lisp software: They invariably include AutoCAD scripting, emacs, Viaweb, and?and?and a few other niche thingies, and the list peters out. Because people are mostly writing software in shitty languages like Java and Objective-C and C++ and so on. The world outside your program is stateful, I think (I agree with Heraclitus on this). Any software that must deal with the "world" outside itself over time must deal with state. So even devotees of of pure FP agree that the trick is to somehow hive off or isolate state and IO, or maybe to mimic it with pure techniques in order to ensure correctness. But the problem of dealing with IO in Haskell is hardly a solved problem. Reading the history of Haskell one discovers that the use of monads was not the first attempt at dealing with IO in the language. Moreover, research papers continue to appear on other ways to handle state and IO in FPL. So it can hardly be said that, "well, we've got this problem licked, so just suck it up and learn it." It can hardly be questioned that people find monads tough to understand; some never do, and some (like me) can use them but find them a pain in the ass (so are arrows). Thus in that sense, Haskell has saved legions of programmers from writing buggy software - because it has prevented them from writing any software at all, at least in Haskell. My guess is that FP research has and will continue to provide real benefits to software development. But making that observation that other approaches are a "bad idea" is not terribly helpful (to me, anyway). I'll continue to tinker with Haskell, and when I want to write audio software or a game or something I'll use Objective-C and the massive bug-riddled but vendor-supported, documented libraries that come with OS X. - P - From allbery.b at gmail.com Sat Aug 17 23:26:50 2013 From: allbery.b at gmail.com (Brandon Allbery) Date: Sat, 17 Aug 2013 17:26:50 -0400 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> Message-ID: On Sat, Aug 17, 2013 at 5:10 PM, Philippe Sismondi wrote: > My sense is that most of us who produce software are less interested in > error-free software than in overall productivity. There is an enormous > amount of highly useful software out there that contains all kinds of both > known and as yet undiscovered bugs. In other words, I propose that the > perfect is the enemy of the good here. I have several security lists (and victims of the reported security issues) and several rather large sectors of industry (financial and medical, to name two) which are increasingly realizing that this attitude isn't viable any more. It is becoming increasingly obvious that "productivity is more important than error-free" leads to very expensive reparations down the road. -- 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 apfelmus at quantentunnel.de Sun Aug 18 10:55:00 2013 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Sun, 18 Aug 2013 10:55:00 +0200 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> Message-ID: Philippe Sismondi wrote: > I am the original poster on this. [..] > > One of the commonest claims made about pure functional languages, and > Haskell in particular, is that programs written in pure functional > languages contain fewer bugs than?"other stuff". The claim seems > largely to be about (a) avoiding mutability, and (b) type safety and > static type checking. (I have no quibble with the typing part of the > claim; I love this in Haskell.) In the same spirit, Haskell > programmers are wont to assert that they are confident that a program > that compiles is a correct program. However, these claims (as made in > books on Haskell, and on mailing lists such as this) are no more than > anecdotal. Note that there is a principled argument for (a) that does not rely on empirical evidence. It goes as follows: avoiding mutable state means that a piece of source code, say a function definition, can be reasoned about *without* needing to know about the possible contexts (code paths) in which it can appear. In other words, the correctness of a pure function can be checked by looking only at the function definition, the rest of the program code has no bearing on it. In contrast, mutable state usually means a "spooky action at a distance" between separate code sections. > At the risk of pouring fuel on the fire, I would ask: Can > anyone point me to scientific studies quantifying the benefits of > pure functional languages? I expect they exist, but I am interested > not just in lack of errors, but in overall productivity. (It's easy > to avoid program bugs: just write programs that don't do anything, or > don't write any software at all.) You know well that (1) such studies are hard to design for any language and (2) nobody asks for studies that quantify the benefits of imperative languages, simply because they happen to be the status quo. Still, there are some interesting case studies, for instance P Hudak and M P Jones "Haskell vs. Ada vs. C++ vs. Awk vs. ... An Experiment in Software Prototyping Productivity" http://haskell.cs.yale.edu/?post_type=publication&p=366 > The value of being able to produce correct programs is, no doubt > enormous. But that is hardly the end of the matter. > > My sense is that most of us who produce software are less interested > in error-free software than in overall productivity. There is an > enormous amount of highly useful software out there that contains all > kinds of both known and as yet undiscovered bugs. [..] I always dread the prospect of dealing with non-Haskell libraries, because I often lose several days of development time investigating how a library really behaves as opposed to how it should behave according to the specification. I have mentioned two recent examples in a previous email (HTML 5 drag & drop, WebSockets), but it has also happened to me when doing development with Cocoa. > The world outside your program is stateful, I think (I agree with > Heraclitus on this). Any software that must deal with the "world" > outside itself over time must deal with state. So even devotees of of > pure FP agree that the trick is to somehow hive off or isolate state > and IO, or maybe to mimic it with pure techniques in order to ensure > correctness. Note that source code is a *model* and we are free to choose any model we like. The "true nature" of the world being "stateful" has no bearing on this. For instance, physicists actually model the world in a stateless fashion (a particle is modeled by a function from time to position in space). > But the problem of dealing with IO in Haskell is hardly a solved > problem. Reading the history of Haskell one discovers that the use of > monads was not the first attempt at dealing with IO in the language. > Moreover, research papers continue to appear on other ways to handle > state and IO in FPL. So it can hardly be said that, "well, we've got > this problem licked, so just suck it up and learn it." It can hardly > be questioned that people find monads tough to understand; some never > do, and some (like me) can use them but find them a pain in the ass > (so are arrows). Huh? How is dealing with IO not a solved problem in Haskell? Note that there may be smarter ways to deal with "IO" (e.g. FRP), but I don't see how experiments with new models invalidate an existing model. Also note that software transactional memory (STM) is a solved problem in Haskell, something that cannot be said of any other imperative language. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com From aurimas.anskaitis at vgtu.lt Mon Aug 19 03:18:28 2013 From: aurimas.anskaitis at vgtu.lt (Aurimas) Date: Mon, 19 Aug 2013 04:18:28 +0300 Subject: [Haskell-beginners] Type inference in ST monad? Message-ID: <52117264.4010404@vgtu.lt> I have the following code which does not compile due to explicit type annotation (ST s Double). Error message says usual thing about "s" type variables. ---------------------------------------------------------------------------------------------------------- import Control.Monad.ST import System.Random.MWC (initialize, uniformR, Gen) import Control.Monad.Loops (whileM) import Data.Vector (singleton) import Data.Word(Word32) main :: IO () main = do print$ runSimulation 1 runSimulation :: Word32 -> [Int] runSimulation seed = runST $do gen <- initialize (singleton seed) whileM (do r1 <- uniformR (-1.0, 1.0) gen :: ST s Double -- does not compile due to this if r1 > 0.0 then return True else return False) (do r2 <- uniformR (0, 10) gen if r2 > 5 then return r2 else return 0) --------------------------------------------------------------------------------------------------------- if I rewrite runSimulation like this (below), everything is OK. --------------------------------------------------------------------------------------------------------- runSimulation :: Word32 -> [Int] runSimulation seed = runST$ do gen <- initialize (singleton seed) whileM (do r1 <- tempFun gen if r1 > 0.0 then return True else return False) (do r2 <- uniformR (0, 10) gen if r2 > 5 then return r2 else return 0) where tempFun :: Gen s -> ST s Double -- this line automatically provides required type annotation tempFun g = uniformR (-1.0, 1.0) g --------------------------------------------------------------------------------------------------------- Ca somebody explain what's wrong with the first version? Best Regards, Aurimas From toad3k at gmail.com Mon Aug 19 04:04:26 2013 From: toad3k at gmail.com (David McBride) Date: Sun, 18 Aug 2013 22:04:26 -0400 Subject: [Haskell-beginners] Type inference in ST monad? In-Reply-To: <52117264.4010404@vgtu.lt> References: <52117264.4010404@vgtu.lt> Message-ID: I'm not exactly sure why you get the error, but the easiest way to fix it is just to type it this way: runSimulation :: Word32 -> [Int] runSimulation seed = runST $do gen <- initialize (singleton seed) whileM (do r1 <- uniformR (-1.0, 1.0 :: Double) gen if r1 > 0.0 then return True else return False) (do r2 <- uniformR (0, 10 :: Int) gen if r2 > 5 then return r2 else return 0) It has something to do with the forall s in runST, although I'm not completely sure what. On Sun, Aug 18, 2013 at 9:18 PM, Aurimas wrote: > I have the following code which does not compile due to explicit type > annotation > (ST s Double). Error message says usual thing about "s" type variables. > > ------------------------------**------------------------------** > ------------------------------**---------------- > import Control.Monad.ST > import System.Random.MWC (initialize, uniformR, Gen) > import Control.Monad.Loops (whileM) > import Data.Vector (singleton) > import Data.Word(Word32) > > main :: IO () > main = do > print$ runSimulation 1 > > runSimulation :: Word32 -> [Int] > runSimulation seed = runST $do > gen <- initialize (singleton seed) > whileM (do r1 <- uniformR (-1.0, 1.0) gen :: ST s Double -- does not > compile due to this > if r1 > 0.0 then return True else return False) > (do r2 <- uniformR (0, 10) gen > if r2 > 5 then return r2 else return 0) > ------------------------------**------------------------------** > ------------------------------**--------------- > > if I rewrite runSimulation like this (below), everything is OK. > > ------------------------------**------------------------------** > ------------------------------**--------------- > runSimulation :: Word32 -> [Int] > runSimulation seed = runST$ do > gen <- initialize (singleton seed) > whileM (do r1 <- tempFun gen > if r1 > 0.0 then return True else return False) > (do r2 <- uniformR (0, 10) gen > if r2 > 5 then return r2 else return 0) > where tempFun :: Gen s -> ST s Double -- this line automatically > provides required type annotation > tempFun g = uniformR (-1.0, 1.0) g > ------------------------------**------------------------------** > ------------------------------**--------------- > > Ca somebody explain what's wrong with the first version? > > Best Regards, > Aurimas > > > ______________________________**_________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/**mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aurimas.anskaitis at vgtu.lt Mon Aug 19 07:36:10 2013 From: aurimas.anskaitis at vgtu.lt (Aurimas) Date: Mon, 19 Aug 2013 08:36:10 +0300 Subject: [Haskell-beginners] Type inference in ST monad? In-Reply-To: References: <52117264.4010404@vgtu.lt> Message-ID: <5211AECA.6050409@vgtu.lt> On 08/19/2013 05:04 AM, David McBride wrote: > I'm not exactly sure why you get the error, but the easiest way to fix > it is just to type it this way: > > runSimulation :: Word32 -> [Int] > runSimulation seed = runST $do > gen <- initialize (singleton seed) > whileM (do r1 <- uniformR (-1.0, 1.0 :: Double) gen > if r1 > 0.0 then return True else return False) > (do r2 <- uniformR (0, 10 :: Int) gen > if r2 > 5 then return r2 else return 0) > > It has something to do with the forall s in runST, although I'm not > completely sure what. > Thanks, this is clearly the most easy way to fix the problem. But the question remains - why the line "do r1 <- uniformR (-1.0, 1.0 :: Double) gen" cannot be annotated with ST s Double? From magnus at therning.org Mon Aug 19 10:18:11 2013 From: magnus at therning.org (Magnus Therning) Date: Mon, 19 Aug 2013 10:18:11 +0200 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> Message-ID: <20130819081811.GB1125@mteis.semcon.se> On Sun, Aug 18, 2013 at 10:55:00AM +0200, Heinrich Apfelmus wrote: > Philippe Sismondi wrote: > >I am the original poster on this. [..] [...] > >At the risk of pouring fuel on the fire, I would ask: Can anyone > >point me to scientific studies quantifying the benefits of pure > >functional languages? I expect they exist, but I am interested not > >just in lack of errors, but in overall productivity. (It's easy to > >avoid program bugs: just write programs that don't do anything, or > >don't write any software at all.) > > You know well that (1) such studies are hard to design for any > language and (2) nobody asks for studies that quantify the benefits > of imperative languages, simply because they happen to be the status > quo. > > Still, there are some interesting case studies, for instance > > P Hudak and M P Jones > "Haskell vs. Ada vs. C++ vs. Awk vs. ... > An Experiment in Software Prototyping Productivity" > http://haskell.cs.yale.edu/?post_type=publication&p=366 There are also a few articles on Erlang, and I believe there's good reason to believe the results with that language can be transferred to other "languages without assignment". - Productivity gains with Erlarng http://dl.acm.org/citation.cfm?id=1362710 slides: http://is.gd/BgGZyh (behind a paywall, I haven't found a freely available copy) - Breakthrough in software design productivity through the use of declarative programming http://www.sciencedirect.com/science/article/pii/S0925527397807669 (behind a paywall, I haven't found a freely available copy) /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus Perl is another example of filling a tiny, short-term need, and then being a real problem in the longer term. -- Alan Kay -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 230 bytes Desc: not available URL: From hjgtuyl at chello.nl Mon Aug 19 12:52:20 2013 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Mon, 19 Aug 2013 12:52:20 +0200 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: <20130819081811.GB1125@mteis.semcon.se> References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> <20130819081811.GB1125@mteis.semcon.se> Message-ID: On Mon, 19 Aug 2013 10:18:11 +0200, Magnus Therning wrote: > There are also a few articles on Erlang, and I believe there's good > reason to believe the results with that language can be transferred to > other "languages without assignment". > > - Productivity gains with Erlarng > http://dl.acm.org/citation.cfm?id=1362710 > slides: http://is.gd/BgGZyh > (behind a paywall, I haven't found a freely available copy) > For free: "Four-fold Increase in Productivity and Quality" Ulf Wiger, FemSYS 2001, Munich http://www.erlang.se/publications/Ulf_Wiger.pdf Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From allbery.b at gmail.com Mon Aug 19 15:59:28 2013 From: allbery.b at gmail.com (Brandon Allbery) Date: Mon, 19 Aug 2013 09:59:28 -0400 Subject: [Haskell-beginners] Type inference in ST monad? In-Reply-To: <5211AECA.6050409@vgtu.lt> References: <52117264.4010404@vgtu.lt> <5211AECA.6050409@vgtu.lt> Message-ID: On Mon, Aug 19, 2013 at 1:36 AM, Aurimas wrote: > Thanks, this is clearly the most easy way to fix the problem. But the > question remains - why the line > "do r1 <- uniformR (-1.0, 1.0 :: Double) gen" cannot be annotated with > ST s Double? > Maybe you need ScopedTypeVariables? But I'd be suspicious that, given the forall in the definition of ST, that such a type annotation *always* creates a new s and some other way to "force" the type is needed. -- 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 aurimas.anskaitis at vgtu.lt Mon Aug 19 16:12:27 2013 From: aurimas.anskaitis at vgtu.lt (Aurimas) Date: Mon, 19 Aug 2013 17:12:27 +0300 Subject: [Haskell-beginners] Type inference in ST monad? In-Reply-To: References: <52117264.4010404@vgtu.lt> <5211AECA.6050409@vgtu.lt> Message-ID: <521227CB.30009@vgtu.lt> On 08/19/2013 04:59 PM, Brandon Allbery wrote: > On Mon, Aug 19, 2013 at 1:36 AM, Aurimas > wrote: > > Thanks, this is clearly the most easy way to fix the problem. But > the question remains - why the line > "do r1 <- uniformR (-1.0, 1.0 :: Double) gen" cannot be annotated > with ST s Double? > > > Maybe you need ScopedTypeVariables? But I'd be suspicious that, given > the forall in the definition of ST, that such a type annotation > *always* creates a new s and some other way to "force" the type is > needed. > ScopedTypeVariables does not solve the problem. As you noticed, new s is created and runST is not happy about this. It is strange that this type can be "forced" replacing given line by a function returning ST s a. -------------- next part -------------- An HTML attachment was scrubbed... URL: From paratribulations at free.fr Mon Aug 19 22:28:14 2013 From: paratribulations at free.fr (TP) Date: Mon, 19 Aug 2013 22:28:14 +0200 Subject: [Haskell-beginners] multi-parameter typeclass with default implementation Message-ID: Hi, I struggle with a dummy example using a multi-parameter typeclass containing a default implementation for a function: --------------------------------------- {-# LANGUAGE MultiParamTypeClasses #-} class Foo a b where bar :: a -> Int foobar :: a -> b -> Int foobar avalue bvalue = bar avalue instance Foo Int Int where bar i = 5 main = do print$ bar (4::Int) --------------------------------------- I obtain the following errors. I have tried various things without any success. Any help appreciated! Thanks TP PS: The errors: $runghc test.hs test.hs:8:28: Could not deduce (Foo a b1) arising from a use of bar' from the context (Foo a b) bound by the class declaration for Foo' at test.hs:(3,1)-(8,37) The type variable b1' is ambiguous Possible fix: add a type signature that fixes these type variable(s) In the expression: bar avalue In an equation for foobar': foobar avalue bvalue = bar avalue test.hs:16:9: No instance for (Foo Int b0) arising from a use of bar' The type variable b0' is ambiguous Possible fix: add a type signature that fixes these type variable(s) Note: there is a potential instance available: instance Foo Int Int -- Defined at test.hs:10:10 Possible fix: add an instance declaration for (Foo Int b0) In the second argument of ($)', namely bar (4 :: Int)' In a stmt of a 'do' block: print $bar (4 :: Int) In the expression: do { print$ bar (4 :: Int) } From bgamari.foss at gmail.com Mon Aug 19 22:59:42 2013 From: bgamari.foss at gmail.com (Ben Gamari) Date: Mon, 19 Aug 2013 16:59:42 -0400 Subject: [Haskell-beginners] multi-parameter typeclass with default implementation In-Reply-To: References: Message-ID: <87haeltn0h.fsf@gmail.com> TP writes: > Hi, > > I struggle with a dummy example using a multi-parameter typeclass containing > a default implementation for a function: > > --------------------------------------- > {-# LANGUAGE MultiParamTypeClasses #-} > > class Foo a b where > > bar :: a -> Int > The problem is in this declaration, which does not mention the type "b". This makes it impossible for the compiler to infer which instance to use when "bar" is used. This is what the compiler is trying to tell you when it says "The type variable b1' is ambiguous". As far as I know, you'd need to do something like this to accomplish what you are after, {-# LANGUAGE MultiParamTypeClasses, DefaultSignatures #-} class Bar a where bar :: a -> Int class FooBar a b where foobar :: a -> b -> Int default foobar :: Bar a => a -> b -> Int foobar avalue bvalue = bar avalue instance Bar Int where bar i = 5 instance FooBar Int Int main = do print $bar (4::Int) print$ foobar (5::Int) (2::Int) Cheers, - Ben -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 489 bytes Desc: not available URL: From magnus at therning.org Tue Aug 20 10:11:39 2013 From: magnus at therning.org (Magnus Therning) Date: Tue, 20 Aug 2013 10:11:39 +0200 Subject: [Haskell-beginners] How Haskell Fits Into an Operating System / API Environment In-Reply-To: References: <2EEE4F93-1136-48EE-8B22-A3DC7E3C4FF6@arqux.com> <20130819081811.GB1125@mteis.semcon.se> Message-ID: <20130820081139.GA8726@mteis.semcon.se> On Mon, Aug 19, 2013 at 12:52:20PM +0200, Henk-Jan van Tuyl wrote: > On Mon, 19 Aug 2013 10:18:11 +0200, Magnus Therning > wrote: > > >There are also a few articles on Erlang, and I believe there's good > >reason to believe the results with that language can be transferred to > >other "languages without assignment". > > > >- Productivity gains with Erlarng > > http://dl.acm.org/citation.cfm?id=1362710 > > slides: http://is.gd/BgGZyh > > (behind a paywall, I haven't found a freely available copy) > > > > For free: > "Four-fold Increase in Productivity and Quality" > Ulf Wiger, FemSYS 2001, Munich > http://www.erlang.se/publications/Ulf_Wiger.pdf Thanks! I was trying to find that paper yesterday, but apparently my google-fu isn't as strong as yours ;) /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves. -- Alan Kay -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 230 bytes Desc: not available URL: From paratribulations at free.fr Tue Aug 20 11:44:49 2013 From: paratribulations at free.fr (TP) Date: Tue, 20 Aug 2013 11:44:49 +0200 Subject: [Haskell-beginners] multi-parameter typeclass with default implementation References: <87haeltn0h.fsf@gmail.com> Message-ID: Ben Gamari wrote: >> {-# LANGUAGE MultiParamTypeClasses #-} >> >> class Foo a b where >> >> bar :: a -> Int >> > The problem is in this declaration, which does not mention the type > "b". This makes it impossible for the compiler to infer which instance > to use when "bar" is used. This is what the compiler is trying to tell > you when it says "The type variable b1' is ambiguous". Thanks, this works perfectly. Yet, to try to improve myself, I would like to discuss a bit on the text of the two obtained errors in my example (correct me if I am wrong below). """ test.hs:16:9: No instance for (Foo Int b0) arising from a use of bar' """ The second error is clear: indeed by calling bar on 4::Int, we don't indicate the type of b allowing to choose the right typeclass for the implementation of the bar function. The fact there is only one typeclass instance with Int as type for type variable a does not change anything: Haskell does not look at the implemented instances. In other words, ?typeclasses are open?: more typeclasses with Int as first type variable (and types different from Int for type variable b) may be added in the future, and Haskell asks to specify which one is to use now, not in the future. (Is this the right meaning for "typeclasses are open"?). """ test.hs:8:28: Could not deduce (Foo a b1) arising from a use of bar' from the context (Foo a b) bound by the class declaration for Foo' at test.hs:(3,1)-(8,37) The type variable b1' is ambiguous """ Is this the same interpretation here? That is, even in the default implementation of a typeclass function, Haskell does not suppose that the instance of bar to use is the one of the considered instance? Thanks a lot, TP From paratribulations at free.fr Tue Aug 20 12:13:28 2013 From: paratribulations at free.fr (TP) Date: Tue, 20 Aug 2013 12:13:28 +0200 Subject: [Haskell-beginners] multi-parameter typeclass with default implementation References: <87haeltn0h.fsf@gmail.com> Message-ID: <83sbea-ove.ln1@rama.universe> Ben Gamari wrote: > As far as I know, you'd need to do something like this to accomplish > what you are after, > > {-# LANGUAGE MultiParamTypeClasses, DefaultSignatures #-} > > class Bar a where > bar :: a -> Int > > class FooBar a b where > foobar :: a -> b -> Int > default foobar :: Bar a => a -> b -> Int > foobar avalue bvalue = bar avalue > > instance Bar Int where > bar i = 5 > instance FooBar Int Int > > main = do > print $bar (4::Int) > print$ foobar (5::Int) (2::Int) It seems that the "DefaultSignatures" extension is not necessary, the following version works correctly on my computer (ghc 7.6.2): ------- {-# LANGUAGE MultiParamTypeClasses #-} class Bar a where bar :: a -> Int class FooBar a b where foobar :: Bar a => a -> b -> Int foobar avalue bvalue = bar avalue instance Bar Int where bar i = 5 instance FooBar Int Int main = do print $bar (4::Int) print$ foobar (5::Int) (2::Int) ------- From twanvl at gmail.com Tue Aug 20 14:20:24 2013 From: twanvl at gmail.com (Twan van Laarhoven) Date: Tue, 20 Aug 2013 14:20:24 +0200 Subject: [Haskell-beginners] multi-parameter typeclass with default implementation In-Reply-To: <83sbea-ove.ln1@rama.universe> References: <87haeltn0h.fsf@gmail.com> <83sbea-ove.ln1@rama.universe> Message-ID: <52135F08.9040002@gmail.com> On 20/08/13 12:13, TP wrote: > {-# LANGUAGE MultiParamTypeClasses #-} > > class Bar a where > bar :: a -> Int > > class FooBar a b where > foobar :: Bar a => a -> b -> Int > foobar avalue bvalue = bar avalue > > instance Bar Int where > bar i = 5 > instance FooBar Int Int > > main = do > print $bar (4::Int) > print$ foobar (5::Int) (2::Int) It might be better to make Bar a superclass of FooBar, class Bar a => FooBar a b where foobar :: a -> b -> Int foobar a b = bar a Then the compiler knows that every instance of FooBar also requires an instance of Bar. Twan From diem at xs4all.nl Tue Aug 20 21:02:17 2013 From: diem at xs4all.nl (Dimitri Hendriks) Date: Tue, 20 Aug 2013 21:02:17 +0200 Subject: [Haskell-beginners] cabal package haskore-vintage fails to build Message-ID: <1C957484-DB86-43B2-8927-A012D4480B1A@xs4all.nl> Hi all, I'm new to this list, and know very little about haskell. I am trying to install the package haskore-vintage on mac osx version 10.6.8, using cabal, but this fails; see the log below. I have ghc version 7.6.3, and cabal-install version 1.16.0.2. ------------------------------------------------------------------------------ $cabal install haskore-vintage Resolving dependencies... Configuring haskore-vintage-0.1... Building haskore-vintage-0.1... Preprocessing library haskore-vintage-0.1... [ 1 of 16] Compiling Haskore.Monads ( src/Haskore/Monads.hs, dist/build/Haskore/Monads.o ) [ 2 of 16] Compiling Haskore.Utils ( src/Haskore/Utils.hs, dist/build/Haskore/Utils.o ) src/Haskore/Utils.hs:87:23: Not in scope: catch' src/Haskore/Utils.hs:93:23: Not in scope: catch' Failed to install haskore-vintage-0.1 cabal: Error: some packages failed to install: haskore-vintage-0.1 failed during the building phase. The exception was: ExitFailure 1$ ------------------------------------------------------------------------------ Does anyone know how to resolve this? Related problems I found: https://code.google.com/p/leksah/issues/detail?id=272 (no solution given). And here: https://github.com/haskell/cabal/issues/1137 it appears they think it is a combination of Cabal 1.10 / cabal-install 0.10 and GHC 7.6 the causes the problem with "catch", but I use cabal 1.16. Many thanks in advance, Dimitri From paratribulations at free.fr Tue Aug 20 22:12:19 2013 From: paratribulations at free.fr (TP) Date: Tue, 20 Aug 2013 22:12:19 +0200 Subject: [Haskell-beginners] multi-parameter typeclass with default implementation References: <87haeltn0h.fsf@gmail.com> Message-ID: <36vcea-pt.ln1@rama.universe> Ben Gamari wrote: > {-# LANGUAGE MultiParamTypeClasses, DefaultSignatures #-} In fact, we could try a solution using a simple parameter typeclass containing an implicit existential type b (I hope I am right): ------------------------- class Foo a where bar :: a -> Int foobar :: Foo b => a -> b -> Int foobar avalue bvalue = bar avalue instance Foo Int where bar i = 5 foobar avalue bvalue = (bar avalue) + (bar bvalue) main = do print $bar (4::Int) print$ foobar (5::Int) (3::Int) ------------------------- It works correctly: $runghc test_one_simple_parameter_typeclass.hs 5 10 But if we try to call a function external to the typeclass: ------------------------- toto :: Int -> Int toto i = 4 class Foo a where bar :: a -> Int foobar :: Foo b => a -> b -> Int foobar avalue bvalue = bar avalue instance Foo Int where bar i = 5 foobar avalue bvalue = (bar avalue) + (bar bvalue) + (toto bvalue) main = do print$ bar (4::Int) print $foobar (5::Int) (3::Int) ------------------------- We get an error message (see below) meaning that when we call "toto" with "bvalue", there is not guarantee that "bvalue" is an "Int". So, in this situation, *are we compelled to use multiparameter typeclasses*? PS: the error message yielded by the second example above:$ runghc test_one_simple_parameter_typeclass_limitation.hs test_one_simple_parameter_typeclass_limitation.hs:15:37: Could not deduce (b ~ Int) from the context (Foo b) bound by the type signature for foobar :: Foo b => Int -> b -> Int at test_one_simple_parameter_typeclass_limitation.hs:(13,5)-(15,43) b' is a rigid type variable bound by the type signature for foobar :: Foo b => Int -> b -> Int at test_one_simple_parameter_typeclass_limitation.hs:13:5 In the first argument of toto', namely bvalue' In the second argument of (+)', namely (toto bvalue)' In the expression: (bar avalue) + (bar bvalue) + (toto bvalue) From stephen.tetley at gmail.com Tue Aug 20 23:55:23 2013 From: stephen.tetley at gmail.com (Stephen Tetley) Date: Tue, 20 Aug 2013 22:55:23 +0100 Subject: [Haskell-beginners] cabal package haskore-vintage fails to build In-Reply-To: <1C957484-DB86-43B2-8927-A012D4480B1A@xs4all.nl> References: <1C957484-DB86-43B2-8927-A012D4480B1A@xs4all.nl> Message-ID: Hi Dimitri You should be able to get it to work by downloading the archive, gunzip and untarring the source and changing Utils.hs to include this line after the line "import Control.Monad": import Control.Exception hiding ( assert ) After that build with these commands from the top of the source tree: runhaskell Setup.hs configure runhaskell Setup.hs build runhaskell Setup.hs install The original problem is that catch is no longer export by Prelude in GHC 7.6 -------------- next part -------------- An HTML attachment was scrubbed... URL: From hsyl20 at gmail.com Wed Aug 21 09:49:52 2013 From: hsyl20 at gmail.com (Sylvain HENRY) Date: Wed, 21 Aug 2013 09:49:52 +0200 Subject: [Haskell-beginners] cabal package haskore-vintage fails to build In-Reply-To: References: <1C957484-DB86-43B2-8927-A012D4480B1A@xs4all.nl> Message-ID: <52147120.9000005@gmail.com> Hi, It is better to use "cabal unpack" to download and unpack the source. Cheers Sylvain Le 20/08/2013 23:55, Stephen Tetley a ?crit : > Hi Dimitri > > You should be able to get it to work by downloading the archive, > gunzip and untarring the source and changing Utils.hs to include this > line after the line "import Control.Monad": > > import Control.Exception hiding ( assert ) > > > After that build with these commands from the top of the source tree: > > runhaskell Setup.hs configure > runhaskell Setup.hs build > runhaskell Setup.hs install > > The original problem is that catch is no longer export by Prelude in > GHC 7.6 > > > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From diem at xs4all.nl Wed Aug 21 09:58:29 2013 From: diem at xs4all.nl (Dimitri Hendriks) Date: Wed, 21 Aug 2013 09:58:29 +0200 Subject: [Haskell-beginners] cabal package haskore-vintage fails to build In-Reply-To: References: <1C957484-DB86-43B2-8927-A012D4480B1A@xs4all.nl> Message-ID: <899939EF-27C7-4AC7-B953-8BA8EA966128@xs4all.nl> Many thanks Stephen, works like a charm! Finally, I can start composing music, can't wait! @Sylvain: why is cabal unpack better than tar zxvf ? Greetings, Dimitri On Aug 20, 2013, at 23:55 , Stephen Tetley wrote: > Hi Dimitri > > You should be able to get it to work by downloading the archive, gunzip and untarring the source and changing Utils.hs to include this line after the line "import Control.Monad": > > import Control.Exception hiding ( assert ) > > > After that build with these commands from the top of the source tree: > > runhaskell Setup.hs configure > runhaskell Setup.hs build > runhaskell Setup.hs install > > The original problem is that catch is no longer export by Prelude in GHC 7.6 > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners From hsyl20 at gmail.com Wed Aug 21 13:00:12 2013 From: hsyl20 at gmail.com (Sylvain HENRY) Date: Wed, 21 Aug 2013 13:00:12 +0200 Subject: [Haskell-beginners] cabal package haskore-vintage fails to build In-Reply-To: <899939EF-27C7-4AC7-B953-8BA8EA966128@xs4all.nl> References: <1C957484-DB86-43B2-8927-A012D4480B1A@xs4all.nl> <899939EF-27C7-4AC7-B953-8BA8EA966128@xs4all.nl> Message-ID: <52149DBC.5030802@gmail.com> It may be a bit quicker as it downloads and unpacks the package automatically. > cabal unpack haskore-vintage > cd haskore-vintage-0.1 > vim src/Haskore/Utils.hs > cabal install Le 21/08/2013 09:58, Dimitri Hendriks a ?crit : > @Sylvain: why is cabal unpack better than tar zxvf ? > > From paratribulations at free.fr Wed Aug 21 18:39:33 2013 From: paratribulations at free.fr (TP) Date: Wed, 21 Aug 2013 18:39:33 +0200 Subject: [Haskell-beginners] fonction in a typeclass that does not mention the type variable Message-ID: <537fea-mm5.ln1@rama.universe> Hi, I have a simple test case containing a typeclass Foo with one type variable a. The goal is to write once and for all a function symbolToInfixLevel function that combines two other functions defined in the typeclass: ----------------------- class Foo a where symbolToConstructor :: String -> ( a -> a -> a ) infixLevel :: a -> Int symbolToInfixLevel :: String -> Int symbolToInfixLevel s = infixLevel $(symbolToConstructor s) undefined undefined ----------------------- This yields an error because there is no "a" in the type signature for symbolToInfixLevel:$ runghc test_typeclass_without_typevariable.hs test_typeclass_without_typevariable.hs:1:1: The class method symbolToInfixLevel' mentions none of the type variables of the class Foo a When checking the class method: symbolToInfixLevel :: String -> Int In the class declaration for Foo' Now, if I define symbolToInfixLevel out of the typeclass: ----------------------- class Foo a where symbolToConstructor :: String -> ( a -> a -> a ) infixLevel :: a -> Int symbolToInfixLevel :: String -> Int symbolToInfixLevel s = infixLevel $(symbolToConstructor s) undefined undefined ----------------------- Now, I obtain:$ runghc test_typeclass_without_typevariable.hs test_typeclass_without_typevariable.hs:7:24: No instance for (Foo a0) arising from a use of infixLevel' In the expression: infixLevel In the expression: infixLevel $(symbolToConstructor s) undefined undefined In an equation for symbolToInfixLevel': symbolToInfixLevel s = infixLevel$ (symbolToConstructor s) undefined undefined How to get rid from this situation? Thanks in advance, TP From byorgey at seas.upenn.edu Wed Aug 21 19:01:01 2013 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Wed, 21 Aug 2013 13:01:01 -0400 Subject: [Haskell-beginners] cabal package haskore-vintage fails to build In-Reply-To: <52149DBC.5030802@gmail.com> References: <1C957484-DB86-43B2-8927-A012D4480B1A@xs4all.nl> <899939EF-27C7-4AC7-B953-8BA8EA966128@xs4all.nl> <52149DBC.5030802@gmail.com> Message-ID: <20130821170101.GA8648@seas.upenn.edu> It also uses the cached version of the tar file which is already on your disk, if you have previously installed the package, so it does not even need to download anything. -Brent On Wed, Aug 21, 2013 at 01:00:12PM +0200, Sylvain HENRY wrote: > It may be a bit quicker as it downloads and unpacks the package > automatically. > > > cabal unpack haskore-vintage > > cd haskore-vintage-0.1 > > vim src/Haskore/Utils.hs > > cabal install > > Le 21/08/2013 09:58, Dimitri Hendriks a ?crit : > >@Sylvain: why is cabal unpack better than tar zxvf ? > > > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > From peter.hall at memorphic.com Wed Aug 21 19:05:42 2013 From: peter.hall at memorphic.com (Peter Hall) Date: Wed, 21 Aug 2013 18:05:42 +0100 Subject: [Haskell-beginners] fonction in a typeclass that does not mention the type variable In-Reply-To: <537fea-mm5.ln1@rama.universe> References: <537fea-mm5.ln1@rama.universe> Message-ID: Maybe I don't fully understand what you are trying to achieve, but I don't think what you are trying to do makes sense. infixLevel and symbolToConstructor will have different implementations for each instance of Foo, and the compiler cannot possibly know which implementations you mean. If the implementation of symbolToInfixLevel is independent of the implementations of infixLevel and symbolToConstructor then it shouldn't need them in its definition. Peter On 21 August 2013 17:39, TP wrote: > Hi, > > I have a simple test case containing a typeclass Foo with one type variable > a. The goal is to write once and for all a function symbolToInfixLevel > function that combines two other functions defined in the typeclass: > > ----------------------- > class Foo a where > > symbolToConstructor :: String -> ( a -> a -> a ) > infixLevel :: a -> Int > > symbolToInfixLevel :: String -> Int > symbolToInfixLevel s = infixLevel $(symbolToConstructor s) undefined > undefined > ----------------------- > > This yields an error because there is no "a" in the type signature for > symbolToInfixLevel: > >$ runghc test_typeclass_without_typevariable.hs > test_typeclass_without_typevariable.hs:1:1: > The class method symbolToInfixLevel' > mentions none of the type variables of the class Foo a > When checking the class method: symbolToInfixLevel :: String -> Int > In the class declaration for Foo' > > Now, if I define symbolToInfixLevel out of the typeclass: > > ----------------------- > class Foo a where > > symbolToConstructor :: String -> ( a -> a -> a ) > infixLevel :: a -> Int > > symbolToInfixLevel :: String -> Int > symbolToInfixLevel s = infixLevel $(symbolToConstructor s) undefined > undefined > ----------------------- > > Now, I obtain: > >$ runghc test_typeclass_without_typevariable.hs > test_typeclass_without_typevariable.hs:7:24: > No instance for (Foo a0) arising from a use of infixLevel' > In the expression: infixLevel > In the expression: > infixLevel $(symbolToConstructor s) undefined undefined > In an equation for symbolToInfixLevel': > symbolToInfixLevel s > = infixLevel$ (symbolToConstructor s) undefined undefined > > How to get rid from this situation? > > Thanks in advance, > > TP > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mlists at pmade.com Wed Aug 21 19:20:30 2013 From: mlists at pmade.com (Peter Jones) Date: Wed, 21 Aug 2013 11:20:30 -0600 Subject: [Haskell-beginners] fonction in a typeclass that does not mention the type variable References: <537fea-mm5.ln1@rama.universe> Message-ID: <87y57vdkpt.fsf@pmade.com> TP writes: > symbolToInfixLevel :: String -> Int > symbolToInfixLevel s = infixLevel $(symbolToConstructor s) undefined > > Now, I obtain: > >$ runghc test_typeclass_without_typevariable.hs > test_typeclass_without_typevariable.hs:7:24: > No instance for (Foo a0) arising from a use of infixLevel' > In the expression: infixLevel > In the expression: > infixLevel $(symbolToConstructor s) undefined undefined > In an equation for symbolToInfixLevel': > symbolToInfixLevel s > = infixLevel$ (symbolToConstructor s) undefined undefined > > How to get rid from this situation? Your symbolToConstructor' function is too specific for both cases you describe. You'd need to change the String' argument to a' and put it back in the type class or write it like this: symbolToInfixLevel :: (Foo a) => a -> Int symbolToInfixLevel s = infixLevel $(symbolToConstructor s) undefined -- Peter Jones, Founder, Devalot.com Defending the honor of good code From mlists at pmade.com Wed Aug 21 19:37:23 2013 From: mlists at pmade.com (Peter Jones) Date: Wed, 21 Aug 2013 11:37:23 -0600 Subject: [Haskell-beginners] fonction in a typeclass that does not mention the type variable References: <537fea-mm5.ln1@rama.universe> <87y57vdkpt.fsf@pmade.com> Message-ID: <87siy3djxo.fsf@pmade.com> Peter Jones writes: > Your symbolToConstructor' function is too specific for both cases you > describe. You'd need to change the String' argument to a' and put it > back in the type class or write it like this: > > symbolToInfixLevel :: (Foo a) => a -> Int > symbolToInfixLevel s = infixLevel$ (symbolToConstructor s) undefined Actually, the problem is with your symbolToConstructor' function. It needs to look like this: symbolToConstructor :: (Foo a) => String -> a Then symbolToInfixLevel can be: symbolToInfixLevel :: String -> Int -- Peter Jones, Founder, Devalot.com Defending the honor of good code From paratribulations at free.fr Wed Aug 21 21:44:43 2013 From: paratribulations at free.fr (TP) Date: Wed, 21 Aug 2013 21:44:43 +0200 Subject: [Haskell-beginners] fonction in a typeclass that does not mention the type variable References: <537fea-mm5.ln1@rama.universe> Message-ID: Peter Hall wrote: > Maybe I don't fully understand what you are trying to achieve, but I don't > think what you are trying to do makes sense. infixLevel and > symbolToConstructor will have different implementations for each instance > of Foo, and the compiler cannot possibly know which implementations you > mean. Indeed, my question was stupid. This is obvious in the second implementation (which instance to choose?), and it is also true in the first one because even if symbolToInfixLevel of one considered instance uses infixLevel and symbolToConstructor of this same instance (what I am not sure of), at the location where I use this function the compiler cannot known which instance I mean. > If the implementation of symbolToInfixLevel is independent of the > implementations of infixLevel and symbolToConstructor then it shouldn't > need them in its definition. No, they are not independent: it is really a function that "composes" functions infixLevel and symbolToConstructor. See my proposition in my answer to Peter Jones. From paratribulations at free.fr Wed Aug 21 21:43:33 2013 From: paratribulations at free.fr (TP) Date: Wed, 21 Aug 2013 21:43:33 +0200 Subject: [Haskell-beginners] fonction in a typeclass that does not mention the type variable References: <537fea-mm5.ln1@rama.universe> <87y57vdkpt.fsf@pmade.com> <87siy3djxo.fsf@pmade.com> Message-ID: <5shfea-vh9.ln1@rama.universe> Peter Jones wrote: > Actually, the problem is with your symbolToConstructor' function. It > needs to look like this: > > symbolToConstructor :: (Foo a) => String -> a > > Then symbolToInfixLevel can be: > > symbolToInfixLevel :: String -> Int > Sorry, I have not been able to write an example with your proposition. Might you give more informations? In the meantime, I have been able to write a working example proposing two variants: ------------------------------ {-# LANGUAGE ScopedTypeVariables #-} data Exp = Plus Exp Exp | Minus Exp Exp | Atom String deriving Show class Foo a where symbolToConstructor :: String -> ( a -> a -> a ) infixLevel :: a -> Int -- The second argument is only used to indicate the type of the -- intermediary result (i.e. the type of the result of -- symbolToConstructor). symbolToInfixLevel :: String -> a -> Int symbolToInfixLevel s u = infixLevel $(((symbolToConstructor s) undefined undefined)::a) instance Foo Exp where symbolToConstructor e = case e of "+" -> Plus "-" -> Minus infixLevel e = case e of Plus _ _ -> 6 Minus _ _ -> 7 main = do -- First variant print$ infixLevel $(((symbolToConstructor "+") undefined undefined)::Exp) print$ infixLevel $(((symbolToConstructor "-") undefined undefined)::Exp) -- Second variant print$ symbolToInfixLevel "+" (undefined::Exp) print $symbolToInfixLevel "-" (undefined::Exp) ------------------------------ From bryanvick at gmail.com Mon Aug 26 23:05:00 2013 From: bryanvick at gmail.com (Bryan Vicknair) Date: Mon, 26 Aug 2013 14:05:00 -0700 Subject: [Haskell-beginners] Lifting (Either SqlError a) in a monad stack Message-ID: <20130826210500.GA4710@bry-m6300> I'm at the beginning of the monad transformers journey, and this is stumping me. I've read "Monad Transformers Step by Step" which made me confident enough to play with simple stacks, but I'm a bit lost in the following example from work. Please excuse any incorrect transformer terminology. In a WAI web app, I want to chain these two actions inside a monad stack: > safeConnect :: ConnectInfo -> IO (Either SqlError Connection) > safeInsert :: Thing -> Connection -> IO (Either SqlError Id) Here is an example where I would like 'result' to be (Right Id) only if the DB connection *and* the insert were successful, (Left SqlError) otherwise. > add :: Request -> ResourceT IO Response > add _ = do > result <- liftIO$ safeConnect devConnInfo >>= safeInsert thing > case result of > (Left e) -> return $dbErr e > (Right _) -> return$ postRedirect > where thing = exampleThing The compiler tells me (edited for brevity): Expected type: Either SqlError Connection -> GHC.Types.IO a0 Actual type: Connection -> GHC.Types.IO (Either SqlError Id) In the return type of a call of safeInsert' In the second argument of (>>=)', namely safeInsert thing' How can I chain safeConnect and safeInsert using the (Either SqlError a) monad inside WAI's (ResourceT IO Response) monad stack? From ktvoelker at gmail.com Tue Aug 27 01:18:16 2013 From: ktvoelker at gmail.com (Karl Voelker) Date: Mon, 26 Aug 2013 16:18:16 -0700 Subject: [Haskell-beginners] Lifting (Either SqlError a) in a monad stack In-Reply-To: <20130826210500.GA4710@bry-m6300> References: <20130826210500.GA4710@bry-m6300> Message-ID: The problem is that the Either SqlError monad is not actually a part of your "monad stack". It's just something that appears in the result type of safeConnect and safeInsert. In order to put Either SqlError into your stack, you'll need a monad transformer which exhibits Either-like semantics, such as EitherT or ErrorT. Then your safeConnect would have type "ConnectInfo -> EitherT SqlError IO Connection". http://hackage.haskell.org/packages/archive/either/3.4.1/doc/html/Control-Monad-Trans-Either.html http://hackage.haskell.org/packages/archive/transformers/0.3.0.0/doc/html/Control-Monad-Trans-Error.html -Karl On Mon, Aug 26, 2013 at 2:05 PM, Bryan Vicknair wrote: > I'm at the beginning of the monad transformers journey, and this is > stumping > me. I've read "Monad Transformers Step by Step" which made me confident > enough > to play with simple stacks, but I'm a bit lost in the following example > from > work. Please excuse any incorrect transformer terminology. > > In a WAI web app, I want to chain these two actions inside a monad stack: > > > safeConnect :: ConnectInfo -> IO (Either SqlError Connection) > > safeInsert :: Thing -> Connection -> IO (Either SqlError Id) > > Here is an example where I would like 'result' to be (Right Id) only if > the DB > connection *and* the insert were successful, (Left SqlError) otherwise. > > > add :: Request -> ResourceT IO Response > > add _ = do > > result <- liftIO $safeConnect devConnInfo >>= safeInsert thing > > case result of > > (Left e) -> return$ dbErr e > > (Right _) -> return $postRedirect > > where thing = exampleThing > > The compiler tells me (edited for brevity): > > Expected type: Either SqlError Connection -> GHC.Types.IO a0 > Actual type: Connection -> GHC.Types.IO (Either SqlError Id) > In the return type of a call of safeInsert' > In the second argument of (>>=)', namely > `safeInsert thing' > > How can I chain safeConnect and safeInsert using the (Either SqlError a) > monad > inside WAI's (ResourceT IO Response) monad stack? > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthony_clayden at clear.net.nz Tue Aug 27 11:46:59 2013 From: anthony_clayden at clear.net.nz (AntC) Date: Tue, 27 Aug 2013 09:46:59 +0000 (UTC) Subject: [Haskell-beginners] print [] References: Message-ID: > Lukas Lehner gmail.com> writes: > > ... My question is that I have to enforce the type that specific way (don't want to use?ExtendedDefaultRules) or is there some more generic way? > print flatten (List ([] :: Show a => [a]) Even for an empty list, we have to provide evidence that the list is showable. That's what the type signature is doing: I am a list of something/anything showable. (If you want all of your NestedLists's to be showable, it's better to put a Show constraint on the data decl. But that would take us into existential types or GADT's.) AntC From kxra at riseup.net Thu Aug 29 07:59:58 2013 From: kxra at riseup.net (=?UTF-8?B?S+G6j3Jh?=) Date: Thu, 29 Aug 2013 01:59:58 -0400 Subject: [Haskell-beginners] Haskell mentors/tutors website? Message-ID: Is there an existing website to connect haskell mentors and mentees? I'm thinking of something along the lines of railsmentors (except, of course, with haskell support). I suppose it doesn't have to be Haskell specific, as long as it's a supported language. Codementor.io seems like a really cool option along those lines, but it would also be valuable to have a network for volunteer mentors. The closest I have seen is Haskellers, which is not about mentorship, but instead only about hiring and job hunting. P.S. Are there any LGBTQIA/female/disabled people of color on this list who would be willing to teach myself and other folks from the Empowermentors Collective? http://kxra.tumblr.com/post/54139122042/please-signal-boost-the-empowermentors Thanks! K?ra -- Board of Directors, Free Culture Foundation: www.freeculture.org Web: kxra.info - StatusNet Microblog: http://identi.ca/kxra Email: kxra at freeculture.org - SMS: +1.617.340.3661 Jabber/XMPP: kxra at riseup.net - IRC: kxra @freenode @oftc @indymedia -------------- next part -------------- An HTML attachment was scrubbed... URL: From ehamberg at gmail.com Thu Aug 29 08:31:55 2013 From: ehamberg at gmail.com (Erlend Hamberg) Date: Thu, 29 Aug 2013 08:31:55 +0200 Subject: [Haskell-beginners] multi-parameter typeclass with default implementation In-Reply-To: References: Message-ID: You could also use functional dependencies here: {-# LANGUAGE FunctionalDependencies #-} class Foo a b | a -> b where bar :: a -> Int foobar :: a -> b -> Int foobar avalue bvalue = bar avalue instance Foo Int Int where bar i = 5 main = print$ bar (4::Int) Here you are saying that the type parameter b is determined by the parameter a, so GHC knows that the instance Foo Int Int is the only instance of Foo with a = Int, thus removing the ambiguity. -- Erlend Hamberg ehamberg at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From shaegis at gmail.com Thu Aug 29 09:02:52 2013 From: shaegis at gmail.com (S. H. Aegis) Date: Thu, 29 Aug 2013 16:02:52 +0900 Subject: [Haskell-beginners] How can I keep delimiters in splitRegex? Message-ID: Hi. I'm newbee to Haskell. I want to keep delimiters in splitRegex like 'keepDelimsR'. I try... splitRegex (keepDelimsR (mkRegex "2013[0-9]{11}AH02")) myDataString but It doesn't work. How can I keep delimiters in splitRegex? Have a nice day. Thank you. S. Chang. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathan.huesken at posteo.de Sat Aug 31 20:05:26 2013 From: nathan.huesken at posteo.de (=?ISO-8859-1?Q?Nathan_H=FCsken?=) Date: Sat, 31 Aug 2013 20:05:26 +0200 Subject: [Haskell-beginners] Early return in IO monad Message-ID: <52223066.7010502@posteo.de> Hey, Is it somehow possible to return "early" in a do block of the IO monad? The eqivalent do in C: void doBlock() { if (some preCondition) { return; } ... } ??? Thanks! Nathan From byorgey at seas.upenn.edu Sat Aug 31 20:23:16 2013 From: byorgey at seas.upenn.edu (Brent Yorgey) Date: Sat, 31 Aug 2013 14:23:16 -0400 Subject: [Haskell-beginners] Early return in IO monad In-Reply-To: <52223066.7010502@posteo.de> References: <52223066.7010502@posteo.de> Message-ID: <20130831182316.GA23914@seas.upenn.edu> On Sat, Aug 31, 2013 at 08:05:26PM +0200, Nathan H?sken wrote: > Hey, > > Is it somehow possible to return "early" in a do block of the IO monad? > The eqivalent do in C: > > void doBlock() { > if (some preCondition) { > return; > } > ... > } > > ??? Nope. But you can say do ... when (not (some condition)) \$ do the rest of the stuff You can even indent "the rest of the stuff" directly under the 'when' if you like, though IMO that may be a bit confusing. -Brent From gnusokyo at gmail.com Sat Aug 31 22:03:35 2013 From: gnusokyo at gmail.com (Tidus Zero) Date: Sat, 31 Aug 2013 22:03:35 +0200 Subject: [Haskell-beginners] Early return in IO monad In-Reply-To: <52223066.7010502@posteo.de> References: <52223066.7010502@posteo.de> Message-ID: <262EAF29-F84B-40BE-9664-50AA29172A5D@gmail.com> You can use the EitherT monad with IO and use the 'left' function which is just 'fail' to return early if you aren't restricted to only use the IO monad. Sent from my iGNU On 31. aug. 2013, at 20.05, Nathan H?sken wrote: > Hey, > > Is it somehow possible to return "early" in a do block of the IO > monad? > The eqivalent do in C: > > void doBlock() { > if (some preCondition) { > return; > } > ... > } > > ??? > > Thanks! > Nathan > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners