Re: [Haskell-cafe] IO is a bad example for Monads [was: do]
I agree with Dan here. IO is important because you can't write any real program without using it. So why not teach enough of it to get people off the ground straight away? People who hang around long enough to do some more Haskell programming will run into the other monads sooner or later. But IO is an unavoidable step to writing Haskell programs. On Dec 4, 2007 5:11 AM, Dan Piponi [EMAIL PROTECTED] wrote: On Dec 3, 2007 6:36 PM, Ben Franksen [EMAIL PROTECTED] wrote: then the special features of IO will remain associated with monads in general, leading to a whole jumble of completely wrong ideas about them. As I only learnt about monads a couple of years ago, the process is still fresh in my mind. I wasted quite a bit of time labouring under the impression that monads were primarily about sequencing. But that wasn't because I incorrectly generalised from IO. It was because countless people out there explicitly said they were about sequencing. I suspect that if courses started with the List monad there'd be countless blogs telling people that monads are a way to eliminate loops from your code like the way list comprehensions are used in Python. This is yet another problem with IO as the standard example for monads: its effect base is huge and poorly structured. You don't teach *all* of IO to students in one go! This again makes it difficult to see exactly which intuitions about IO can be generalized to arbitrary monads and which not. That's true of any monad. IO is unique. [] is unique. Cont is unique. All of them can lead you down the garden path. You need to see multiple monads, and it helps if you can sneak an example under a student's nose so they can already reason about monads before they even know what a monad is. What is pointless about failure and how to handle it? It's pointless when you're still trying to make your first tweaks to Hello, World! work. -- Dan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] a Char-Char function?
0x02 is not a Char, it's a numeric constant. Perhaps you meant '\x02' ? On Dec 8, 2007 9:02 AM, Galchin Vasili [EMAIL PROTECTED] wrote: Hello, I am writing a function(actually much more than this): bozo :: Char - Char bozo 0x02 = 'a' ... However, I get complaints from ghc suggesting that I should add an instance declaration (Num, Char). I (mistaking) thought I understood the Haskell class hierarchy and the associated constraints .. but apparently not .. = help please. Should Kind regards, Vasya ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] a Char-Char function?
Hello, I am writing a function(actually much more than this): bozo :: Char - Char bozo 0x02 = 'a' ... However, I get complaints from ghc suggesting that I should add an instance declaration (Num, Char). I (mistaking) thought I understood the Haskell class hierarchy and the associated constraints .. but apparently not .. = help please. Should Kind regards, Vasya ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: distinguish functions from non-functions in a class/instances
Luke Palmer wrote: Hmm, this still seems ill-defined to me. compose :: (Int - Int - Int) - (Int - Int) - Int - Int - Int Is a valid expression given that definition (with a,b = Int and c = Int - Int), but now the arity is 4. That's correct, the arity of a function is not well-defined due to polymorphism. The simplest example is probably id :: a - a-- arity 1 id = ($) :: (a - b) - (a - b) -- arity 2 Therefore, the polymorphic expression wrap id is problematic. It roughly has the type wrap id ~~ [String] - a But it's clearly ambiguous: do we have wrap id (x:_) = read x or wrap id (f:x:_) = wrap ($) (f:x:_) = read f (read x) or what? (assuming a read instance for function types) GHCi gives it a type :type wrap id wrap id :: (FunWrap (a - a) y) = [String] - y but trying to use it like in let x = wrap id [1] :: Int yields lots of type errors. We have to specialize the type of id before supplying it to wrap . For example, wrap (id :: Int - Int) works just fine. I don't like this behavior of wrap since it violates the nice property of polymorphic expressions that it's unimportant when a type variable is instantiated, like in map ((+1) :: Int - Int) [1..5] = map (+1) ([1..5] :: [Int]) = (map (+1) [1..5]) :: [Int] Regards, apfelmus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Literate HTML
Hello, You can compile a .html file with: ghc --make -x lhs index.html if you write the code like this: code foo = 1 /code N.B. You need an empty line between code and the code and one between the code and /code. The -x flag doesn't seem to work for runhaskell, when I try this, I get the message: interactive:1:112: attempting to use module `Main' (Main.hs) which is not loaded Regards, Henk-Jan On Fri, 07 Dec 2007 20:07:41 +0100, Neil Mitchell [EMAIL PROTECTED] wrote: Hi I want literate Haskell, but where the literate bit forming a document is actually HTML, not latex. Does anyone have any idea how to go about this? -- http://functor.bamikanarie.com http://Van.Tuyl.eu/ -- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] do notation strangeness
Hello! I see from http://www.haskell.org/haskellwiki/Monads_as_computation#Do_notation that do { v - x ; stmts } = x = \v - do { stmts } However, look at this GHCi session: Prelude let return' = return :: a - Maybe a Prelude do {1 - return 1; return' ok} Just ok Prelude return 1 = \1 - return' ok Just ok Prelude do {1 - return 3; return' ok} Nothing Prelude return 3 = \1 - return' ok *** Exception: interactive:1:13-30: Non-exhaustive patterns in lambda Hmmm... let's try with IO: Prelude let return' = return :: a - IO a Prelude do {1 - return 1; return' ok} ok Prelude return 1 = \1 - return' ok ok Prelude do {1 - return 3; return' ok} *** Exception: user error (Pattern match failure in do expression at interactive:1:4) Prelude return 3 = \1 - return' ok *** Exception: interactive:1:13-30: Non-exhaustive patterns in lambda Oh! What about lists? Prelude let return' = return :: a - [a] Prelude do {1 - return 1; return' ok} [ok] Prelude return 1 = \1 - return' ok [ok] Prelude do {1 - return 3; return' ok} [] Prelude return 3 = \1 - return' ok *** Exception: interactive:1:13-30: Non-exhaustive patterns in lambda Something seems wrong to me here. What am I missing? Thanks! -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] do notation strangeness
On Sat, Dec 08, 2007 at 02:59:16PM -0200, Felipe Lessa wrote: Hello! I see from http://www.haskell.org/haskellwiki/Monads_as_computation#Do_notation that do { v - x ; stmts } = x = \v - do { stmts } However, look at this GHCi session: Prelude let return' = return :: a - Maybe a Prelude do {1 - return 1; return' ok} Just ok Prelude return 1 = \1 - return' ok Just ok Prelude do {1 - return 3; return' ok} Nothing Prelude return 3 = \1 - return' ok *** Exception: interactive:1:13-30: Non-exhaustive patterns in lambda What seems confusing to you? \1 - foo is the same as \x - case x of {1 - foo;} When this function is evaluated with parameter different from 1, Haskell fails to find matching pattern for x and exception occurs. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] do notation strangeness
On Sat, Dec 08, 2007 at 03:28:58PM -0200, Felipe Lessa wrote: On Dec 8, 2007 3:12 PM, Ilya Tsindlekht [EMAIL PROTECTED] wrote: On Sat, Dec 08, 2007 at 02:59:16PM -0200, Felipe Lessa wrote: Prelude do {1 - return 3; return' ok} Nothing Prelude return 3 = \1 - return' ok *** Exception: interactive:1:13-30: Non-exhaustive patterns in lambda What seems confusing to you? \1 - foo is the same as \x - case x of {1 - foo;} When this function is evaluated with parameter different from 1, Haskell fails to find matching pattern for x and exception occurs. The problem is that with the do notation it doesn't raise an exception. In the example you quoted, Yes, I have already understood it from your reply to the original poster. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [OT] A nice organized collection of threads in Haskell-Cafe
Albert Y. C. Lai wrote: Some reply posts lack In-Reply-To: References: headers because their authors fail to choose compliant software or know the issue. Some non-reply posts (genuinely new topic, not even digression from existing ones) contain In-Reply-To: References: headers because their authors fail to know the issue and just hit reply to write new posts. All these are because the everyone can haz PC movement failed to educate everyone. You can cope by looking at Subject:. Thunderbird has a long-standing bug in that new posts having the same subject line as some other post that happened many years ago get added to that thread. It's really most irritating. :-S ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Point and link
Tom Davies wrote: Andrew Coppin andrewcoppin at btinternet.com writes: [snip] You might like to look at OpenQuark: http://labs.businessobjects.com/cal/ -- its 'GemCutter' provides a visual environment for linking together functions written in a Haskell-like language. I'm not sure if it would be flexible enough for you out of the box, but it's open source so you might be able to adapt it. Looks interesting anyway... Thanks for the tip. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Point and link
Denis Bueno wrote: Do you need to update positions of the units in real time? Do they even evolve over time, or are you just trying to visualise? If it's the latter, you might just take a collection of units and connections between them, output them in the graphviz [0] format, and see the resulting drawing. Graphviz is for visualising arbitrary graphs, and it's quite good at it. If you're thinking of writing games, then this suggestion likely won't help; but you didn't specify anything about real-time update, so I thought I'd mention it. Well, for starters, take a look at KLogic. It's a nice program, but it has two small problems: 1. Sometimes it produces outright incorrect results. 2. It crashes with extreme frequency. I'd like to write a similar program in Haskell that does not have these properties. Of course, simulating a bunch of logic gates is a pretty trivial programming task. All the difficulty is in making a usable UI. I have ideas for several other programs which would require more or less the same kind of UI - you add things to the screen and wire them up. The things in question are different. But it's still things that need wiring up. I was wondering if any tools already exist to tackle this kind of thing...? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] general
hi I have a problem. Function A is a function that passes its input into B Function B is a function that does something once. How do I make it so function A is done multiple times without adding a third function? Ryan _ Who's friends with who and co-starred in what? http://www.searchgamesbox.com/celebrityseparation.shtml___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] general
On Dec 8, 2007 7:41 PM, Ryan Bloor [EMAIL PROTECTED] wrote: hi I have a problem. Function A is a function that passes its input into B Function B is a function that does something once. What do you mean by that? B does something once. More details! (Type signatures at least will give us a good idea what is going on) Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [OT] A nice organized collection of threads in Haskell-Cafe
Albert Y. C. Lai wrote: Andrew Coppin wrote: Thunderbird has a long-standing bug in that new posts having the same subject line as some other post that happened many years ago get added to that thread. It's really most irritating. :-S I have investigated. A bit of skepticism goes a long way. Never be taken in. So, for the record: In Thunderbird if you click Write (not Reply or Reply All), the headers are according to the semantics of Write, i.e., no References: or In-Reply-To:. Insofar as headers, this is correct behaviour. When Thunderbird gets a post (from your Write or from outside) with no References: and In-Reply-To: header, but with Subject: same as existing posts, it still displays them together as a thread. But this is just a display trick - References: and In-Reply-To: are not fudged. Evidently, this is a measure against non-compliant posts. Furthermore, this is configurable. In the config editor, look for mail.strict_threading. The presence of the setting implies that the programmers know what they are getting into. There is a tension between following the rules and inter-operating with those who don't follow the rules. This is not a bug; this is a conscious compromise. And you can change it. Changing the setting doesn't change the threading structure of existing posts - the decisions made back then were recorded. (There is also a way to delete that, along with lots of other meta-data: delete the appropriate .msf file.) The setting is effective for posts seen henceforth. I can't blame you for being not observant. Afterall, this is precisely what I'm alluding to with everyone can haz PC, or rather, the way Bill Gates executes it. Everyone becomes superficial, everyone just looks at what's displayed on the screen - or rather, fictionized on the screen - and jumps to conclusions. Never be taken in. I have heard - multiple times - that this erroneous behaviour can be turned off. I have tried endlessly to follow such instructions to the letter. And yet, I can never get Thunderbird to not misthread things. So kindly don't tell me I'm jumping to conclusions. I've read the bug reports (there have been many!) and followed the instructions for changing the settings, and it never ever works. I still get broken threading. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] general
On 8 Dec 2007, [EMAIL PROTECTED] wrote: Function A is a function that passes its input into B Function B is a function that does something once. How do I make it so function A is done multiple times without adding a third function? By this, do you mean that you have functions f, g f :: a - a g :: a - b and you want b . f . f . f . ... . f where there are n applications of f? If so, then g . (!! n) . iterate f will do the trick. Alternatively, you can produce the infinite list, as in: map (^2) . iterate succ $ 0 -- [0,1,4,9,16,25,36,49,64,81 ... Jed pgpjrNihmzAWk.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Point and link
On Dec 8, 2007 10:15 PM, Andrew Coppin [EMAIL PROTECTED] wrote: Bit Connor wrote: On Dec 8, 2007 8:19 PM, Andrew Coppin [EMAIL PROTECTED] wrote: http://alts.homelinux.net/shots/195-0.jpg This is the kind of thing I'd like to end up with. Such a GUI would also be cool for visually programming Functional Reactive Programming systems using yampa, by connecting Signal Transformers using the arrow combinators. It would be a glorified version of the arrow do notation syntax. Such a GUI would be cool for a number of projects. It still needs to exist first. ;-) What about Gnome Canvas? It's a widget for Gtk+. I don't think there are haskell bindings for it. Gtk2hs already has bindings to a number of gtk/gnome extensions... maybe Gnome Canvas can be next on the list? Here are screenshots: http://gstreamer.freedesktop.org/data/images/gst-editor/gst-editor-0.4.1.png http://gstreamer.freedesktop.org/data/images/gst-editor/gst-editor-ambisonics.png Peace, Bit ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Problem with Gtk2hs
I just spent the evening writing a library that's a thin layer over Gtk2hs. It took an age to get it to compile, but eventually it worked. Yay! When I ran it, I got this: Test2: gtk/Graphics/UI/Gtk/Gdk/PixbufData.hs.pp:58:0: No instance nor default method for class operation Data.Array.Base.getNumElements Er... wow. OK, at this point, I am completely stumped. Any hints? (Also, the documentation for Graphics.UI.Gtk.Misc.DrawingArea suggests that you may want to draw a Pixbuf using the pixbufRenderToDrawable function - but GHC complains that this function doesn't exist. I had to use drawPixbuf instead. Wow that has a lot of parameters... In particular, the final two don't seem to be documented. Interesting. They're both 0 in the fastdraw demo.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [OT] A nice organized collection of threads in Haskell-Cafe
Albert Y. C. Lai wrote: I can't blame you for being not observant. Afterall, this is precisely what I'm alluding to with everyone can haz PC [...] Please don't flame people on the list. Thank you, b ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problem with Gtk2hs
On Sat, Dec 08, 2007 at 08:33:36PM +, Andrew Coppin wrote: I just spent the evening writing a library that's a thin layer over Gtk2hs. It took an age to get it to compile, but eventually it worked. Yay! When I ran it, I got this: Test2: gtk/Graphics/UI/Gtk/Gdk/PixbufData.hs.pp:58:0: No instance nor default method for class operation Data.Array.Base.getNumElements Er... wow. OK, at this point, I am completely stumped. Any hints? That's pretty obviously a bug - Graphics.UI.Gtk.Gdk.PixbufData doesn't fully implement the (M)Array class. (Also, the documentation for Graphics.UI.Gtk.Misc.DrawingArea suggests that you may want to draw a Pixbuf using the pixbufRenderToDrawable function - but GHC complains that this function doesn't exist. I had to use drawPixbuf instead. Wow that has a lot of parameters... In particular, the final two don't seem to be documented. Interesting. They're both 0 in the fastdraw demo.) Stefan signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Point and link
On Sat, 8 Dec 2007, Bit Connor wrote: On Dec 8, 2007 8:19 PM, Andrew Coppin [EMAIL PROTECTED] wrote: Andrew Coppin wrote: Well, for starters, take a look at KLogic. http://alts.homelinux.net/shots/195-0.jpg This is the kind of thing I'd like to end up with. Such a GUI would also be cool for visually programming Functional Reactive Programming systems using yampa, by connecting Signal Transformers using the arrow combinators. It would be a glorified version of the arrow do notation syntax. Reminds me on http://www.haskell.org/pipermail/haskell-cafe/2007-August/030972.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Point and link
Bit Connor wrote: On Dec 8, 2007 10:15 PM, Andrew Coppin [EMAIL PROTECTED] wrote: Bit Connor wrote: On Dec 8, 2007 8:19 PM, Andrew Coppin [EMAIL PROTECTED] wrote: http://alts.homelinux.net/shots/195-0.jpg This is the kind of thing I'd like to end up with. Such a GUI would also be cool for visually programming Functional Reactive Programming systems using yampa, by connecting Signal Transformers using the arrow combinators. It would be a glorified version of the arrow do notation syntax. Such a GUI would be cool for a number of projects. It still needs to exist first. ;-) What about Gnome Canvas? It's a widget for Gtk+. I don't think there are haskell bindings for it. Gtk2hs already has bindings to a number of gtk/gnome extensions... maybe Gnome Canvas can be next on the list? I'm told gnome canvas is deprecated? Gtk2Hs has some Cairo bindings though, which are capable of quite pretty stuff. Jules ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Over-allocation
gracjanpolak: Gracjan Polak gracjanpolak at gmail.com writes: Don Stewart dons at galois.com writes: ByteStrings have all the same operations as lists though, so you can index, compare and take substrings, with the benefit that he underlying string will be shared, not copied. And only use 1 byte per element. Is there any parser built directly over ByteString that I could look at? Or maybe somebody implemented something like Text.ParserCombinators.ReadP for ByteString? From the first sight it seems doable, so there is light at the end of the tunnel :) Just a success report, after 58 min of coding I got kind of ReadP parser over ByteString working and my memory usage went down from 1500MB to... 1.2MB! Over 1000 times better! Incredible! Thanks for the suggestion to do it with ByteStrings! I hope to publish it when I clean it up enough! That is really awesome! Sharing input strings around with bytestrings really should lead to excellent memory savings in parsing. I'm glad we see this confirmed. Will you be releasing the code soon? -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] general-revised
hi I have four functions below: What I want to do is have a way to parse more than one digit or more than one string head in ParseTrue. Any ideas... removeSpace:: String - StringremoveSpace = dropWhile (`elem` space) where space = [' '] match :: String - String - (Bool, String)match word str| ((isPrefixOf) (removeSpace word) (removeSpace str)) = (True,rest) | otherwise = (False,str) where rest = drop (length (removeSpace word)) (removeSpace str) parseDigit :: String - [(Int, String)]parseDigit (x:xs) | isDigit x = [(read [x],xs)] | otherwise = [] parseTrue :: String - (Bool, String)parseTrue x = match True x Ryan _ Celeb spotting – Play CelebMashup and win cool prizes https://www.celebmashup.com___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Type error in final generator
Hi, I am new to Haskell. I wrote the following code: module Main where import IO main = do hSetBuffering stdin LineBuffering numList - processInputs foldr (+) 0 numList processInputs = do putStrLn Enter a number: strNum - getLine let num = read strNum if num == 0 then return [] else do rest - processInputs return (num : rest) And am getting the following errors: ERROR Ex310.hs:6 - Type error in final generator *** Term : foldr (+) 0 numList *** Type : Integer *** Does not match : IO a Any pointers to the source of this error would be appreciated. Thanks, Logo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type error in final generator
Loganathan Lingappan wrote: main = do hSetBuffering stdin LineBuffering numList - processInputs foldr (+) 0 numList The type of main is understood to be IO (), so it can't return anything. You could work around this by rewriting the last line above as follows: print (foldr (+) 0 numList) This prints the number, which is presumably what you want, and print has type IO (), so it works out nicely here. b ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type error in final generator
On Sat, 2007-12-08 at 16:39 -0800, Bryan O'Sullivan wrote: Loganathan Lingappan wrote: main = do hSetBuffering stdin LineBuffering numList - processInputs foldr (+) 0 numList The type of main is understood to be IO (), so it can't return anything. You could work around this by rewriting the last line above as follows: print (foldr (+) 0 numList) This prints the number, which is presumably what you want, and print has type IO (), so it works out nicely here. Nitpicking: Actually, as the error message says, the type of main is IO a so it can 'return' -anything- and that will be discarded as the type makes clear. The issue is that foldr (+) 0 numList :: Integer and that's not IO a for any a. Either way, Bryan's suggestion is probably what you want. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type error in final generator
Thanks Bryan and Derek. This works! Logo - Original Message From: Derek Elkins [EMAIL PROTECTED] To: Bryan O'Sullivan [EMAIL PROTECTED] Cc: Loganathan Lingappan [EMAIL PROTECTED]; haskell-cafe@haskell.org Sent: Saturday, December 8, 2007 4:53:54 PM Subject: Re: [Haskell-cafe] Type error in final generator On Sat, 2007-12-08 at 16:39 -0800, Bryan O'Sullivan wrote: Loganathan Lingappan wrote: main = do hSetBuffering stdin LineBuffering numList - processInputs foldr (+) 0 numList The type of main is understood to be IO (), so it can't return anything. You could work around this by rewriting the last line above as follows: print (foldr (+) 0 numList) This prints the number, which is presumably what you want, and print has type IO (), so it works out nicely here. Nitpicking: Actually, as the error message says, the type of main is IO a so it can 'return' -anything- and that will be discarded as the type makes clear. The issue is that foldr (+) 0 numList :: Integer and that's not IO a for any a. Either way, Bryan's suggestion is probably what you want. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] do... error
hi test :: Parser (Char,Char) test = do x - item item y - item return (x,y) How come this brings an error saying that after do {} it must end with an expression. Ryan _ Get free emoticon packs and customisation from Windows Live. http://www.pimpmylive.co.uk___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] do... error
On Dec 8, 2007, at 21:38 , Ryan Bloor wrote: test :: Parser (Char,Char) test = do x - item item The second and subsequent lines are indented too much, so are read as a continuation of the first; which, starting with x - , is not an expression. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] do... error
On Dec 8, 2007, at 21:40 , Brandon S. Allbery KF8NH wrote: On Dec 8, 2007, at 21:38 , Ryan Bloor wrote: test :: Parser (Char,Char) test = do x - item item The second and subsequent lines are indented too much, so are read as a continuation of the first; which, starting with x - , is not an expression. I neglected to say the proper indentation: test = do x - item item -- note, indented to match the token after the do y - item return (x,y) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] do... error
On Dec 9, 2007 12:42 AM, Brandon S. Allbery KF8NH [EMAIL PROTECTED] wrote: I neglected to say the proper indentation: test = do x - item item -- note, indented to match the token after the do y - item return (x,y) That is the best thing to do. If you don't like the identation rule, you may also use explicit semicolons as in test = do {x - item; item; y - item; return (x,y)} or maybe test = do {x - item; item; y - item; return (x,y)} or even test = do { x - item; item ; y - item ; return (x,y)} Of course, in the last example you lost all the legibility of your code, but it compiles =). HTH, -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] do... error
On Dec 9, 2007 1:01 AM, Ryan Bloor [EMAIL PROTECTED] wrote: But what is the right way to indent...? It is so annoying, why does it matter so much! :( You may read http://en.wikibooks.org/wiki/Haskell/Indentation which tries to explain in a very simple language. -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] annoying output
hi The code below does almost what I want but not quite! It outputs...parseInt 12444a gives... [(EInt 1,2444a),(EInt 2,444a),(EInt 4,44a),(EInt 4,4a),(EInt 4,a)] What I want is: [(EInt 12444, a)] data Expr = EInt {vInt :: Int} -- integer values | EBool {vBool :: Bool} -- boolean values parseInt :: Parser parseInt (x:xs) | (isDigit x xs /= []) = [(EInt (read [x]),xs)] ++ parseInt xs | isDigit x xs == [] = [(EInt (read [x]),[])] | otherwise = [] Thanks Ryan _ Who's friends with who and co-starred in what? http://www.searchgamesbox.com/celebrityseparation.shtml___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] annoying output
Well, you're choosing to parse each digit of your integer as a separate integer, so if you want to combine them after reading you'll need to multiply by powers of two. Or, you can just read in all the digits in one 'read' command, like this: parseInt :: String - (Expr, String) parseInt xs = let (digits, rest) = span isDigit in (EInt (read digits), rest) where 'span' is defined in the Prelude. Hope this helps! - Phil On Dec 8, 2007 10:03 PM, Ryan Bloor [EMAIL PROTECTED] wrote: hi The code below does almost what I want but not quite! It outputs...parseInt 12444a gives... [(EInt 1,2444a),(EInt 2,444a),(EInt 4,44a),(EInt 4,4a),(EInt 4,a)] What I want is: [(EInt 12444, a)] data Expr = EInt {vInt :: Int} -- integer values | EBool {vBool :: Bool} -- boolean values parseInt :: Parser parseInt (x:xs) | (isDigit x xs /= []) = [(EInt (read [x]),xs)] ++ parseInt xs | isDigit x xs == [] = [(EInt (read [x]),[])] | otherwise = [] Thanks Ryan -- Get closer to the jungle. I'm a Celebrity Get Me Out Of Here!http://entertainment.uk.msn.com/tv/realitytv/im-a-celebrity/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] annoying output
I mean powers of *ten* :) On Dec 8, 2007 10:48 PM, Philip Weaver [EMAIL PROTECTED] wrote: Well, you're choosing to parse each digit of your integer as a separate integer, so if you want to combine them after reading you'll need to multiply by powers of two. Or, you can just read in all the digits in one 'read' command, like this: parseInt :: String - (Expr, String) parseInt xs = let (digits, rest) = span isDigit in (EInt (read digits), rest) where 'span' is defined in the Prelude. Hope this helps! - Phil On Dec 8, 2007 10:03 PM, Ryan Bloor [EMAIL PROTECTED] wrote: hi The code below does almost what I want but not quite! It outputs...parseInt 12444a gives... [(EInt 1,2444a),(EInt 2,444a),(EInt 4,44a),(EInt 4,4a),(EInt 4,a)] What I want is: [(EInt 12444, a)] data Expr = EInt {vInt :: Int} -- integer values | EBool {vBool :: Bool} -- boolean values parseInt :: Parser parseInt (x:xs) | (isDigit x xs /= []) = [(EInt (read [x]),xs)] ++ parseInt xs | isDigit x xs == [] = [(EInt (read [x]),[])] | otherwise = [] Thanks Ryan -- Get closer to the jungle. I'm a Celebrity Get Me Out Of Here!http://entertainment.uk.msn.com/tv/realitytv/im-a-celebrity/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe