Re: [Haskell-cafe] Strange behavior of float literals
On Sat, Apr 5, 2008 at 1:00 AM, Vladimir Reshetnikov [EMAIL PROTECTED] wrote: The float literal 1e-1 in GHC evaluates to 1.0, and 1e-9 evaluates to 10.0. Is it a bug, or a documented overflow behavior? Sounds like a bug to me. I wasn't able to test your example in GHCi because it started consuming all my memory. In GHCi 6.8.2 I got: Prelude let x = 1e-100 *** Exception: stack overflow I tried compiling the following program with ghc -O --make, and it again started consuming all memory: x = 1e-1 :: Double main = print x What it the correct place to submit bug reports concerning GHC? http://hackage.haskell.org/trac/ghc/wiki/ReportABug -- I'm doing Science and I'm still alive. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A question about monad laws
On Feb 11, 2008 11:24 AM, Wolfgang Jeltsch [EMAIL PROTECTED] wrote: a b b c = a c If an Ord instances doesn't obey these laws than it's likely to make Set and Map behave strangely. Some months ago I pointed out that Ratio Int (which is an Ord instance) doesn't satisfy this property. I provided a patch to fix the problem, but my bug report was closed as wontfix: http://hackage.haskell.org/trac/ghc/ticket/1517. -- I'm doing Science and I'm still alive. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A question about monad laws
On Feb 11, 2008 10:18 PM, Uwe Hollerbach [EMAIL PROTECTED] wrote: If I fire up ghci, import Data.Ratio and GHC.Real, and then ask about the type of infinity, it tells me Rational, which as far as I can tell is Ratio Integer...? Yes, Rational is Ratio Integer. It might not be a good idea to import GHC.Real, since it doesn't seem to be documented at http://www.haskell.org/ghc/docs/latest/html/libraries/. If you just import Data.Ratio, and define pinf :: Integer pinf = 1 % 0 ninf :: Integer ninf = (-1) % 0 Then things fail the way you expect (basically, Data.Ratio isn't written to support infinity). But it's really odd the way the infinity from GHC.Real works. Anyone have an explanation? -- I'm doing Science and I'm still alive. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] QuickCheck properties: export or not?
I think that type classes with nontrivial requirements should export QuickCheck properties that test those requirements. For example, the Data.Monoid module (http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Monoid.html) could export properties that check the monoid laws (for an Arbitrary Monoid with Eq). That would serve as a formal specification of the requirements, and allow any user to check that their implementation is right. -- I'm doing Science and I'm still alive. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [newbie question] Memoization automatic in Haskell?
On 1/12/08, Henning Thielemann [EMAIL PROTECTED] wrote: Caching is not the default, but you can easily code this by yourself: Define an array and initialize it with all function values. Because of lazy evaluation the function values are computed only when they are requested and then they persist in the array. But how can I implement memoization for a more complicated function? For example, perhaps I want to memoize f :: String - Int - Double - String - Bool In Python, it's pretty easy to memoize this. How can I do it in Haskell? I suspect the only way would involve changing the function signature to use IO or ST. It would be nice if I could just tell the compiler I command you to memoize this function, and have it produce the required code automatically. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does this blow the stack?
On 12/26/07, Don Stewart [EMAIL PROTECTED] wrote: Depending on laziness if fine, but depending on undefined strictness semantics for particular types is more fragile. Whether Int or Bool or whatever type has a strict or lazy accumulator in enumFromTo is entirely unspecified -- you can't look up the report to check. Right, I understand that. But is there any reason not to keep the Integer version of [a..] lazy, given that we can fix the stack overflow problem without introducing strictness? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does this blow the stack?
Since it's possible to support laziness for Integer (while still avoiding any stack overflow), I think it makes sense to do so. What if you have some big complicated program like the following: x = some big slow computation y = [x..] lots of code z = length $ take 10 y Why bother computing x if you don't have to? And as an added benefit, if you keep laziness, you don't have to worry about possibly breaking any programs that depend on the current lazy behavior. Laziness would NOT make sense for Int, since Int is bounded. You can't tell how long [(x::Int) ..] is without evaluating x. On 12/22/07, Don Stewart [EMAIL PROTECTED] wrote: People shouldn't be writing code that depends on this! One of the main features of Haskell is that it's lazy. I don't think it's wrong to write code that depends on laziness. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does this blow the stack?
On 12/21/07, Stefan O'Rear [EMAIL PROTECTED] wrote: Because they simply aren't the same. Good point; thanks. That means that Don's patch could theoretically break some existing Haskell program: Prelude length $ take 10 ([undefined ..] :: [Integer]) 10 With his patch, that will throw. Some other types have the same issue (lazy Enum when it could be strict, leading to stack overflow): Prelude length $ take 10 ([undefined ..] :: [Double]) 10 Prelude length $ take 10 ([undefined ..] :: [Float]) 10 Prelude Foreign.C.Types length $ take 10 ([undefined ..] :: [CFloat]) 10 Prelude Foreign.C.Types length $ take 10 ([undefined ..] :: [CDouble]) 10 Prelude Foreign.C.Types length $ take 10 ([undefined ..] :: [CLDouble]) 10 Prelude Data.Ratio length $ take 10 ([undefined ..] :: [Ratio Int]) 10 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does this blow the stack?
On 12/22/07, David Benbennick [EMAIL PROTECTED] wrote: On 12/21/07, Stefan O'Rear [EMAIL PROTECTED] wrote: Because they simply aren't the same. Good point; thanks. That means that Don's patch could theoretically break some existing Haskell program: In fact, it's possible to get strictness to avoid stack overflow, and still have laziness to allow undefined: myEnumFrom :: Integer - [Integer] myEnumFrom a = map (a+) $ enumDeltaIntegerStrict 0 1 where enumDeltaIntegerStrict x d = x `seq` x : enumDeltaIntegerStrict (x+d) d then *Main (myEnumFrom 42) !! (10^6) 142 *Main length $ take 10 $ myEnumFrom undefined 10 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does this blow the stack?
On Dec 21, 2007 9:51 AM, Justin Bailey [EMAIL PROTECTED] wrote: I think its [1..] which is building up the unevaluated thunk. Using this definition of dropTest does not blow the stack: It also works if you do [(1::Int) ..] !! n, but not with [(1::Integer) ..] !! n Sounds like GHC is being smart about strictness for Ints, but doesn't know that Integer is equally strict. If that's right, it's a bug in GHC. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does this blow the stack?
On Dec 21, 2007 12:02 PM, Don Stewart [EMAIL PROTECTED] wrote: There's no good reason for the accumulator for Integer to be lazy, especially when you see that adding an upper bound (enumFromTo) or using Int uses a strict accumulator. I've filled a bug report and fix for this. http://hackage.haskell.org/trac/ghc/ticket/1997 there's an ad hoc sprinkling of strict and lazy Num ops for Integer through the base library, while Int is fairly consistently strict. Thanks for fixing this. But doesn't GHC have strictness analysis? Even if there was consistent strictness for Integer in the base library, that wouldn't help for code not in the base library. In other words, I want to be able to define mysum :: (Num a) = [a] - a mysum = foldl (+) 0 in my own programs, and have GHC automatically make it strict if a happens to be Int or Integer. Is there any chance of GHC getting that ability? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why does this blow the stack?
On Dec 21, 2007 2:30 PM, Don Stewart [EMAIL PROTECTED] wrote: dbenbenn: Thanks for fixing this. But doesn't GHC have strictness analysis? Sure does! The problem here was an explicit recusive loop though, with just not enough for the strictness analyser to get going. The explicit loop you're talking about is: enumDeltaInteger :: Integer - Integer - [Integer] enumDeltaInteger x d = x : enumDeltaInteger (x+d) d That code isn't very complicated, and I would hope to be able to write code like that in my own programs without having to worry about strictness. Given that the compiler even has an explicit signature, why can't it transform that code to enumDeltaInteger x d = let s = x + d in x : (seq s $ enumDeltaInteger s d) since it knows that (Integer+Integer) is strict? Of course, improving the strictness analysis is harder, but it pays off more, too. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Looking for smallest power of 2 = Integer
On Dec 4, 2007 9:21 AM, Steven Fodstad [EMAIL PROTECTED] wrote: For the index, how about this: truncate . (/(log 2)) . log . fromIntegral That will not work. It will convert the Integer to Double, which will overflow if the Integer is very large. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Looking for largest power of 2 = Integer
On Dec 4, 2007 11:51 AM, Don Stewart [EMAIL PROTECTED] wrote: Awesome. We can use this in Data.Bits, if you've got some QuickChecks for it. Hear hear. But is there any way to just make the compiler use fastTestBit in place of testBit :: (Bits a) = a - Int - Bool when a = Integer? (That is, without having to introduce a new function to the public interface of Data.Bits.) Some kind of SPECIALIZE pragma, perhaps? I've attached a program with two QuickCheck properties. Unfortunately they fail on negative Integers. I can't figure out why. {-# OPTIONS_GHC -fglasgow-exts #-} module Main where import Test.QuickCheck import Data.Bits import GHC.Exts fastTestBit :: Integer - Int - Bool fastTestBit n i = case n of S# m - testBit (I# m) i J# l d - let I# w = shiftR i 6 b = i .. 63 in testBit (I# (indexIntArray# d w)) b prop_testBit1 :: Integer - Int - Bool prop_testBit1 i n = testBit i n == fastTestBit i n -- Test fastTestBit on large Integers prop_testBit2 :: Integer - Int - Int - Bool prop_testBit2 i j n = testBit k n == fastTestBit k n where k = i ^ (abs j) main = do putStrLn Testing prop_testBit1: quickCheck prop_testBit1 putStrLn Testing prop_testBit2: quickCheck prop_testBit2 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Looking for smallest power of 2 = Integer
On 12/3/07, Dan Piponi [EMAIL PROTECTED] wrote: On Dec 3, 2007 9:32 PM, Sterling Clover [EMAIL PROTECTED] wrote: if all else fails, be determined by unpacking it into the primitives, which are (# Int#, ByteArr# #) with the Int# as the number of limbs of the integer, as well as its sign. That's the answer I'm looking for, thanks. Could you please post your code here when you're done? I'd be interested to see the final result. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Erik Meijer's talk at Google?
Google's Tech Talks channel is at http://www.youtube.com/googletechtalks. There doesn't seem to be any video of Erik Meijer there. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Screen scraping with an interactive process: Buffering problems?
On Nov 7, 2007 5:12 AM, Denis Bueno [EMAIL PROTECTED] wrote: Ironically, this was my first problem. First of all, I don't think I want the semi-closed state -- I want to be able to read and write freely later on (I may be misunderstanding semi-closed, however). I don't think that makes sense. First of all, pout is only the stdout of the program, so you can only read from it, not write to it. And once you do hGetContents, you have read all the data that will ever exist on that handle, so there's nothing to read from it later on. Second, when I used this approach, after the hGetContents call I did the regexp matching, and the program hung during matching. That's not surprising. You first match for Proof succeeded. So if the proof failed, the matcher will go past the attempt has failed message, looking for a later succeeded. Which means it will block waiting for more output from your subprocess, which will never produce more output until you give it another request. Assuming that each call to ACL2 produces exactly one of either Proof succeeded or attempt has failed, you can get a list of results like this (where aclOutput :: String is the result of hGetContents): let results = map (\l - if l == Proof succeeded then True else False) $ filter (\l - elem l [Proof succeeded, attempt has failed]) $ lines aclOutput Then results :: [Bool], and results !! n is True if the nth call succeeded. Just make sure not to inspect results !! n until after making the nth call to ACL2, or it will block. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] type/class question: toString
On 11/6/07, Graham Fawcett [EMAIL PROTECTED] wrote: ToString.hs:5:0: Illegal instance declaration for `MyShow String' (The instance type must be of form (T a b c) where T is not a synonym, and a,b,c are distinct type variables) In the instance declaration for `MyShow String' ToString.hs:6:0: Illegal instance declaration for `MyShow a' (The instance type must be of form (T a b c) where T is not a synonym, and a,b,c are distinct type variables) In the instance declaration for `MyShow a' In ghc 6.8.1, the error messages are more helpful: foo.hs:5:0: Illegal instance declaration for `MyShow String' (All instance types must be of the form (T t1 ... tn) where T is not a synonym. Use -XTypeSynonymInstances if you want to disable this.) In the instance declaration for `MyShow String' foo.hs:6:0: Illegal instance declaration for `MyShow a' (All instance types must be of the form (T a1 ... an) where a1 ... an are distinct type *variables* Use -XFlexibleInstances if you want to disable this.) In the instance declaration for `MyShow a' When I run with -XTypeSynonymInstances -XFlexibleInstances it works. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Screen scraping with an interactive process: Buffering problems?
What about using hGetContents to just read ALL of the input, as a lazy string? Then you look through that string for success or failure. In other words, readACL2Answer pout = do s - hGetContents pout parse s here ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Monte Carlo Pi calculation (newbie learnings)
On 11/5/07, David Roundy [EMAIL PROTECTED] wrote: On Mon, Nov 05, 2007 at 01:42:50PM -0700, Luke Palmer wrote: let pairs = [ (x,y) | x - randoms (-1,1) g0 | y - randoms (-1,1) g1 ] Or even better, just don't use list comprehensions, they're confusing: let pairs = zip (randoms (-1,1) g0) (randoms (-1,1) g1) Or even better, have a declaration instance (Random a, Random b) = Random (a, b) then do let pairs = randomRs ((-1, -1), (1, 1)) g0 Wouldn't it be nice if System.Random had an instance declaration for pairs? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Strange subtract operator behavior - and lazy naturals
This module doesn't appear to be very lazy to me. For example, in ghci, *Util.LazyNum List genericLength (1:2:undefined) (1 :: Nat) *** Exception: Prelude.undefined How is this module intended to be used? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Strange subtract operator behavior - and lazy naturals
On 10/17/07, John Meacham [EMAIL PROTECTED] wrote: Oops, sorry, the version I posted was an intermediate one that had a different addition algorithm. here is a better one that fixes that issue: Zero + y = y Sum x n1 + y = Sum x (y + n1) note that it alternates the order in the recursive call, interleaving the elements of the two arguments. Thanks. Have you thought at all about how to make maximally lazy Naturals? For example, a data type that can answer True to both genericLength (1:undefined) + genericLength (1:2:3:4:5:6:undefined) (6 :: Nat) genericLength (1:2:3:4:5:6:undefined) + genericLength (1:undefined) (6 :: Nat) Is that a desired feature? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: pi
On 10/10/07, Dan Weston [EMAIL PROTECTED] wrote: Actually, it is a constant: piDecimalExpansion :: String. Where is this constant defined? A translation from piDecimalExpansion :: String to pi :: Floating a = a is already well defined via read :: Read a = String - a Any definition of pi in the Floating class that differs from (read piDecimalExpansion) is erroneous. I propose the above as the default definition of pi. piDecimalExpansion, if defined, would be an infinite length string. The expression read $ 0. ++ repeat '1' :: Double is Bottom. So even if you had piDecimalExpansion, it isn't clear how to use that to define pi. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Manual constructor specialization
On 10/9/07, Johan Tibell [EMAIL PROTECTED] wrote: data Rope = Empty | Leaf | Node !Rope !Rope The point is that Empty can only appear at the top by construction How about indicating this in your data type? I.e., data Rope = Empty | NonEmptyRope data NonEmptyRope = Leaf | Node !NonEmptyRope !NonEmptyRope ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Dynamic choice of reverse implementation
On 9/28/07, Ross Paterson [EMAIL PROTECTED] wrote: However one can define reversor :: Traversable f = f a - f a which returns something of the same shape, but with the contents reversed. How? Is it possible to define a version of foldl for Traversable? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] getting crazy with character encoding
On 9/12/07, Andrea Rossato [EMAIL PROTECTED] wrote: If I run it in a console I get abAAA (sort of) no matter what my LANG is - 8 single 8 -bit characters. It's possible to set your Linux console to grok UTF8. I don't remember the details, but I'm sure you can Google for it. By the way, does anyone know The Right Way to deal with UTF-8 in Haskell? I.e., take that 8 byte UTF-8 string and convert it to a 5 character Unicode string (so it can be manipulated)? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] About mplus
On 9/4/07, ok [EMAIL PROTECTED] wrote: I've been thinking about making a data type an instance of MonadPlus. From the Haddock documentation at haskell.org, I see that any such instance should satisfy mzero `mplus` x = x x `mplus` mzero = x mzero = f = mzero v mzero = mzero but is that all there is to it? Are there no other requirements for MonadPlus to make sense? Also, mplus has to be associative. I.e. (a `mplus` b) `mplus` c == a `mplus` (b `mplus` c) I also wondered why, once MonadPlus was added to the language, the definition of ++ wasn't changed to (++) = MonadPlus (with the MonadPlus instance for [] defined directly). You mean (++) = mplus. I've wondered that too. Similarly, one should define map = fmap. And a lot of standard list functions can be generalized to MonadPlus, for example you can define filter :: (MonadPlus m) = (a - Bool) - m a - m a (This is not the same as filterM.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe