Re: [Haskell-cafe] grapefruit on windows or osX

2010-02-23 Thread Wolfgang Jeltsch
Am Sonntag, 21. Februar 2010 21:57:45 schrieb gladst...@gladstein.com:
> I'm unable to get grapefruit going on osx or windows because (I think) I
> can't get the underlying GTK installed.

Hi,

thank you for giving Grapefruit a try.

Yes, you are most likely right that Gtk2Hs is the stumbling block. Grapefruit 
itself doesn’t do anything OS-specific, and since it works on Linux, it should 
also work on OS X.

I strongly suggest that you try out the current development version of 
Grapefruit instead of the version on Hackage, since the latter is lacking a 
bunch of features.

If you have any Grapefruit-related questions, please ask here or on the 
Grapefruit mailing list.

Best wishes,
Wolfgang
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Alex Lexer: Trying to get rid of "Alex"

2010-02-23 Thread Amit Deshwar
Hi Haskell-cafe

My problem:  I'm trying to obtain the current position of the lexer once it
reaches the end of the file (line and row number).
I'm trying to do this in a function:

getEndPosition = do
  (a,b,c) <- alexGetInput
  return a


Unfortunately, the type of a is 'Alex AlexPosn' instead of just 'AlexPosn'
How do I strip the Alex so I'm left with just a AlexPosn object?

Thanks,

Amit Deshwar
University of Calgary
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Alex Lexer: Trying to get rid of "Alex"

2010-02-23 Thread Bernie Pope
On 23 February 2010 20:15, Amit Deshwar  wrote:
> Hi Haskell-cafe
> My problem:  I'm trying to obtain the current position of the lexer once it
> reaches the end of the file (line and row number).
> I'm trying to do this in a function:
> getEndPosition = do
>   (a,b,c) <- alexGetInput
>   return a
>
> Unfortunately, the type of a is 'Alex AlexPosn' instead of just 'AlexPosn'
> How do I strip the Alex so I'm left with just a AlexPosn object?

Hi Amit,

Are you sure about the type of a?

It looks like you are using the "monad" wrapper, described here:
   http://www.haskell.org/alex/doc/html/wrappers.html

If that is true, then:
   alexGetInput :: Alex AlexInput
and
   type AlexInput = (AlexPosn, Char, String)

>From that we can infer from your code:
   getEndPosition :: Alex AlexPosn
and thus:
   a :: AlexPosn

If you want to manipulate the value bound to a, you can simply apply a
function to it in the body of getEndPosition, and return the result of
that application (still inside the Alex type). Or you can use the
function:
runAlex :: String -> Alex a -> Either String a

Cheers,
Bernie.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsing of bytestrings with non-String errors?

2010-02-23 Thread Magnus Therning
On Tue, Feb 23, 2010 at 00:39, Bryan O'Sullivan  wrote:
> On Mon, Feb 22, 2010 at 2:38 PM, Magnus Therning 
> wrote:
>>
>> My thoughts went more like a parser type like
>>
>>    data Parser e a = ...
>
> Yes, I knew that's where you were going :-)
> The trouble is, you'd still have to deal with
> fail :: Monad m => String -> m a
> which would require your failure type to somehow accept a string. Plumbing
> that in would be a little more awkward than your initial exporations suggest
> :-\
> You have two problems. The first is how to construct a value of your failure
> type that accepts a String parameter so that you can support users of
> "fail". The second is that you might need to pass extra information to
> construct your failure value when naïve code uses fail or mzero, otherwise
> you will only get useful error values out quite infrequently.

Yes, I suspected there'd be something I had missed.

I guess it'd would require 'Parser e a' to have a 'fail' that's
similar to the one in 'Maybe'.  Users would then be forced to use
'' to get useful error info out.  Would that be an unworkable
situation?

>> I still haven't convinced myself that this will work though.  Also, I had
>> a
>> look at attoparsec on bitbucket, and there are some major changes between
>> 0.7
>> and 0.8.
>
> Even though those changes represent a major modification to the internals of
> attoparsec, they shouldn't really affect what you want to do, or anything
> interesting about how to do it.

Ah, that's good.  I think I'll have to postpone any work on this for
now though, and instead implement a 'String -> MyErrorType' function
for, hopefully, temporary use.  I've already been sidetracked twice
before ;-)

/M

-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Function to detect duplicates

2010-02-23 Thread Rafael Gustavo da Cunha Pereira Pinto
Hi folks,

While solving a puzzle, I was posed the problem of finding if there was no
duplicates on a list.

First I used:

noneRepeated=null.(filter (>1)).(map length).group.sort


But this seemed very unneficient, so I thought that I could detect the
duplicates while sorting, and devised this:

import Control.Monad
import Data.Maybe

noneRepeated=isNothing . (foldl merge (Just [])) . (map sort) . pairs

pairs []=[]
pairs [x]=[[x]]
pairs (x:y:xs)=[x,y]:pairs xs

sort []=Just []
sort [x]=Just [x]
sort [x,y] | x>y=Just [y,x]
   | y>x=Just [x,y]
   | x==y=Nothing

merge::(Eq a, Ord a) => Maybe [a]->Maybe [a]->Maybe[a]
merge _ Nothing = Nothing
merge Nothing _ = Nothing
merge (Just []) (Just xs)=Just xs
merge (Just xs) (Just [])=Just xs
merge (Just (x:xs)) (Just (y:ys)) | x==y = Nothing
  | x>y  = (Just y) +? (merge (Just (x:xs))
(Just ys))
  | x___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Function to detect duplicates

2010-02-23 Thread Jonas Almström Duregård
Hi Rafael,

I assume you will perform this operation on some very large lists, or
performance would not be an issue. Have you tested if your optimized
version is better than your initial one?

You should compare your implementation against something like this:

import qualified Data.Set as Set
noneRepeated :: (Ord a) => [a] -> Bool
noneRepeated = accum Set.empty where
  accum _ [] = True
  accum s (x:xs)
| Set.member x s = False
| otherwise  = accum (Set.insert x s) xs

Also there is some discussion about the nub function that relates to
this topic, e.g. http://buffered.io/2008/07/28/a-better-nub/.

/Jonas

On 23 February 2010 12:30, Rafael Gustavo da Cunha Pereira Pinto
 wrote:
>
> Hi folks,
>
> While solving a puzzle, I was posed the problem of finding if there was no
> duplicates on a list.
>
> First I used:
>
> noneRepeated=null.(filter (>1)).(map length).group.sort
>
>
> But this seemed very unneficient, so I thought that I could detect the
> duplicates while sorting, and devised this:
>
> import Control.Monad
> import Data.Maybe
>
> noneRepeated=isNothing . (foldl merge (Just [])) . (map sort) . pairs
>
> pairs []=[]
> pairs [x]=[[x]]
> pairs (x:y:xs)=[x,y]:pairs xs
>
> sort []=Just []
> sort [x]=Just [x]
> sort [x,y] | x>y=Just [y,x]
>    | y>x=Just [x,y]
>    | x==y=Nothing
>
> merge::(Eq a, Ord a) => Maybe [a]->Maybe [a]->Maybe[a]
> merge _ Nothing = Nothing
> merge Nothing _ = Nothing
> merge (Just []) (Just xs)=Just xs
> merge (Just xs) (Just [])=Just xs
> merge (Just (x:xs)) (Just (y:ys)) | x==y = Nothing
>   | x>y  = (Just y) +? (merge (Just (x:xs))
> (Just ys))
>   | x (Just (y:ys)))
>
> (+?) = liftM2 (:)
>
>
>
> My version of the merge sort returns Nothing whenever it finds two equal
> entries, aborting all subsequent comparisons.
>
> I have a few questions for the friendly people at this cafe:
>
> 1) Is there any improvement I can make?
> 2) Can it be parallelized (par, pseq)?
>
>
> Best regards,
>
> Rafael
>
> ___
> 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] Profiling OpenGL applications

2010-02-23 Thread Sönke Hahn
On Sunday, Andrew Coppin asked:

> Is Thread Scope any use for profiling single-threaded programs?

I used threadscope to look at eventlogs from a program that uses OpenGL to 
render multiple frames per second (compiled without "-threaded"). That means, 
there is CPU activity regularly (multiple times per second), and this can be 
observed via threadscope and i found it somewhat useful.

There are some problems, though:

1. I can't definitely tell, which time span corresponds to CPU activity for the 
calculations for one frame. Is it possible to generate threadscope bookmarks 
from within the profiled program? (Or other events that can be shown in 
threadscope?)

2. The GPU activity cannot be observed. This is not a problem specific to 
Haskell, though. Is it even possible (with end user hardware) to get something 
similar to threadscope, not for CPU, but GPU activity? Any other ideas, that 
might help gathering information, about what's going on on the CPU(s) and the 
GPU?

Many thanks,
Sönke
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Function to detect duplicates

2010-02-23 Thread Ertugrul Soeylemez
Rafael Gustavo da Cunha Pereira Pinto  wrote:

> While solving a puzzle, I was posed the problem of finding if there
> was no duplicates on a list.
>
> First I used:
>
> noneRepeated=null.(filter (>1)).(map length).group.sort
>
> But this seemed very unneficient, so I thought that I could detect the
> duplicates while sorting, and devised this:
>
> import Control.Monad
> import Data.Maybe
>
> noneRepeated=isNothing . (foldl merge (Just [])) . (map sort) . pairs

import Data.List

noneRepeated xs = xs == nub xs


Greets
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Function to detect duplicates

2010-02-23 Thread Daniel Fischer
Am Dienstag 23 Februar 2010 13:03:45 schrieb Ertugrul Soeylemez:
> Rafael Gustavo da Cunha Pereira Pinto  wrote:
> > While solving a puzzle, I was posed the problem of finding if there
> > was no duplicates on a list.
> >
> > First I used:
> >
> > noneRepeated=null.(filter (>1)).(map length).group.sort
> >
> > But this seemed very unneficient, so I thought that I could detect the
> > duplicates while sorting, and devised this:
> >
> > import Control.Monad
> > import Data.Maybe
> >
> > noneRepeated=isNothing . (foldl merge (Just [])) . (map sort) . pairs
>
> import Data.List
>
> noneRepeated xs = xs == nub xs

Talk about inefficiency :)

import Data.Set (Set)
import qualified Data.Set as Set

noneRepeated = go 0 Set.empty
  where
go ct st (x:xs)
| Set.size st < ct = False
| otherwise = go (ct+1) (Set.insert x st) xs
go ct st [] = ct == Set.size st

>
>
> Greets
> Ertugrul

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Function to detect duplicates

2010-02-23 Thread Jonas Almström Duregård
Ertugrul: while your solution is minimalistic, Rafael deemed his
~n*log n implementation too inefficient. Thus your ~n^3 implementation
is hardly an improvement...

/Jonas

On 23 February 2010 13:03, Ertugrul Soeylemez  wrote:
> Rafael Gustavo da Cunha Pereira Pinto  wrote:
>
>> While solving a puzzle, I was posed the problem of finding if there
>> was no duplicates on a list.
>>
>> First I used:
>>
>> noneRepeated=null.(filter (>1)).(map length).group.sort
>>
>> But this seemed very unneficient, so I thought that I could detect the
>> duplicates while sorting, and devised this:
>>
>> import Control.Monad
>> import Data.Maybe
>>
>> noneRepeated=isNothing . (foldl merge (Just [])) . (map sort) . pairs
>
> import Data.List
>
> noneRepeated xs = xs == nub xs
>
>
> Greets
> Ertugrul
>
>
> --
> nightmare = unsafePerformIO (getWrongWife >>= sex)
> http://blog.ertes.de/
>
>
> ___
> 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] Function to detect duplicates

2010-02-23 Thread Ketil Malde
Rafael Gustavo da Cunha Pereira Pinto 
writes:

> First I used:
>
> noneRepeated=null.(filter (>1)).(map length).group.sort

> But this seemed very unneficient, so I thought that I could detect the
> duplicates while sorting, and devised this:
   [...]
> 1) Is there any improvement I can make?

Well - it's a bit long, don't you think?  Long enough that from a
cursory glance, I'd say it's in the "no obvious errors" category.  How
about (inspired by quicksort, as you no doubt can tell):

   noneRepeated [] = True
   noneRepeated (x:xs) = noneRepeated lt && singleton eq && noneRepeated gt
where lt = filter (x) xs
  eq = x:filter (==x) xs
  singleton [_] = True
  singleton _   = False

> 2) Can it be parallelized (par, pseq)?

You could force each of the sublists in parallel, but you might lose
some laziness properties, so I'd carefully benchmark it.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Function to detect duplicates

2010-02-23 Thread Ertugrul Soeylemez
Jonas Almström Duregård  wrote:

> Ertugrul: while your solution is minimalistic, Rafael deemed his
> ~n*log n implementation too inefficient. Thus your ~n^3 implementation
> is hardly an improvement...

My variant has an advantage, though.  It is completely lazy, so it will
take a shortcut, as soon as a duplicate is found.  Depending on his
application, this may be useful or not.

I think the nub-based solution is the best one in general, but it's the
base library implementation of nub, which is unfortunate.  In fact, with
a better nub implementation, this becomes an O(n * log n) time
algorithm, too, but with the additional laziness advantage.  The article
you linked to contains such an implementation, I think.


Greets
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Function to detect duplicates

2010-02-23 Thread Daniel Fischer
Am Dienstag 23 Februar 2010 13:59:49 schrieb Ertugrul Soeylemez:
> Jonas Almström Duregård  wrote:
> > Ertugrul: while your solution is minimalistic, Rafael deemed his
> > ~n*log n implementation too inefficient. Thus your ~n^3 implementation
> > is hardly an improvement...

Not quite as bad, nub is O(n^2).

>
> My variant has an advantage, though.  It is completely lazy, so it will
> take a shortcut, as soon as a duplicate is found.  Depending on his
> application, this may be useful or not.
>
> I think the nub-based solution is the best one in general, but it's the
> base library implementation of nub, which is unfortunate.  In fact, with
> a better nub implementation, this becomes an O(n * log n) time

How can you nub in O(n*log n)? Remember, you only have Eq for nub.

> algorithm, too, but with the additional laziness advantage.  The article
> you linked to contains such an implementation, I think.
>
>
> Greets
> Ertugrul

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Andy Gimblett

Hi all,

Short version: How can I pretty print and parse values of type Double  
such that those operations are each other's inverse?


Long version: I'm writing and QuickCheck-testing a parser using the  
approach set out here:


http://lstephen.wordpress.com/2007/07/29/parsec-parser-testing-with-quickcheck/

That is, each syntactic category gets a pretty-printer and a parser  
and an Arbitrary instance, and QuickCheck checks that (parse .  
prettyPrint) == id, basically.  Somewhat unsurprisingly, this  
sometimes fails for floating point values (I'm using Doubles).


Now, I know that floats are in some sense imprecise, and comparing for  
equality is fraught with peril, but it seems that if x==x then it  
ought to be at least _possible_ to arrange matters such that (parse .  
prettyPrint x) == x as well.  At worst, pretty-printing the underlying  
binary representation!?  So my feeling is that my parser could be  
improved.


At the moment I'm working around it by defining a type class which  
checks for equality within some margin of error, and using that  
instead of Eq - but it's messier than I'd like, so I wondered if there  
was something obvious I'm missing.


As hpaste.org seems to be down, I'll attach a code example here instead.

Thanks!

-Andy

--
Andy Gimblett
http://gimbo.org.uk/



TestParse.hs
Description: Binary data



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Function to detect duplicates

2010-02-23 Thread Jonas Almström Duregård
>>noneRepeated xs = xs == nub xs

> Not quite as bad, nub is O(n^2)

You are correct of course. Still, it will probably be a bit less
inefficient if the length of the lists are compared (as opposed to the
elements):

noneRepeated xs = length xs == length (nub xs)

On 23 February 2010 14:09, Daniel Fischer  wrote:
> Am Dienstag 23 Februar 2010 13:59:49 schrieb Ertugrul Soeylemez:
>> Jonas Almström Duregård  wrote:
>> > Ertugrul: while your solution is minimalistic, Rafael deemed his
>> > ~n*log n implementation too inefficient. Thus your ~n^3 implementation
>> > is hardly an improvement...
>
> Not quite as bad, nub is O(n^2).
>
>>
>> My variant has an advantage, though.  It is completely lazy, so it will
>> take a shortcut, as soon as a duplicate is found.  Depending on his
>> application, this may be useful or not.
>>
>> I think the nub-based solution is the best one in general, but it's the
>> base library implementation of nub, which is unfortunate.  In fact, with
>> a better nub implementation, this becomes an O(n * log n) time
>
> How can you nub in O(n*log n)? Remember, you only have Eq for nub.
>
>> algorithm, too, but with the additional laziness advantage.  The article
>> you linked to contains such an implementation, I think.
>>
>>
>> Greets
>> Ertugrul
>
> ___
> 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] Re: Function to detect duplicates

2010-02-23 Thread Daniel Fischer
Am Dienstag 23 Februar 2010 14:54:36 schrieb Jonas Almström Duregård:
> You are correct of course. Still, it will probably be a bit less
> inefficient if the length of the lists are compared (as opposed to the
> elements):
>
> noneRepeated xs = length xs == length (nub xs)

Only if no repeated elements appear early.
For xs = 1 : [1 .. 10^7], xs == nub xs will return False without noticeable 
delay, length xs == length (nub xs) will take VERY long.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Daniel Fischer
Am Dienstag 23 Februar 2010 14:44:50 schrieb Andy Gimblett:
> Hi all,
>
> Short version: How can I pretty print and parse values of type Double
> such that those operations are each other's inverse?
>
> Long version: I'm writing and QuickCheck-testing a parser using the
> approach set out here:
>
> http://lstephen.wordpress.com/2007/07/29/parsec-parser-testing-with-quic
>kcheck/
>
> That is, each syntactic category gets a pretty-printer and a parser
> and an Arbitrary instance, and QuickCheck checks that (parse .
> prettyPrint) == id, basically.  Somewhat unsurprisingly, this
> sometimes fails for floating point values (I'm using Doubles).
>
> Now, I know that floats are in some sense imprecise, and comparing for
> equality is fraught with peril, but it seems that if x==x then it
> ought to be at least _possible_ to arrange matters such that (parse .
> prettyPrint x) == x as well.  At worst, pretty-printing the underlying
> binary representation!?  So my feeling is that my parser could be
> improved.

Parse it as a Rational, then convert with fromRational.
I don't know whether that will always have parse . prettyPrint == id, but 
it'll be much closer.

The naturalOrFloat default implementation uses

fraction= do{ char '.'
; digits <- many1 digit  "fraction"
; return (foldr op 0.0 digits)
}
   "fraction"
where
  op d f= (f + fromIntegral (digitToInt d))/10.0

and division by 10 isn't exact with a binary representation.

>
> At the moment I'm working around it by defining a type class which
> checks for equality within some margin of error, and using that
> instead of Eq - but it's messier than I'd like, so I wondered if there
> was something obvious I'm missing.
>
> As hpaste.org seems to be down, I'll attach a code example here instead.
>
> Thanks!
>
> -Andy
>
> --
> Andy Gimblett
> http://gimbo.org.uk/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Christian Maeder
Andy Gimblett schrieb:
> Hi all,
> 
> Short version: How can I pretty print and parse values of type Double
> such that those operations are each other's inverse?

Maybe you have more luck with show and read (without Parsec.Token).

Your example:
x = 9.91165677454629

fails because the computation performed by the parser
9.0 + 0.91165677454629 yields 9.911656774546291

Cheers Christian

> Long version: I'm writing and QuickCheck-testing a parser using the
> approach set out here:
> 
> http://lstephen.wordpress.com/2007/07/29/parsec-parser-testing-with-quickcheck/
> 
> 
> That is, each syntactic category gets a pretty-printer and a parser and
> an Arbitrary instance, and QuickCheck checks that (parse . prettyPrint)
> == id, basically.  Somewhat unsurprisingly, this sometimes fails for
> floating point values (I'm using Doubles).
> 
> Now, I know that floats are in some sense imprecise, and comparing for
> equality is fraught with peril, but it seems that if x==x then it ought
> to be at least _possible_ to arrange matters such that (parse .
> prettyPrint x) == x as well.  At worst, pretty-printing the underlying
> binary representation!?  So my feeling is that my parser could be improved.
> 
> At the moment I'm working around it by defining a type class which
> checks for equality within some margin of error, and using that instead
> of Eq - but it's messier than I'd like, so I wondered if there was
> something obvious I'm missing.
> 
> As hpaste.org seems to be down, I'll attach a code example here instead.
> 
> Thanks!
> 
> -Andy
> 
> -- 
> Andy Gimblett
> http://gimbo.org.uk/
> 
> 
> 
> 
> 
> 
> ___
> 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] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Andy Gimblett



Short version: How can I pretty print and parse values of type Double
such that those operations are each other's inverse?


Maybe you have more luck with show and read (without Parsec.Token).

Your example:
x = 9.91165677454629

fails because the computation performed by the parser
9.0 + 0.91165677454629 yields 9.911656774546291


That seems to do the trick!  Below, for the record, the code I've come  
up with (I threw away the Either Integer Double part so it's a bit  
simpler, also).  I'm sure it can be improved, but this is passing all  
tests reliably, it seems.


Many thanks, Christian and Daniel, for your help!

Best,

-Andy

parseDouble :: Parser Double
parseDouble = try $ do (symbol toks) "-"
   n <- floater
   return $ negate n
  <|> floater
  where toks = makeTokenParser emptyDef

-- This could definitely be improved, but it's working. :-)
floater :: Parser Double
floater = do w <- many1 digit
 char '.'
 f <- many1 digit
 e <- optionMaybe $ do char 'e' -- Optional exponent part
   n <- option "" (char '-' >> return  
"-") -- Optional negation in exponent

   m <- many1 digit
   return $ n ++ m
 case e of Nothing -> return $ read $ w ++ "." ++ f
   Just e' -> return $ read $ w ++ "." ++ f ++  
"e" ++ e'


--
Andy Gimblett
http://gimbo.org.uk/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Problems linking hsql-mysql

2010-02-23 Thread Maciej Podgurski

Hi,

I have problems linking a simple test program that imports 
Database.HSQL.MySQL via ghc --make Test.hs. The error only occurs when 
importing this module of hsql-mysql-1.7.1. I pasted the building output 
here: http://hpaste.org/fastcgi/hpaste.fcgi/view?id=22911 (actually it 
was even longer but hpaste only takes 30k).


When I do ghc -e main Test.hs or starting it from GHCi, everything works 
fine and no errors occur. So I guess all needed .lib files are there but 
GHC can't find them when linking (adding the flag -L"path to 
mysql/lib/opt" doesn't help). Anyone an idea?



Best wishes,

Maciej
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Lennart Augustsson
If you use read (reads) and show for the actual conversion it will round trip.
It appears to be non-trivial since most languages and libraries get it wrong. :)

  -- Lennart

On Tue, Feb 23, 2010 at 1:44 PM, Andy Gimblett  wrote:
> Hi all,
>
> Short version: How can I pretty print and parse values of type Double such
> that those operations are each other's inverse?
>
> Long version: I'm writing and QuickCheck-testing a parser using the approach
> set out here:
>
> http://lstephen.wordpress.com/2007/07/29/parsec-parser-testing-with-quickcheck/
>
> That is, each syntactic category gets a pretty-printer and a parser and an
> Arbitrary instance, and QuickCheck checks that (parse . prettyPrint) == id,
> basically.  Somewhat unsurprisingly, this sometimes fails for floating point
> values (I'm using Doubles).
>
> Now, I know that floats are in some sense imprecise, and comparing for
> equality is fraught with peril, but it seems that if x==x then it ought to
> be at least _possible_ to arrange matters such that (parse . prettyPrint x)
> == x as well.  At worst, pretty-printing the underlying binary
> representation!?  So my feeling is that my parser could be improved.
>
> At the moment I'm working around it by defining a type class which checks
> for equality within some margin of error, and using that instead of Eq - but
> it's messier than I'd like, so I wondered if there was something obvious I'm
> missing.
>
> As hpaste.org seems to be down, I'll attach a code example here instead.
>
> Thanks!
>
> -Andy
>
> --
> Andy Gimblett
> http://gimbo.org.uk/
>
>
>
>
>
> ___
> 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] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-23 Thread Andy Gimblett

For the record, here's the final improved version:

float' :: TokenParser st -> GenParser Char st Double
float' t = do n <- liftCtoS '-'
  w <- many1 digit
  char '.'
  f <- many1 digit
  e <- option "" $ do char 'e'
  n' <- liftCtoS '-'
  m <- many1 digit
  return $ concat ["e", n', m]
  whiteSpace t
  return $ read $ concat [n, w, ".", f, e]
  where liftCtoS a = option "" (char a >> return [a])

Thanks for all the help, again.

-Andy

--
Andy Gimblett
http://gimbo.org.uk/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problems linking hsql-mysql

2010-02-23 Thread Nick Rudnick

Hi Maciej,

I will try to reproduce the error -- could you send me your both *.cabal 
files (for hsql & hsql-mysql), if you have changed anything, and your 
system configuration.


Is this extremely urgent? I ask this, as these days exactly the end 
phase of the projects of about 100 beginner Haskell students, which I am 
the one to look after. So I am in a little of slow motion regarding 
other things... ;-)


But in case you are in emergency, please let me know... At first sight, 
I would say it looks like a configuration problem... ;-)


Cheers,

   Nick

Maciej Podgurski wrote:

Hi,

I have problems linking a simple test program that imports 
Database.HSQL.MySQL via ghc --make Test.hs. The error only occurs when 
importing this module of hsql-mysql-1.7.1. I pasted the building 
output here: http://hpaste.org/fastcgi/hpaste.fcgi/view?id=22911 
(actually it was even longer but hpaste only takes 30k).


When I do ghc -e main Test.hs or starting it from GHCi, everything 
works fine and no errors occur. So I guess all needed .lib files are 
there but GHC can't find them when linking (adding the flag -L"path to 
mysql/lib/opt" doesn't help). Anyone an idea?



Best wishes,

Maciej
___
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] Re: sendfile leaking descriptors on Linux?

2010-02-23 Thread Brandon S. Allbery KF8NH

On Feb 21, 2010, at 20:17 , Jeremy Shaw wrote:
The PS3 does do something though. If we were doing a write *and*  
read select on the socket, the read select would wakeup. So, it is  
trying to notify us that something has happened, but we are not  
seeing it because we are only looking at the write select().


Earlier the OP claimed this would happen within a few minutes if he  
seeked in a movie.  If it's that reproducible, it should be easy to  
capture a tcpdump and attach it to an email (or pastebin it), allowing  
us to determine what really happens.


Also, Donn, you are incorrect about invalidating premises; we know the  
connection is going away, we can infer it's not going away normally,  
that's why there have been comments about it sending a FIN and  
dropping the connection entirely (bypassing the shutdown handshake),  
or sending an RST, etc.


(I'd also be interested in finding out if OpenSolaris or FreeBSD has  
the same problem, but that may be too difficult to test easily.  I  
still find it highly unlikely that loss of a connection only wakes the  
read end in general, and would absolutely not be surprised if this  
were some odd corner case in the Linux TCP stack.  Sadly, I don't have  
a PS3 (yet, if ever) and I don't know of any streaming software for  
non-hacked Wiis.)


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: sendfile leaking descriptors on Linux?

2010-02-23 Thread Donn Cave
Quoth "Brandon S. Allbery KF8NH" ,
> On Feb 21, 2010, at 20:17 , Jeremy Shaw wrote:
>> The PS3 does do something though. If we were doing a write *and*  
>> read select on the socket, the read select would wakeup. So, it is  
>> trying to notify us that something has happened, but we are not  
>> seeing it because we are only looking at the write select().
>
> Earlier the OP claimed this would happen within a few minutes if he  
> seeked in a movie.  If it's that reproducible, it should be easy to  
> capture a tcpdump and attach it to an email (or pastebin it), allowing  
> us to determine what really happens.
>
> Also, Donn, you are incorrect about invalidating premises; we know the  
> connection is going away, we can infer it's not going away normally,  
> that's why there have been comments about it sending a FIN and  
> dropping the connection entirely (bypassing the shutdown handshake),  
> or sending an RST, etc.

That's what I'm saying - it clearly is not a full close, i.e., going
away normally per protocol.

With luck maybe the packets will show that something does happen at
a wire protocol level, and there will be a way to recognize the event
at the `user land' level and plug that into the event loop.

My prediction is that on the contrary, the transition between functional
and defunct will not be not announced in any way by the peer, but that's
just guessing.  It would be a lot less interesting.

Donn

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: sendfile leaking descriptors on Linux?

2010-02-23 Thread Brandon S. Allbery KF8NH

On Feb 23, 2010, at 23:47 , Donn Cave wrote:
My prediction is that on the contrary, the transition between  
functional
and defunct will not be not announced in any way by the peer, but  
that's

just guessing.  It would be a lot less interesting.



But that's not the issue.  The *kernel* is clearly detecting it; the  
problem is it's only being reported for the *read* end of the socket,  
whereas sendfile() (correctly) only cares about, and therefore only  
registers interest in, the *write* end.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Optimizing hash array mapped tries

2010-02-23 Thread Brandon S. Allbery KF8NH

On Feb 22, 2010, at 02:15 , Edward Z. Yang wrote:

* i-Full-update essentially copies a 32-size vector, with a change to
 one element.  I think I am getting brutally punished for this, in
 terms of both memory usage as well as runtime.  What I'm curious is
 whether or not this is intrinsic to the algorithm, or if it's
 something special that GHC is doing.


IIRC this is intrinsic to the way GHC modifies and garbage-collects  
array modifications.  There's been discussion on -cafe about it.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC RTS question

2010-02-23 Thread Brandon S. Allbery KF8NH

On Feb 22, 2010, at 03:36 , Roman Cheplyaka wrote:

* Anthony Cowley  [2010-02-21 14:15:00-0500]

#! /usr/bin/env bash
./prog --RTS $*


 ./prog --RTS "$@"

Otherwise it will work wrong if arguments contain quoted field
separators (e.g. spaces).



  #! /bin/sh
  ./prog --RTS ${1+"$@"}

The longer specification above should work with whatever /bin/sh is  
around, whether it's Solaris /sbin/sh, FreeBSD's sh, general Linux  
bash, Debian/Ubuntu dash, etc.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Linux ghci vs Windows ghci

2010-02-23 Thread Brandon S. Allbery KF8NH

On Feb 21, 2010, at 06:27 , Donghee Nah wrote:
I'm using Windows 7 32bit Host OS(ghc 6.8.3) and Virtualbox  
Archlinux Guest OS(ghc 6.8.4)
I feel that ghci code executing speed in guest os is 1.5~2x faster  
than host os


My guess is that GHC (and the GHC RTS) on win32 is using a POSIX  
emulation layer supplied by mingw32 for all system calls, introducing  
extra overhead.  Unfortunately, I don't think we have enough Windows- 
familiar folks with enough understanding of the GHC RTS to optimize it  
for the native Windows API.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] [offtopic] UNIX Shell (was: GHC RTS question)

2010-02-23 Thread Roman Cheplyaka
* Brandon S. Allbery KF8NH  [2010-02-24 00:02:12-0500]
> On Feb 22, 2010, at 03:36 , Roman Cheplyaka wrote:
> >* Anthony Cowley  [2010-02-21 14:15:00-0500]
> >>#! /usr/bin/env bash
> >>./prog --RTS $*
> >
> > ./prog --RTS "$@"
> >
> >Otherwise it will work wrong if arguments contain quoted field
> >separators (e.g. spaces).
> 
> 
>   #! /bin/sh
>   ./prog --RTS ${1+"$@"}
> 
> The longer specification above should work with whatever /bin/sh is
> around, whether it's Solaris /sbin/sh, FreeBSD's sh, general Linux
> bash, Debian/Ubuntu dash, etc.

Are you referring to some Solaris shell bug?

Under POSIX these constructs seem to be equivalent.
"If there are no positional parameters, the expansion of '@' shall
generate zero fields, even when '@' is double-quoted."

-- 
Roman I. Cheplyaka :: http://ro-che.info/
"Don't let school get in the way of your education." - Mark Twain
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe