Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: type classes and multiple implementations (Chadda? Fouch?) 2. timer_create: Invalid argument (Thomas Friedrich) 3. Re: timer_create: Invalid argument (Daniel Fischer) 4. Re: timer_create: Invalid argument (Maur??cio) 5. Re: Re: timer_create: Invalid argument (Thomas Friedrich) 6. Re: timer_create: Invalid argument (Maur??cio) 7. exercise 3.10 in YAHT (George Huber) 8. Re: exercise 3.10 in YAHT (Fernando Henrique Sanches) ---------------------------------------------------------------------- Message: 1 Date: Sat, 6 Jun 2009 18:00:50 +0200 From: Chadda? Fouch? <chaddai.fou...@gmail.com> Subject: Re: [Haskell-beginners] type classes and multiple implementations To: Sean Bartell <wingedtachik...@gmail.com> Cc: beginners@haskell.org Message-ID: <e9350eaf0906060900l713faeabl47c8ef38d7e16...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Fri, Jun 5, 2009 at 7:09 PM, Sean Bartell<wingedtachik...@gmail.com> wrote: >   by_type :: Storage a => String -> String -> IO a > This function must, for any Storage type, take any two strings and produce > an IO value of that type. (by_type "disk" "xyz" :: Memory must be valid.) It > doesn't really have the option of choosing which instance of Storage to use. > > In pure Haskell, you would probably have to do something like >  type Storage = Disk Handle | Memory String >  by_type :: String -> String -> Storage > That way, by_type can return any Storage it wants. > > I'm sure there are also ways to do what you want with extensions. I think the point is to be able to extend the storage methods in another module ? If not, Sean's solution is what you want. If you want to use the type class to allow anyone to add a new method in his own module, you can use existential type, like : > data Store = forall a . Storage a => Store a and then your byType : > byType "disk" x = Store (open x :: Disk) > byType "memory" x = Store (open x :: Memory) See XMonad and its Layout type for an example of this method. -- Jedaï ------------------------------ Message: 2 Date: Mon, 08 Jun 2009 10:35:22 -0400 From: Thomas Friedrich <i...@suud.de> Subject: [Haskell-beginners] timer_create: Invalid argument To: beginners <beginners@haskell.org> Message-ID: <4a2d21aa.2090...@suud.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi, I need to check if a couple of files have the same number of lines in them. So, I written a little Haskell program that counts the number of lines in a file. import System.Environment (getArgs) main :: IO () main = do [f] <- getArgs cs <- readFile f print $ length (lines cs) Now, when I invoke the program on my computer, it does what it should do: ~ $ ./count count.hs 7 However, when I run the program on a different computer, I get the following: ~ $ scp count count.hs thom...@...:~ tho...@...'s password: count 100% 492KB 492.2KB/s 00:00 count.hs 100% 125 0.1KB/s 00:00 ~ $ ssh tho...@... [tho...@... ~] $ ./count count.hs count: timer_create: Invalid argument [tho...@... ~]$ What does this error message mean? And why does it occur? Other programs that I written and compiled on my computer worked just fine on the other. I run Arch Linux and I am using GHC 6.10.3, the other computer is a RedHat 3. Cheers, Thomas ------------------------------ Message: 3 Date: Mon, 8 Jun 2009 17:17:33 +0200 From: Daniel Fischer <daniel.is.fisc...@web.de> Subject: Re: [Haskell-beginners] timer_create: Invalid argument To: beginners@haskell.org Message-ID: <200906081717.33765.daniel.is.fisc...@web.de> Content-Type: text/plain; charset="iso-8859-1" Am Montag 08 Juni 2009 16:35:22 schrieb Thomas Friedrich: > Hi, > > [tho...@... ~] $ ./count count.hs > count: timer_create: Invalid argument > [tho...@... ~]$ > > What does this error message mean? And why does it occur? Other > programs that I written and compiled on my computer worked just fine on > the other. I run Arch Linux and I am using GHC 6.10.3, the other > computer is a RedHat 3. Do other Haskell programmes compiled with ghc-6.10.3 on Arch run on Red Hat 3? I think the timer_create is called during initialisation of the run-time, for +RTS -sstderr and such, probably RH3 has an older timer_create which doesn't like the passed argument. Then no ghc-compiled programme from Arch should run on RH3, nor should C programmes using timer_create with like arguments. > > Cheers, > Thomas > ------------------------------ Message: 4 Date: Mon, 08 Jun 2009 12:26:48 -0300 From: Maur??cio <briqueabra...@yahoo.com> Subject: [Haskell-beginners] Re: timer_create: Invalid argument To: beginners@haskell.org Message-ID: <h0jajo$u2...@ger.gmane.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed > Now, when I invoke the program on my computer, it does what it should do: > (...) > However, when I run the program on a different computer, I get the > following: (...) > [tho...@... ~] $ ./count count.hs > count: timer_create: Invalid argument I don't know where time_create is exactly used here, however, it seems like a linking problem. Have you tried rebuilding your program in the remote machine? Actually, the fact that other programs did succeed seems strange to me. You could show some program that did work on both machines if you want to know why it actually worked. If you don't want to rebuild, why not to use it as a script? You can do it by just adding this first line to your file: #!/usr/bin/runhaskell and allowing it to be used as a script: chmod a+x count.hs I usually add such scripts to ~/bin so I can run then anywhere (but check if your distribution do add ~/bin to path). Maurício ------------------------------ Message: 5 Date: Mon, 08 Jun 2009 13:46:56 -0400 From: Thomas Friedrich <i...@suud.de> Subject: Re: [Haskell-beginners] Re: timer_create: Invalid argument Cc: beginners <beginners@haskell.org> Message-ID: <4a2d4e90.8050...@suud.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi Mauricio, yes it is a linking problem. When I compile the program on my computer with ghc --make A.hs -threaded the program will run on the Red Hat 3. If I compile it with ghc --make A.hs it won't. I don't know why though, and I don't think this is an expected behavior. Daniel suggested to file a bug report on this. I've never done that before. Where would I do this? Is there something I should know about filing a bug? I cannot compile the program on the Red Hat machine, as GHC is not installed there and I only have user rights. Cheers, Thomas Maurício wrote: >> Now, when I invoke the program on my computer, it does what it should >> do: > > (...) >> However, when I run the program on a different computer, I get the >> following: (...) >> [tho...@... ~] $ ./count count.hs >> count: timer_create: Invalid argument > > I don't know where time_create is exactly used here, however, > it seems like a linking problem. Have you tried rebuilding your > program in the remote machine? Actually, the fact that other > programs did succeed seems strange to me. You could show some > program that did work on both machines if you want to know why > it actually worked. > > If you don't want to rebuild, why not to use it as a script? You > can do it by just adding this first line to your file: > > #!/usr/bin/runhaskell > > and allowing it to be used as a script: > > chmod a+x count.hs > > I usually add such scripts to ~/bin so I can run then anywhere > (but check if your distribution do add ~/bin to path). > > Maurício > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners ------------------------------ Message: 6 Date: Mon, 08 Jun 2009 15:25:41 -0300 From: Maur??cio <briqueabra...@yahoo.com> Subject: [Haskell-beginners] Re: timer_create: Invalid argument To: beginners@haskell.org Message-ID: <h0jl36$31...@ger.gmane.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed It seems it's a know question: http://thread.gmane.org/gmane.comp.lang.haskell.cafe/49337 One of the problems discussed in that thread is the timer_create issue, but it seems upgrading is the sugested solution. Did Daniel mean to open a bug report on Red Hat or GHC? If you ever want to report a bug on GHC: http://haskell.org/ghc The ReportABug link do have nice instructions. But maybe this is worth discussing in haskell-cafe first, so I posted a message there: http://thread.gmane.org/gmane.comp.lang.haskell.cafe/59643 Best, Maurício > Hi Mauricio, > > yes it is a linking problem. When I compile the program on my computer > with > > ghc --make A.hs -threaded > > the program will run on the Red Hat 3. If I compile it with > > ghc --make A.hs > > it won't. I don't know why though, and I don't think this is an > expected behavior. Daniel suggested to file a bug report on this. I've > never done that before. Where would I do this? Is there something I > should know about filing a bug? > > I cannot compile the program on the Red Hat machine, as GHC is not > installed there and I only have user rights. > > Cheers, > Thomas > > > > > Maurício wrote: >>> Now, when I invoke the program on my computer, it does what it should >>> do: >> > (...) >>> However, when I run the program on a different computer, I get the >>> following: (...) >>> [tho...@... ~] $ ./count count.hs >>> count: timer_create: Invalid argument >> >> I don't know where time_create is exactly used here, however, >> it seems like a linking problem. Have you tried rebuilding your >> program in the remote machine? Actually, the fact that other >> programs did succeed seems strange to me. You could show some >> program that did work on both machines if you want to know why >> it actually worked. >> >> If you don't want to rebuild, why not to use it as a script? You >> can do it by just adding this first line to your file: >> >> #!/usr/bin/runhaskell >> >> and allowing it to be used as a script: >> >> chmod a+x count.hs >> >> I usually add such scripts to ~/bin so I can run then anywhere >> (but check if your distribution do add ~/bin to path). >> >> Maurício >> >> _______________________________________________ >> Beginners mailing list >> Beginners@haskell.org >> http://www.haskell.org/mailman/listinfo/beginners ------------------------------ Message: 7 Date: Tue, 09 Jun 2009 00:05:21 -0400 From: George Huber <geohu...@verizon.net> Subject: [Haskell-beginners] exercise 3.10 in YAHT To: beginn...@haskell.org. Message-ID: <4a2ddf81.9060...@verizon.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed I'm currently working through "Yet Another Haskell Tutorial" by H. Daume and have a question on how to proceed with his exercise 3.10. The exercise question is: Write a program that will repeatedly ask the user for numbers until he types in zero, at which point it will tell him the sum of all the numbers, the product of all the numbers, and, for each number, its factorial. The hint that is given is to write an IO action that reads a number and either returns an empty list (if the number is zero) or recurses itself making a list from the number and the result of the recursive call. Daume presents and example of such a function: askForWords = do putStrLn "Please enter a word:" word <- getLine if word == "" then return [] else do rest <- askForWords return (word : rest) so, based on his example I created the function: getNums = do putStrLn "Enter a number (zero to stop):"; strNum <- getLine let num = read strNum if num == 0 then return [] else do rest <- getNums return (num:rest) loading the file that contains the above function into GHCi (version 6.8.3) gives the following error "The last statement in a 'do' construct must be an expression" being a beginner, I'm at a loss at the cause of the error and how to fix it -- any suggestions? thanks, george ------------------------------ Message: 8 Date: Tue, 9 Jun 2009 01:27:32 -0300 From: Fernando Henrique Sanches <fernandohsanc...@gmail.com> Subject: Re: [Haskell-beginners] exercise 3.10 in YAHT To: George Huber <geohu...@verizon.net> Cc: beginners@haskell.org Message-ID: <174c72ef0906082127l2b9c9bbbkceb73a246c8d1...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" It compiles fine here with GHC 6.8.2: *Main> getNums Enter a number (zero to stop): 4 Enter a number (zero to stop): 3 Enter a number (zero to stop): 0 [4,3] Are you sure the problem is in this function? Fernando Henrique Sanches On Tue, Jun 9, 2009 at 1:05 AM, George Huber <geohu...@verizon.net> wrote: > I'm currently working through "Yet Another Haskell Tutorial" by H. Daume > and have a question on how to proceed with his exercise 3.10. > > The exercise question is: Write a program that will repeatedly ask the > user for numbers until he types in zero, at which point it will tell him the > sum of all the numbers, the product of all the numbers, and, for each > number, its factorial. > > The hint that is given is to write an IO action that reads a number and > either returns an empty list (if the number is zero) or recurses itself > making a list from the number and the result of the recursive call. > > Daume presents and example of such a function: > > askForWords = do > putStrLn "Please enter a word:" > word <- getLine > if word == "" > then return [] > else do > rest <- askForWords > return (word : rest) > > so, based on his example I created the function: > > getNums = do > putStrLn "Enter a number (zero to stop):"; > strNum <- getLine > let num = read strNum > if num == 0 > then return [] > else do > rest <- getNums > return (num:rest) > > loading the file that contains the above function into GHCi (version 6.8.3) > gives the following error "The last statement in a 'do' construct must be an > expression" > > being a beginner, I'm at a loss at the cause of the error and how to fix it > -- any suggestions? > > thanks, > george > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090609/d8b741a9/attachment.html ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 12, Issue 4 ****************************************