Re: [Haskell-cafe] Installing and running QuickCheck

2005-04-12 Thread Daniel Fischer
Hm,

no instance Arbitrary Char is provided in the QuickCheck modules that came 
with my hugs or ghc. Probably the author just forgot to import Data.Char. Try 
inserting that in QuickCheck.hs.

Hope that works,
Daniel

Am Samstag, 9. April 2005 21:10 schrieb Adam Wyner:
> Hi,
>
> I'd like to use QuickCheck for testing Haskell programs.  I'm using Hugs
> in Windows.  I'm a newbie to Haskell.
>
> Just running QuickCheck.hs itself, which comes with the Hugs98
> libraries, I get an error message and the Monad command line, which
> indicates that quickcheck didn't load.
>
> ERROR "C:\Program Files\Hugs98/libraries\QuickCheck.hs":147 - Undefined
> variable  "chr"
> Monad>
>
> Here is the line in QuickCheck.hs which leads to the error.
>
> instance Arbitrary Char where
>arbitrary = choose (32,255) >>= \n -> return (chr n)
>coarbitrary n = variant (ord n)
>
> This code is from the website:
>
> http://www.cs.chalmers.se/~rjmh/QuickCheck/QuickCheck.hs
>
> I tested it with the following module, as per the instructions in on
> QuickCheck's manual page:
> 
> module TestQuickCheck
>
> where
>
> import QuickCheck
>
> prop_RevRev xs = reverse (reverse xs) == xs
>where types = xs::[Int]
> 
> Loading just this, I get the same error:
>
> Prelude> :l TestQuickCheck
> ERROR "C:\Program Files\Hugs98/libraries\QuickCheck.hs":147 - Undefined
> variable
>   "chr"
> Monad>
>
> I know others report using QuickCheck, so this problem must have been
> resolved.
>
> Also, I guess the quickcheck script is for Linux alone?  Any scripts for
> Hugs in Windows?
>
> Cheers,
> Adam

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


[Haskell-cafe] predicates in XML toolboxes

2005-04-12 Thread Henning Thielemann
The XML toolboxes HaXml, HXML and the XML toolbox uses one function type 
(called filter) for different purposes.

The functions of types
predicates   a -> Bool
selectors, transformatorsa -> a
list-valued functionsa -> [a]
are all implemented with the one type (a -> [a]). In this design 
predicates don't return False or True, but an empty list or a one-element 
list containing the input value. Transformators return single element 
lists.
 In my opinion this means a significant loss of type safety and quality of 
documentation. Are there more type safe XML/HTML processor libraries in 
Haskell?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] predicates in XML toolboxes

2005-04-12 Thread Malcolm Wallace
Henning Thielemann <[EMAIL PROTECTED]> writes:

> The XML toolboxes HaXml, HXML and the XML toolbox uses one function type 
> (called filter) for different purposes.
> 
> predicates   a -> Bool
> selectors, transformatorsa -> a
> list-valued functionsa -> [a]
> 
> are all implemented with the one type (a -> [a]).
>
>   In my opinion this means a significant loss of type safety and quality of 
> documentation. Are there more type safe XML/HTML processor libraries in 
> Haskell?

When we were first experimenting with designs that later became
HaXml, we did indeed have separate notions of predicate, transformer,
selector, and so on.  But having lots of different types like this
meant it was more difficult to plug things together nicely into a
combinator framework.  Thus, we decided to squash everything together
into the filter type, so each piece was modular and could fit with
any other piece.  I think it was a good design.

But I take your point that this approach reduces type safety.
One option we considered was to use the DTD "type" of XML document
fragments themselves as a basis for a type system over the combinator
library.  Doubtless this would have required some subtle class
machinery to overload the same operation over many different DTDs.
Maybe even dependent types, subtyping, or union/intersection types
would be needed to get it just right.  In the end, we decided that
the mismatch between DTDs and Hindley-Milner was too great to do a
good job here, so the combinator library remained rather generic
and almost typeless.

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


Re: [Haskell-cafe] predicates in XML toolboxes

2005-04-12 Thread Henning Thielemann
On Tue, 12 Apr 2005, Malcolm Wallace wrote:
Henning Thielemann <[EMAIL PROTECTED]> writes:
The XML toolboxes HaXml, HXML and the XML toolbox uses one function type
(called filter) for different purposes.
predicates   a -> Bool
selectors, transformatorsa -> a
list-valued functionsa -> [a]
are all implemented with the one type (a -> [a]).
  In my opinion this means a significant loss of type safety and quality of
documentation. Are there more type safe XML/HTML processor libraries in
Haskell?
When we were first experimenting with designs that later became
HaXml, we did indeed have separate notions of predicate, transformer,
selector, and so on.  But having lots of different types like this
meant it was more difficult to plug things together nicely into a
combinator framework.  Thus, we decided to squash everything together
into the filter type, so each piece was modular and could fit with
any other piece.  I think it was a good design.
What about providing combinators for the most common cases and provide 
lifting functions for the uncommon cases, such as

liftPred :: (a -> Bool) -> (a -> [a])
liftPred p x = if p x then [x] else []
liftTrans :: (a -> b) -> (a -> [b])
liftTrans f x = [f x]
?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] predicates in XML toolboxes

2005-04-12 Thread Malcolm Wallace
Henning Thielemann <[EMAIL PROTECTED]> writes:

> >> predicates   a -> Bool
> >> selectors, transformatorsa -> a
> >> list-valued functionsa -> [a]
> 
> What about providing combinators for the most common cases and provide 
> lifting functions for the uncommon cases, such as
> 
> liftPred :: (a -> Bool) -> (a -> [a])
> liftPred p x = if p x then [x] else []
> 
> liftTrans :: (a -> b) -> (a -> [b])
> liftTrans f x = [f x]

Looks good.  If you want to come up with a concrete design for an fuller
set of alternative combinators, I'd be happy to include it into HaXml as
a further choice of facility.

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


Re: [Haskell-cafe] Installing and running QuickCheck

2005-04-12 Thread Derek Elkins
On Tue, 12 Apr 2005 10:09:52 +0200
Daniel Fischer <[EMAIL PROTECTED]> wrote:

> Hm,
> 
> no instance Arbitrary Char is provided in the QuickCheck modules that came 
> with my hugs or ghc. Probably the author just forgot to import Data.Char. Try 
> inserting that in QuickCheck.hs.
> 
> Hope that works,
> Daniel

Hugs used to (non-standardly) import some functions from the Char module.  A bit
back on the #haskell channel someone mentioned a similar issue, they also had
issues with fromInt which should likely be replaced with fromIntegral. 
Presumably the Hugs QuickCheck accidently relied on these non-standard aspects.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Thompson's Exercise 9.13

2005-04-12 Thread Hamilton Richards
Here's a solution:
  init :: [a] -> [a]
  init xs = tail (foldr keep [] xs)
where
keep :: a -> [a] -> [a]
keep x []  = [x]
keep x [y] = [x,x]
keep x (y:z:zs)  = x:x:y:zs

--Ham

At 3:44 PM +0900 2005/4/10, Kaoru Hosokawa wrote:
I've been working through Thompson's exercises and got to one I 
could not solve. It's Exercise 9.13. This is where I need to define 
init using foldr.

init :: [a] -> [a]
init "Greggery Peccary" ~> "Greggary Peccar"
This is as far as I got:
init xs = foldr left [] xs
left :: a -> [a] -> [a]
left x []   = []
left x1 : (x2 : xs) = x1 : (left x2 xs)
But this returns [] and doesn't work. I can't get "left" to know 
that it is working with the rightmost element. It just throws away 
every element when its right hand side is empty.

I found a solution that works for Strings, but I am looking for a 
more general solution. This exercise may yet again be one of those 
that is difficult to solve with my current knowledge of Haskell, but 
I'm asking anyway.

--
Kaoru Hosokawa
[EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

--
--
Hamilton Richards, PhD   Department of Computer Sciences
Senior Lecturer  The University of Texas at Austin
512-471-9525 1 University Station C0500
Taylor Hall 5.138Austin, Texas 78712-0233
[EMAIL PROTECTED][EMAIL PROTECTED]
http://www.cs.utexas.edu/users/ham/richards
--
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Thompson's Exercise 9.13

2005-04-12 Thread Henning Thielemann
On Tue, 12 Apr 2005, Hamilton Richards wrote:
Here's a solution:
  init :: [a] -> [a]
  init xs = tail (foldr keep [] xs)
where
keep :: a -> [a] -> [a]
keep x []  = [x]
keep x [y] = [x,x]
keep x (y:z:zs)  = x:x:y:zs
Nice idea!
One case can be eliminated.
init :: [a] -> [a]
init xs = tail (foldr keep [] xs)
  where
keep :: a -> [a] -> [a]
keep x []  = [x]
keep x (_:zs)  = x:x:zs
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Closest analog to popen()

2005-04-12 Thread Dimitry Golubovsky
Hi,

Does there exist any analog of popen in the standard Haskell libraries?

I need to execute an external program (not a Haskell funciton) - maybe
in a shell, being able to feed something to its stdin, and finally
catch the exit code. Does there exist a way to do this without dealing
with multithreading, writing my own ffi and other stuff?

Something like rawSystem, but acting asynchronously (returning a
writeable pipe handle, and a process ID), and later I would use
getProcessStatus to catch the exit code.

PS I have found
http://community.moertel.com/ss/space/Tom's+Haskell+code/POpen.hs
so far, but it does not seem to be part of the standard library.

-- 
Dimitry Golubovsky

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


Re: [Haskell-cafe] Closest analog to popen()

2005-04-12 Thread Donn Cave
On Tue, 12 Apr 2005, Dimitry Golubovsky wrote:
> Does there exist any analog of popen in the standard Haskell libraries?
> 
> I need to execute an external program (not a Haskell funciton) - maybe
> in a shell, being able to feed something to its stdin, and finally
> catch the exit code. Does there exist a way to do this without dealing
> with multithreading, writing my own ffi and other stuff?
> 
> Something like rawSystem, but acting asynchronously (returning a
> writeable pipe handle, and a process ID), and later I would use
> getProcessStatus to catch the exit code.
> 
> PS I have found
> http://community.moertel.com/ss/space/Tom's+Haskell+code/POpen.hs
> so far, but it does not seem to be part of the standard library.

True, but it looks like it might show a way to do this without dealing
with multithreading, writing your own ffi and other stuff.  It sounds
like his popenRaw would work for your application.  As you probably
know, you will need to at least flush output and possibly close the
pipe in order to get all output from the child process, because of
buffering in the respective processes.

Incidentally, if it had been up to me, System.Posix.Process executeFile 
would have taken the entire argv list [0..n].   [1..n] seems like a
gratuitous abridgement to the underlying functionality.

Donn Cave, [EMAIL PROTECTED]

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


[Haskell-cafe] Re: Closest analog to popen()

2005-04-12 Thread John Goerzen
On 2005-04-12, Dimitry Golubovsky <[EMAIL PROTECTED]> wrote:
> Does there exist any analog of popen in the standard Haskell libraries?

Dmitry,

I have one in MissingH, and it's written in pure Haskell.  Reference at
http://quux.org/devel/missingh/html/MissingH.Cmd.html, code at
http://quux.org/devel/missingh.

If you choose to not use that code, and instead write your own, just
know that popen() can be implemented in terms of pipe(), dup(), and
fork() in C -- or createPipe, dupTo, and forkProcess in Haskell.  Take
care to handle SIGCHLD properly -- or, just use my module :-)

-- John

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


Re: [Haskell-cafe] Re: Closest analog to popen()

2005-04-12 Thread Dimitry Golubovsky
Thanks everybody who answered.
Dimitry Golubovsky
Middletown, CT
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Binary file r/w example

2005-04-12 Thread Bo Herlin
Hi, does anyone have a small but complete example on how to read a 
(portion of) a binary file, like r/w the header of a Midi-file?

It seems like readBinaryFile (ans writeBinaryFile) is deprecated and I 
should use hGetBuf (and hPutBuf), but what is this Ptr thing?

How would I implement readBinaryFile using hGetBuf?
Best/
Bo Herlin
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe