Re: [Haskell-cafe] Can't cabal install readline
On Fri, Dec 5, 2008 at 2:08 PM, Judah Jacobson [EMAIL PROTECTED]wrote: On Fri, Dec 5, 2008 at 1:10 PM, Martijn van Steenbergen [EMAIL PROTECTED] wrote: Hello, This week I upgraded to GHC 6.10 using the .pkg installer. It installed without a single hiccup -- thanks! I've noticed two odd things: the standard library haddock that comes with the installer doesn't have links to the hs-coloured sources anymore (and neither does the online documentation); I miss that a lot. I also can't Ctrl+R anymore in GHCi to search my command history. But I can learn to live without those. The following instructions should re-enable Ctrl-R: http://mult.ifario.us/p/editrc-tidbit-for-ghci Another minor inconvenience is that the packages I had installed (using cabal) are no longer available to GHC -- I think I will have to reinstall them. But I cannot continue working on my Yogurt project anymore, because it depends on readline, which fails to build: snip checking for rl_readline_version... yes checking for rl_begin_undo_group... no configure: error: readline not found, so this package cannot be built See `config.log' for more details. cabal: Error: some packages failed to install: Yogurt-0.2 depends on readline-1.0.1.0 which failed to install. readline-1.0.1.0 failed during the configure step. The exception was: exit: ExitFailure 1 The above happens because GHC is using the OS X default installation of libreadline.a which is actually a link to libedit that doesn't implement the full readline API. If you already have the MacPorts readline, you just need to tell cabal where it is, with (for example) cabal install readline --extra-include-dirs=/opt/local/include --extra-lib-dirs=/opt/local/lib If you'd like, you can add /opt/local/include to your shell's INCLUDE_PATH and/or C_INCLUDE_PATH environment variables and /opt/local/lib to your LIBRARY_PATH and/or LD_LIBRARY_PATH variables. I say and/or because I don't know which one is actually necessary, but if you add it to both you'll be safe. - Phil -Judah ___ 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] TimeDiff to Int?
2008/11/12 Lyle Kopnicky [EMAIL PROTECTED] Hi folks, I had some code using the oldtime package, and want to convert it to use the time package. One of the things I need to do is calculate the number of seconds since midnight. The easy part is getting a TimeDiff result: utc - getCurrentTime tz - getCurrentTimeZone let td = timeOfDayToTime $ localTimeOfDay $ utcToLocalTime tz utc Now td is a TimeDiff representation of the number of seconds since midnight. It prints nicely, but I'm having a heck of a time figuring out how to truncate it to an Int. The floor function is only supported by the RealFrac class. Although TimeDiff has an instance of RealFrac and Fractional, it doesn't have an instance of RealFrac. I looked up the various to* and from* functions and have come up short. fromEnum yields an Int but it's the wrong value. I know I could use show and then use readS to get an Integer, or use formatTime (and reparse that), but that's a hack. I can convert it to a TimeOfDay which gives me hours, minutes, and seconds, but then I have to do arithmetic on it, and the seconds are of type Pico, which I can't call floor on either. I can convert it to a Rational via timeOfDayToDayFraction, but a TimeDiff is already a Rational those don't have floor. What am I missing? There has got to be an easy way to count seconds! Well, you could always (read . takeWhile (not . (=='.')) . show), but here's a better way: let x = toRational td in numerator x `div` denominator x This was just the first thing I could come up with. I bet there's a nicer way. - Phil Thanks, Lyle ___ 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] Temlpate Haskell: [d| ... |]
On Fri, Oct 17, 2008 at 9:26 AM, Achim Schneider [EMAIL PROTECTED] wrote: [d| ... |], where the ... is a list of top-level declarations; the quotation has type Q [Dec]. ( http://www.haskell.org/ghc/docs/latest/html/users_guide/template-haskell.html ) Can someone elaborate on what a list means here? Neither declarations = [d| foo = bar bar = foo |] nor declarations = [d| [ foo = bar , bar = foo ] |] work. I'm trying to automatically generate a bunch of functions out of an xml file. Works for me. Note that -fth is needed. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited. ___ 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] How to check if two Haskell files are the same?
On Tue, Sep 16, 2008 at 7:30 AM, Mauricio [EMAIL PROTECTED] wrote: Hi, I would like to write a Haskell pretty-printer, using standard libraries for that. How can I check if the original and the pretty-printed versions are the same? For instance, is there a file generated by GHC at the compilation pipe that is always guaranteed to have the same MD5 hash when it comes from equivalent source? I don't know, but you can parse the resulting concrete syntax and compare the original abstract syntax to the new abstract syntax. Thanks, Maurício ___ 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] What monad am I in?
On Tue, Sep 2, 2008 at 5:33 PM, Ryan Ingram [EMAIL PROTECTED] wrote: ghci has some crazy defaulting rules for expressions at the top level. In particular, it tries to unify those expressions with a few different types, including IO. On the other hand, the let-expression is typed like regular Haskell and you run into the monomorphism restriction. Right. Just to make it clear for the original poster, this monomorphism restriction is not about GHCi specifically, just GHC in general. With the -fno-monomorphism-restriction, you will not get this error. -- ryan On Tue, Sep 2, 2008 at 1:25 PM, Henry Laxen [EMAIL PROTECTED] wrote: Dear Group, When I fire up ghci and define: increment x = return (x+1) I can say: Main increment 1 and ghci dutifully replies 2. Also as expected, the type signature of increment is: (Num a, Monad m) = a - m a However, if I say: Main let a = increment 1 I get: interactive:1:8: Ambiguous type variable `m' in the constraint: `Monad m' arising from a use of `increment' at interactive:1:8-18 Probable fix: add a type signature that fixes these type variable(s) Have I, like Monsier Jourdain, been running in the IO monad all my life, and didn't even know it? Thanks, Henry Laxen ___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Syntax of 'do'
On Fri, Aug 29, 2008 at 6:41 AM, Maurício [EMAIL PROTECTED] wrote: Hi, http://haskell.org/haskellwiki/Keywords says that: - [do is a] syntactic sugar for use with monadic expressions. For example: do { x ; result - y ; foo result } is shorthand for: x y = \result - foo result - I did some tests hiding Prelude. and Prelude.= and applying and = to non-monadic types, and saw that 'do' would not apply to them. So, I would like to add the following to that text: It sounds like you tried to redefine () and (=) and make 'do' use the new definitions. This is not possible, regardless of what types you give () and (=). If you want to define () and (=), do so for a particular instance of Monad. - as long as proper types apply: x :: Prelude.Monad a y :: Prelude.Monad b foo :: b - Prelude.Monad c - Is that correct (Haskell and English)? Thanks, Maurício ___ 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] Syntax of 'do'
On Fri, Aug 29, 2008 at 8:50 AM, David House [EMAIL PROTECTED] wrote: 2008/8/29 Philip Weaver [EMAIL PROTECTED]: It sounds like you tried to redefine () and (=) and make 'do' use the new definitions. This is not possible, regardless of what types you give () and (=). Watch out for rebindable syntax: http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#rebindable-syntax Oh, I had no idea! Thanks :). At first reading, I thought that -XNoImplicitPrelude was required to turn this on. But now I'm not sure: it seems that if you hide Prelude.= and Prelude.return, that ought to be enough to make do notation work with your alternative definitions. I'm not at home, so I can't try this right now. -- -David ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Named field syntax
On Fri, Aug 29, 2008 at 1:59 PM, Roman Cheplyaka [EMAIL PROTECTED] wrote: * Johannes Waldmann [EMAIL PROTECTED] [2008-08-29 15:39:15+0200] data Test = Test Integer {b::String} positional (= unnamed) record notation is a language design error :-) and its use should be discouraged. - J.W. Polluting namespace with unneeded functions should not be encouraged either. Consider for instance defining datatype for 3x3 matrix. Would the absence of unnamed record notation make you more happy? Also, if positional record notation is a design error, then is it also a design error not to require all arguments to be explicitly associated with named formal parameters at a function call site (e.g. f(x = 1, y = 2, z = 3))? -- Roman I. Cheplyaka :: http://ro-che.info/ kzm: My program contains a bug. How ungrateful, after all I've done for it. ___ 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] best runProcess solution to work with windows and linux
On Wed, Aug 27, 2008 at 5:40 AM, Andrew U. Frank [EMAIL PROTECTED] wrote: i use System.POSIX.IO to run a process and access the handles (after due transformation) to get the values back. this solution is unfortunately not portable and works only on unix (or cygwin) but not for plain windows. there seems to be a somewhat comparable package in system.win32.process. is there a solution independent of OS? what is the best approach to use to run a process and read the result back which works in both unix and windows? The System.Process module works well on both unix and windows: http://hackage.haskell.org/packages/archive/process/1.0.0.0/doc/html/System-Process.html any suggestion highly appreciated! andrew ___ 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] Cabal and Strings and CPP
On Tue, Jul 29, 2008 at 3:14 AM, Malcolm Wallace [EMAIL PROTECTED] wrote: Philip Weaver [EMAIL PROTECTED] wrote: I'm trying to use CPP-defined strings in a Haskell module, like this: main :: IO () main = putStrLn FOO This of course will not work: ghc -DFOO=hello world --make Main.hs -o test Have you tried using ANSI cpp's stringification operator? {-# LANGUAGE CPP #-} #define STRING(bar) #bar main :: IO () main = putStrLn FOO ghc -DFOO=STRING(hello world) --make Main.hs -o test Yes, I have. It does not seem to be supported. Regards, Malcolm ___ 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] Cabal and Strings and CPP
Hello all, I'm trying to use CPP-defined strings in a Haskell module, like this: main :: IO () main = putStrLn FOO This of course will not work: ghc -DFOO=hello world --make Main.hs -o test You'll get this error message: ./Main.hs:6:16: Not in scope: `hello' ./Main.hs:6:22: Not in scope: `world' Either of these will do what I want: ghc -DFOO=\hello world\ --make Main.hs -o test ghc -DFOO='hello world' --make Main.hs -o test # (that's double quotes inside single quotes) However, passing the same CPP definition via cabal does not work. runhaskell Setup.hs build --ghc-options=-DFOO=\hello world\ runhaskell Setup.hs build --ghc-options=-DFOO='hello world' With either of these commands, I get the same error message as above. This is understandable, since cabal has to evaluate the string before sending it to GHC, so I lose my escaped quotes. Any idea how I could change the Haskell module or the command line argument so that I get what I want? I've tried many combinations of quotes and escaped quotes with no luck. Thanks, - Phil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FPGA / Lava and haskell
On Wed, Jul 9, 2008 at 2:22 AM, Marc Weber [EMAIL PROTECTED] wrote: You're going to design something like that with an FPGA in it? :) The FPGA is only used for developement. If everything works fine I'd like to put it on the market. My hope is to get one low cost chip doing everything this way. Would you suggest using other tools? Ah, yes, it is common to develop on an FPGA before fabricating to, say, on ASIC . I'm still a total noob in this area So you plan on developing a chip or board without any previous hardware experience? Sounds challenging :). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FPGA / Lava and haskell
On Tue, Jul 8, 2008 at 5:43 PM, Marc Weber [EMAIL PROTECTED] wrote: Is Haskell still used (in industry as well ?) to write (V)HDL code to program FPGAs and create circuits on chips? Indeed! Galois maintains a language called Cryptol. Almost all tools for this language, including an FPGA compiler that produces HDL, are written in Haskell. It is not open source, nor is it free as in beer, but there is a free academic version without FPGA support. The Chalmers Lava homepage tells abouta Xilinx version which should be merged in soon. But on the xilinx homepage there was no reference to neither Lava nor haskell.. As for Lava and the Xilinx version, I am not really sure how actively it is being developed. Perhaps someone else here knows? I'm thinking about designing a similar tool to www.combimouse.com. You're going to design something like that with an FPGA in it? :) For a simple enough design, it can be useful to write specs in Haskell and then translate them to HDL by hand. I believe someone on this list had a particularly successful experience doing that :). - Philip Sincerly Marc ___ 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] GHCi gives type signature that won't compile.
On Thu, Jun 5, 2008 at 9:36 AM, Miguel Mitrofanov [EMAIL PROTECTED] wrote: Check your types for typos. On 5 Jun 2008, at 20:31, A A wrote: Hi All I can successfully compile the following code using ghci import Data.Array.IArray makeArray (lower, upper) f = listArray (lower, upper) [(f i) | i - [lower..upper] tridiagonal_solve (a, b, c, d, (lower, upper)) = x where gen_array f = (makeArray (lower, upper) f) x = gen_array x_f where x_f i | i == upper = (d_dash ! upper) | otherwise = (d_dash ! i) - (c_dash ! i) * (x ! (i + 1)) d_dash = gen_array d_dash_f where d_dash_f i | i == lower = (d ! lower) / (b ! lower) | otherwise= ((d ! i) - (d_dash ! (i - 1)) * (a ! i)) / ((b ! i) - (c_dash ! (i - 1)) * (a ! i)) c_dash = gen_array c_dash_f where c_dash_f i | i == lower= (c ! lower) / (b ! lower) | otherwise = (c ! i) / ((b ! i) - (c_dash ! (i - 1)) * (a ! i)) I then attempted to write a type signature for tridiagonal_solve. I didn't succeed at this however, all of my type signatures gave compile errors when attempting to load them in ghci. I asked in the #haskell channel, and they suggested that I try the type signature from ghci :type function. So I removed any type signatures, and reloaded the file in ghci, and typed :type tridiagonal_solve which produced the following output: tridiagonal_solve :: (IArray a3 e, IArray a6 e, IArray a7 e, Fractional e, Ix a, Num a, IArray a4 e, IArray a2 e, IArray a5 e, IArray a1 e, Enum a) = (a4 a e, a2 a e, a1 a e, a5 a e, (a, a)) - a7 a e I then attempted to paste this into my code, the resulting code looking like this: import Data.Array.IArray makeArray (lower, upper) f = listArray (lower, upper) [(f i) | i - [lower..upper]] tridiagonal_solve :: (IArray a3 e, IArray a6 e, IArray a7 e, Fractional e, Ix a, Num a, IArray a4 e, IArray a2 e, IArray a5 e, IArray a1 e, Enum a) = (a4 a e, a2 a e, a1 a e, a5 a e, (a, a)) - a7 a e tridiagonal_solve (a, b, c, d, (lower, upper)) = x where gen_array f = (makeArray (lower, upper) f) x = gen_array x_f where x_f i | i == upper = (d_dash ! upper) | otherwise= (d_dash ! i) - (c_dash ! i) * (x ! (i + 1)) d_dash = gen_array d_dash_f where d_dash_f i | i == lower = (d ! lower) / (b ! lower) | otherwise= ((d ! i) - (d_dash ! (i - 1)) * (a ! i)) / ((b ! i) - (c_dash ! (i - 1)) * (a ! i)) c_dash = gen_array c_dash_f where c_dash_f i | i == lower= (c ! lower) / (b ! lower) | otherwise = (c ! i) / ((b ! i) - (c_dash ! (i - 1)) * (a ! i)) When I attempt to load this into ghci, I recieve the following error: [1 of 1] Compiling Main ( main.lhs, interpreted ) main.lhs:29:11: Could not deduce (IArray a1 e) from the context (IArray a3 e, IArray a6 e, IArray a7 e, Fractional e, Ix a2, Num a2, IArray a4 e, IArray a21 e, IArray a5 e, IArray a11 e, Enum a2) arising from a use of `gen_array' at main.lhs:29:11-28 Possible fix: add (IArray a1 e) to the context of the type signature for `tridiagonal_solve' In the expression: gen_array d_dash_f In the definition of `d_dash': d_dash = gen_array d_dash_f where d_dash_f i | i == lower = (d ! lower) / (b ! lower) | otherwise = ((d ! i) - (d_dash ! (i - 1)) * (a ! i)) / ((b ! i) - (c_dash ! (i - 1)) * (a ! i)) In the definition of `tridiagonal_solve': tridiagonal_solve (a, b, c, d, (lower, upper)) = x where
Re: [Haskell-cafe] A simple beginner question
On Tue, Jun 3, 2008 at 5:11 PM, Adam Smyczek [EMAIL PROTECTED] wrote: Example: data SampleType = A | B Int | C String | D -- etc. sampleTypes = [A, B 5, C test] :: [SampleType] How do I find for example element A in the sampleTypes list? Do I have to create e.g.: isA :: SampleType - Bool isA A = True isA _ = False for every constructor and use find? isA is already defined for every constructor, so all you have to do is find isA It feels like this is not the quicker method. Thanks, Adam ___ 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] [Newbie question] -- Looping stdin until condition is met
On Fri, May 30, 2008 at 5:28 PM, Martin Blais [EMAIL PROTECTED] wrote: Allright, this is a definitely a newbie question. I'm learning Haskell and going through the exercises in the beautiful Hutton book, and one of them requires for me to write a loop that queries a line from the user (stdin), looping until the user enters a valid integer (at least that's how I want to implement the interface to the exercise). I have tried tons of variants and modifications of code, and I can't find the way to implement this. Here is what my emacs buffer is at now:: import Text.Read import System.IO import qualified Control.Exception as C getNum :: IO Int getNum = do line - (hGetLine stdin) x - (C.catch (do return (read line :: Int)) (\e - getNum)) return x main = do x - getNum putStr ((show x) ++ \n) Now, I've tried the Prelude's catch, the Control.Exception catch, I've tried moving it at the top of getnum, I've tried without catch, I've tried a ton of other shtuff, so much that I'm starting to think that Emacs is going to run out of electrons soon. I asked some half-newbie friends who are insanely enthousiastic about Haskell and they can't do it either (I'm starting to think that those enthousiastic friends are dating a beautiful girl with 3 PhDs, but she has a 2-inch thick green and gooey wart smack on her nose and they're so blindly in love that they can't admit that she does). I've asked some university profs and they sidetrack my question by saying I shouldn't do I/O so early. Can anyone here restore my faith in the Haskell section of humanity? 1. How do I catch the exception that is raised from read? I think you want readIO, which yields a computation in the IO monad, so it can be caught. 2. Where do I find the appropriate information I need in order to fix this? I'm probably just not searching in the right place. (Yes, I've seen the GHC docs, and it doesn't help, maybe I'm missing some background info.) In this particular case, I am not sure where you'd find this information. It's not very intuitive to a beginner why read doesn't work in this case. 3. Please do not tell me I should solve the problem differently. Here is the problem I'm trying to solve, and nothing else: Write a program that reads a line from the user, looping the query until the line contains a valid integer. It shouldn't be too hard i think. The best answer would be a two-liner code example that'll make me feel even more stupid than I already do. Thanks in advance. ___ 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] [Newbie question] -- Looping stdin until condition is met
On Fri, May 30, 2008 at 5:14 PM, Martin Blais [EMAIL PROTECTED] wrote: On Fri, 30 May 2008 16:54:18 -0700, Philip Weaver [EMAIL PROTECTED] said: 1. How do I catch the exception that is raised from read? I think you want readIO, which yields a computation in the IO monad, so it can be caught. Holy schmoly, there it is, words of wisdom, written as clearly as can be, from the docs: The readIO function is similar to read except that it signals parse failure to the IO monad instead of terminating the program. I'll be prosternating on the floor towards my web browser for the next four hours. Thank you very much Philip. (And thank you Don for the verbose examples.) 2. Where do I find the appropriate information I need in order to fix this? I'm probably just not searching in the right place. (Yes, I've seen the GHC docs, and it doesn't help, maybe I'm missing some background info.) In this particular case, I am not sure where you'd find this information. It's not very intuitive to a beginner why read doesn't work in this case. Dear Philip, could you point your virtual finger towards a reference/paper/book/any-bleeping-thing that would help this simple beginner understand why it doesn't work in this case? I'm trying to picture why a read function that terminates the program would be useful anywhere. In fact, any library function other than something like UNIX's exit or kill which terminates my program is not really welcome in any of my computer programs, but then again, I haven't yet been illuminated by the genie of pure functional languages. A reference would be awesome. Sorry, I wouldn't know where to point you, other than stating the simple rule that you can't catch exceptions in pure code. Others may be able to enlighten you better. By the way, the example that Dons gave may look more verbose, but (when possible) it's a probably a better idea to capture failure in a Maybe than in IO. I gave you readIO because it fit in to the exception handling that you were trying to do, and because you said you didn't want anyone to tell you you were doing things wrong :). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] An alternative break
On Wed, May 28, 2008 at 2:53 PM, Pieter Laeremans [EMAIL PROTECTED] wrote: Hello, I need a break function that splits the list one element further than the ordinary break. This is the simplest solution I could imagine: breakI :: (a - Bool) - [a] - ([a], [a]) breakI p s = case break p s of ([], []) - ([], []) (x, []) - (x, []) (x, l) - (x ++ [head l], tail l ) Is there a better way to write this ? Your first two cases are redundant; you can eliminate the first one. Other than that, it looks fine. thanks in advance, Pieter -- Pieter Laeremans [EMAIL PROTECTED] ___ 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] runInteractiveCommand: program ends before writing or reading all the output
2008/5/15 Olivier Boudry [EMAIL PROTECTED]: Hi all, It's the first time I use the runInteractiveCommand and I was probably bitten by laziness. When I run the following program and send its output to a file using '' redirection I get the full output of the called process. But if I run it in the console I get only half of the output. As console is slower than disk I assume the called process terminates before all data has been read from it or the main process terminates before data has been written to stdout. I thought using waitForProcess, closing called process output and flushing stdout would solve the problem but it doesn't. -- Compile with -threaded option module Main where import Control.Concurrent (forkIO) import System.Environment (getArgs) import System.FilePath (dropExtension, takeFileName) import System.IO (Handle, hClose, hFlush, hGetContents, stdout) import System.Process (runInteractiveCommand, waitForProcess) main :: IO () main = do (file:_) - getArgs (_, out, _, pid) - runInteractiveCommand $ dumpbin /EXPORTS ++ file forkIO (createDefFile file out) waitForProcess pid hClose out hFlush stdout createDefFile :: String - Handle - IO () createDefFile file inp = do putStrLn $ LIBRARY ++ (dropExtension . takeFileName) file ++ .dll putStrLn EXPORTS text - hGetContents inp mapM_ writeExport $ keepExports $ map words $ lines text where keepExports :: [[String]] - [String] keepExports = map head . filter (not . null) . takeWhile ([Summary]/=) . drop 1 . dropWhile ([ordinal,name]/=) writeExport ('_':xs) = putStrLn xs writeExport xs = putStrLn xs Any idea regarding the cause of this problem? I think I've encountered the same problem several times, and it was because I was reading from the handle lazily, like this: (_, out, _, pid) - runInteractiveProcess ... str - hGetContents out waitForProcess pid But I didn't use 'str' until after the process finishes. My solution was to use strict IO, usually by replacing String with a strict ByteString. I hear there is now a library that lets you do strict IO with Strings Hope this helps. Thanks, Olivier. ___ 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] runInteractiveCommand: program ends before writing or reading all the output
On Thu, May 15, 2008 at 11:42 AM, Ronald Guida [EMAIL PROTECTED] wrote: It looks like a simple race condition to me. You are using waitForProcess pid to wait for runInteractiveCommand to finish, but you don't seem to have anything that waits for createDefFile to finish. Whoops, sorry, I didn't read the original post closely enough. main :: IO () main = do (file:_) - getArgs (_, out, _, pid) - runInteractiveCommand $ dumpbin /EXPORTS ++ file forkIO (createDefFile file out) waitForProcess pid hClose out hFlush stdout ___ 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] build version problem?
Ok, I'll ask the obvious question... did you try to re-configure? runhaskell Setup.hs configure 2008/5/9 Galchin, Vasili [EMAIL PROTECTED]: Hello, I changed the version # in a cabal file and now I get ... runhaskell Setup.hs configure Configuring unix-2.4.0.0... [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0$ runhaskell Setup.hs build Setup.hs: unix.cabal has been changed, please re-configure. Now no matter what I change the version #, e.g. 2.3.0.0, things are not happy. ? Thanks, Vasili ___ 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] Maybe a, The Rationale
On Sat, May 10, 2008 at 3:10 PM, PR Stanley [EMAIL PROTECTED] wrote: Paul: Hi folks data Maybe a = Nothing | Just a What is the underlying rationale for the Maybe data type? is it the safe style of programming it encourages/ Something tells me this is going to start a lengthy discussion. :-) Bob: Pure and simple -- it allows you to represent partial functions. Looking up a map will only sometimes find a value, so we either return Nothing, or Just that value. Paul: Would yu like to demonstrate this in an example? Um, I was encountering and recognizing times when I really needed an out-of-band null, and the pain of representing such in C, shortly after I started serious programming in C (call it 1984-5). Is this really difficult? Paul: Hmm, I'm not quite sure what you're driving at. Me neither. Cheers, Paul ___ 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] asserting the type of a binding in a do expression
On Fri, Apr 25, 2008 at 11:49 PM, Brandon S. Allbery KF8NH [EMAIL PROTECTED] wrote: On Apr 26, 2008, at 2:36 , Ken Takusagawa wrote: But this does not: foo::IO a; foo = do{ (x::a) - bar; return x;}; Error message: A pattern type signature cannot bind scoped type variables `a' unless the pattern has a rigid type context. Yeah, using the forall is exactly what you want to fix this problem. It puts the type variable in scope throughout the definition of the function. This works for me (in a slightly out of date HEAD) if I explicitly forall the declaration as per the ghc manual (see section 8.7.6.3): bar :: forall b. IO b bar = return undefined -- just want a type for now foo :: forall a. IO a foo = do { (x :: a) - bar; return x; } -- 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cabalizing darcs
It looks quite clean (no funny business in Setup.lhs). I would favor using this cabalized version over the other. Thanks! So, autoconf/configure generate cryptol.buildinfo from cryptol.buildinfo.in. Did you change configure.ac much? And the Makefile is no longer needed at all, right? - Phil 2008/4/23 Gwern Branwen [EMAIL PROTECTED]: So recently I spent a bit of time working on a cabalization of Darcs. It works well for me, and is reasonably easy to apply (attached are three files; do a 'darcs get --lazy http://darcs.net' with Darcs-2 to get the latest, and copy the files into it, the usual autoconf, and it should then work as normal; if this doesn't work for you, I'd appreciate knowing). My question for y'all is: would you find an unofficial version of Darcs - one with the cabalization added and uploaded to Hackage - useful? Or would it just be frustrating and redundant and Not Good? (If yes, any suggestions for a package name? 'darcs' is out, but 'darcs-cb' and 'darcs-cabalized' strike me as horribly clunky or obscure.) -- gwern Threat WANK football Talent anarchy RIT interception Hutsul forschung ISS ___ 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] Cabalizing darcs
On Wed, Apr 23, 2008 at 4:49 PM, Gwern Branwen [EMAIL PROTECTED] wrote: On 2008.04.23 12:26:35 -0700, Philip Weaver [EMAIL PROTECTED] scribbled 1.2K characters: It looks quite clean (no funny business in Setup.lhs). I would favor using this cabalized version over the other. Thanks! So, autoconf/configure generate cryptol.buildinfo from cryptol.buildinfo.in. Did you change configure.ac much? I had to make a number of changes to configure.ac - the problem was that a lot of Darcs capabilities get modified through CPP; hence the darcs.buildinfo, to smuggle exported variables from the configure script to Cabal and to insert them in the correct fields. But not all of the necessary information was exported, so I had to fix that. Straightforward if you understand what you need. But there seems to be very little documentation on Cabal and buildinfos, so I had to do a bit of trial-and-error (Also, I dunno how you guys do Cryptol so can't speak to that.) Trial-and-error was my experience with buildinfo files, too. And the Makefile is no longer needed at all, right? - Phil Strictly speaking, the Darcs makefile does a lot of stuff besides just building and installing - it also generates various forms of documentation (Haddocks, the LaTeX manual for Darcs), run the tests, and do quite a bunch of miscellaneous stuff like support for some Windows installer and Debian package format. Some of this could no doubt be handled in a pure Cabal framework (ie. I understand Goerzen has a package which can automatically take a Cabal tarball and make a Debian source deb), but I was just aiming at the building part. If that's all you need (like most users), then the makefile isn't needed, yes. So do you feel like this process yielded an easier to maintain build system? -- gwern BLACKER Loin JAVA anthrax AG Zemin The Internet Sayeret 3P-HV ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ghc
2008/4/10 Cetin Sert [EMAIL PROTECTED]: Hi, Is GHC required to be installed on the target OS I compile Haskell binaries for in order for these binaries to run? I need a quick answer on that! If I parse your question correctly, the answer is no, you do not need GHC installed to run the binaries, only to compile them. By the way there is no computer in the 4 or so networks I have online access to on which ghc is not installed, which might be a sign people like haskell here in Heidelberg/Mannheim, Germany. Best Regards, Cetin Sert ___ 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] GHC + interactive input/output
Your gsi is buffered because there's no newline at the end. To flush the buffer and force it to be printed immediately, use 'hFlush' from the System.IO library, or use 'hSetBuffering' from that same library: http://haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html I believe you can observe the same behavior in C. - Phil On Feb 8, 2008 4:14 PM, Jonathan Cast [EMAIL PROTECTED] wrote: $ cat foo.c #include stdio.h int main() { char s[1024]; printf(gsi ); gets(s); printf(%s\n, s); return 0; } $ make foo cc gsi.c -o gsi $ ./foo warning: this program uses gets(), which is unsafe. gsi hello hello $ cat foo.hs main = do putStr gsi s - getLine putStrLn s $ ghc foo.hs -o foo $ ./foo hello gsi hello (This is on MacOS X). It strikes me that GHC is being extraordinarily unhelpful here. Is there anyone on the planet who ever actually wants this behavior? jcc ___ 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] Haskell purity and printing
On Dec 18, 2007 1:00 PM, Cristian Baboi [EMAIL PROTECTED] wrote: This is what I understand so far ... Suppose we have these two values: a) \x-x + x b) \x-2 * x Because these to values are equal, all functions definable in Haskell must preserve this. This is why I am not allowed to define a function like h :: (a-b) - (a-b) h x = x Of course you can define h. This is just a more specific (as far as types go) version of 'id', as defined in the Prelude: id :: a - a id x = x where 'a' can be any type, including a function such as (a - b). You can apply 'id' to either of your functions above, and get back an equivalent function, so each of the following evaluates to 20: let f = id (\x - x+x) in f 10 let f = id (\x - 2 * x) in f 10 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Questions about the Functor class and it's use in Data types à la carte
On Dec 14, 2007 11:44 AM, Corey O'Connor [EMAIL PROTECTED] wrote: I'm working through the interesting paper Data type à la carte and am confused by the Functor instance for Val. I think this stems from some confusion of mine regarding the Functor class in general. I'll try to explain, but I might not be very clear :). The Functor instance I'm confused about is: instance Functor Val where fmap f (Val x ) = Val x where Val is defined as: data Val e = Val Int Is this the only valid Functor instance for the Val type? Even though I'd, naively, expect the Functor instance to look like: instance Functor Val where fmap f (Val x) = Val (f x) Yes, I think people often expect this, because they're used to the idea that fmap applies a function to all the terminal elements in a data structure. For example, if you map a function across a list or tree, you expect the function to be applied to each value or node, not the branches themselves, and to preserve the structure of the tree or list. This is not the case when you use functors as you are in your email (I think sometimes called syntactic functors, for traversing abstract syntax trees); In this case, you are only pushing the function into all recursive subterms of a data structure, which the function then operates on. So, consider this data structure: data Val e = Add e e | Val Int instance Functor Val where fmap f (Val x) = Val x fmap f (Add x y) = Add (f x) (f y) Notice that it is not (fmap f x) and (fmap f y). You only push the function one level deeper, not all the way down (the catamorphism takes care of fmap-ing the function all the way down). I suspect that would not work out due to the type of the Val constructor. Is this correct? Correct, the types wouldn't work. Try it and see :) The reason I find all this odd is because I'm not sure how the type class Functor relates to the category theory concept of a functor. How does declaring a type constructor to be an instance of the Functor class relate to a functor? Is the type constructor considered a functor? I could try to answer this one, but I would just confuse both of us, heh. Hope I was helpful! Any help would be, of course, greatly appreciated. -Corey O'Connor ___ 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] parsebinaryoperations
Maybe you should look into Parsec, a Haskell library for writing parsers. Google should find what you need. - Phil On Dec 9, 2007 1:58 AM, Ryan Bloor [EMAIL PROTECTED] wrote: hi I have a function parseInt... which needs an error guard for when the input is not an Int. parseInt :: Parser parseInt [] = [] parseInt xs = let (digits, rest) = span isDigit (removeSpace xs) in [(EInt (read digits), removeSpace rest)] Also... I have a function that does this... parseBinaryOp + (5 + 2) if gives...[(Int 5, Int 2, if)] so, op is '+' or . I am unsure of how to begin... parseBinaryOp :: String - String - [(Expr, Expr, String)] parseBinaryOp op str Thankyou 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
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
Re: [Haskell-cafe] Pattern matching error
If you add a third pattern, you can see exactly what it's failing to match: kmerge x = error (show x) In order to do this, you just need to add Show constraints for a and b in the type of kmerge: kmerge :: (Show a, Show b, Eq a) = [(a,[b])]-[(a,[b])] You'll find that the pattern that it's failing to match is: [('b',[5,4]),('b',[1]),('b',[6])] Because you combined 5 and 4 and passed that on to your recursive 'kmerge' call. Your patterns only cover the case where there is exactly one element in the list. - Phil On Dec 6, 2007 9:39 AM, georg86 [EMAIL PROTECTED] wrote: Hello! I need to write a function which should is supposed to merge multiple entries with the same key (out of a sorted key-value-list) into one single entry. However, I keep getting a pattern matching error. (For example, for input [('b',[5]),('b',[4]),('b',[1]),('b',[6])]: Program error: pattern match failure: kgroup [('b',[5,4]),('b',[1]),('b',[6])]) Thank you very much for your help. kmerge::Eq a = [(a,[b])]-[(a,[b])] kmerge [] = [] kmerge ((x,[y]):[]) = [(x,[y])] kmerge ((x,[y]):(u,[v]):xs) | x == u = kmerge ((x,[y,v]):xs) | otherwise = (x,[y]):(u,[v]):kmerge xs -- View this message in context: http://www.nabble.com/Pattern-matching-error-tf4957268.html#a14196413 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ 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] Illegal type def
Should work with glasgow extensions (-fglasgow-exts). - Phil On Dec 1, 2007 6:43 PM, PR Stanley [EMAIL PROTECTED] wrote: Hi type assoc k v = [(k, v)] works beautifully and everything makes sense. type Assoc v = (Ord k) = [(k, v)] This doesn't work. Is there any wayof defining k as an element of type Ordinal. I could redefine k by putting Char or Int in its place. Why can't I be more general? Thanks, Paul ___ 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