Re: [Haskell-cafe] Hackage on Linux

2010-08-25 Thread Ivan Lazar Miljenovic
On 25 August 2010 15:18, Mathew de Detrich dete...@gmail.com wrote:
 The thing is, libraries at least should be automated. There are just way too
 many packages in Hackage for someone to go through and manually check if
 something goes wrong, and you get the issues described previously in
 conflicts of latest version and outdated versions of libraries installed
 through AUR/cabal (and in my case having to manually go through and use
 cabal2arch to fix things was taking up way too much time). C/C++ libraries
 can be checked by hand because there aren't many of them (as mentioned
 earlier) where as the 'Haskell' way of doing things is using lots of
 smaller modularized libraries.

Well, this is my (unofficial policy) of how to deal with libraries and
packages in the Haskell overlay for Gentoo:

* Unless required by the Haskell Platform, etc. keep at most one major
version of each package (for packages like Parsec, keep one 2.x series
and one 3.y series version)

* Don't keep around useless packages: if I find a package that has had
a newer version on Hackage for 6 months or more, then it's quite
likely that no-one cares about that package.  In that case, if it will
be too difficult to build and test a new version (e.g. something
approaching the complexity of yi's ebuild:
http://code.haskell.org/gentoo/gentoo-haskell/app-editors/yi/yi-0.6.2.4.ebuild
) then get rid of it; if the package has rather simple build
requirements, then consider bumping it on a case-by-case basis.

Note that I keep a rather large selection of Haskell packages
installed so that I can keep an eye on when new versions come out
(using cabal update  cabal upgrade --dry-run).  For example, I
don't use yi, but I keep it installed solely because of the large
number of dependencies it has.

About 10 months ago, I went on a spring clean of the overlay; going
alphabetically I got down to Cabal before I gave up due to the sheer
number of packages that were affected by one of the above two
criteria.  Most of the packages removed due to the second criteria
where those that someone thought that looks cool, let's make an
ebuild for it and then it never actually got used.

I add packages typically due to one of two reasons:

* I want that package (or else something I have installed has a new
version that wants that package).

* Someone requests it (preferably via IRC).

Some are still added due to the cool factor; typically I try to
restrain myself from doing so unless I'm also going to install it to
keep track of it (e.g. criterion; I haven't seriously used it but I
keep it installed to also ensure that vector{,algorithms}, statistics,
etc. are kept up-to-date; I also keep hmatrix installed despite only
needing it for one semester a few years back for the same reason).
Otherwise, it's just going to grow out of control.

So, in essence I try to ensure that we keep the overlay as a curated
version of Hackage (and I typically do more package maintenance in the
overlay than kolmodin or slyfox, who play more with GHC, etc.).  I'm
not saying that my decisions are necessarily correct on whether
something is worth keeping or not, but this way we try to avoid creep
of useless, unmaintained distribution packages.

(If there is a package you want that's not in there, either ping me on
IRC or email me; but there are no guarantees of it being kept
up-to-date with the latest version unless I decide I want to install
it myself as well.).

 If people just wanted an auto udpate version of cabal that works through
 arch's package management, then there should have just been a pacman wrapper
 which when you install/update haskell libraries/packages, it creates a local
 package through cabal2arch instead of using AUR.
 You either have everything properly updated (assuming it doesn't fail
 building for w/e reason) or if you want to 'clone' cabal onto AUR, then only
 do it for the necessary/base/required packages which is easy to keep track
 of

Yeah, I don't like that solution, as I mentioned a few emails back: if
nothing else because of the inability of properly tracking non-Haskell
dependencies properly.

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Fwd: Semantics of iteratees, enumerators, enumeratees?

2010-08-25 Thread Heinrich Apfelmus

Stephen Tetley wrote:

John Lato wrote:


This is how I think of them.  I particularly your description of them as a
foldl with a pause button.
Maybe it would be helpful to consider iteratees along with delimited
continuations?


Aren't they closer - in implementation and by supported operations -
to resumptions monads?

See many papers by William Harrison here:
http://www.cs.missouri.edu/~harrisonwl/abstracts.html


A general method to implement resumption monads, or, in fact, any monad, 
 is given in my Operational Monad Tutorial:


   http://apfelmus.nfshost.com/articles/operational-monad.html

Here a tiny toy implementation of Iteratees:

   data IterateeI a where
   Symbol :: IterateeI Char
   EOF:: IterateeI Bool
   type Iteratee = ProgramT IterateeI
   symbol = singleton . Symbol
   eof= singleton . EOF

   runString :: Monad m = Iteratee m a - String - m a
   runString m cs = go cs = viewT m
   where
   go _  (Return x)  = return x
   go [] (Symbol := k) = error Expecting input
   go (c:cs) (Symbol := k) = runString (k c) cs
   go cs (EOF:= k) = runString (k $ null cs) cs

   -- an iteratee that counts the number of elements in the input
   count :: Monad m = Iteratee m Int
   count = go 0
   where
   go n = eof = \b - case b of
   True  - return n
   False - symbol  go $! (n+1)


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com

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


[Haskell-cafe] Re: Fwd: Semantics of iteratees, enumerators, enumeratees?

2010-08-25 Thread Heinrich Apfelmus

Jason Dagit wrote:

Heinrich Apfelmus wrote:


I'm curious, can you give an example where you want to be explicit about
chunking? I have a hard time imagining an example where chunking is
beneficial compared to getting each character in sequence. Chunking
seems to be common in C for reasons of performance, but how does that
apply to Haskell?


[...]
I think it basically comes down to this: We replace lazy io with explicit
chunking because lazy io is unsafe, but explicit chunking can be safe.


Ah, I mean to compare Iteratees with chunking to Iteratees with single 
character access, not to lazy IO.


In C, this would be a comparison between  read  and  getchar . If I 
remember correctly, the former is faster for copying a file simply 
because copying one character at a time with  getchar  is too granular 
(you have to make an expensive system call every time). Of course, this 
reasoning only applies to C and not necessarily to Haskell.


Do you have an example where you want chunking instead of single 
character access?



Supposing we use lazy io (Prelude.readFile):
  1) read the file, compute (a), close the file, read the file, compute (b),
and finally close the file. You can do so in constant space.
  2) read the file, use one pass to calculate both (a) and (b) at the same
time, then close the file. You can do so in constant space.
  3) read the file, use one pass to compute (a) followed by a pass to
compute (b), then close the file.  The space used will be O(filesize).

I consider option #3 to be letting the elements of the stream leak out.
 The computation in (b) references them and thus the garbage collector
doesn't free them between (a) and (b), and the optimizer cannot fuse (a) and
(b) in all cases.


Indeed, Iteratees make it difficult to express option #3, hence 
discouraging this particular space leak. Compared to lazy IO, they also 
make sure that the file handle is closed properly and does not leak.



Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com

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


[Haskell-cafe] Re: Fwd: Semantics of iteratees, enumerators, enumeratees?

2010-08-25 Thread Heinrich Apfelmus

Nicolas Pouillard wrote:

Heinrich Apfelmus wrote:


There are also enumerators and enumeratees. I think that

 purpose of enumerator =
run an iteratee on multiple sources
 (i.e. first part of the input from a  Handle ,
   second part from a  String )


I would say more simply that an enumerator is a data-producer (or source).
Although it is a producer defined as a consumer (or sink) feeder.


Sure, but then why not define them as

   type Enumerator a b = Iteratee a b - IO b

? After all, I imagine a data producer to feed an Iteratee with tokens 
until it has run to completion.



The reason for the definition

   type Enumerator a b = Iteratee a b - IO (Iteratee a b)

is that you can now concatenate different input sources.


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com

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


Re: [Haskell-cafe] Fwd: Semantics of iteratees, enumerators, enumeratees?

2010-08-25 Thread John Lato
From: John Millikin jmilli...@gmail.com


 Here's my (uneducated, half-baked) two cents:

 There's really no need for an Iteratee type at all, aside from the
 utility of defining Functor/Monad/etc instances for it. The core type
 is step, which one can define (ignoring errors) as:

data Step a b = Continue (a - Step a b)
  | Yield b [a]

 Input chunking is simply an implementation detail, but it's important
 that the yield case be allowed to contain (= 0) inputs. This allows
 steps to consume multiple values before deciding what to generate.

 In this representation, enumerators are functions from a Continue to a
 Step.

type Enumerator a b = (a - Step a b) - Step a b

 I'll leave off discussion of enumeratees, since they're just a
 specialised type of enumerator.

 -

 Things become a bit more complicated when error handling is added.
 Specifically, steps must have some response to EOF:

data Step a b = Continue (a - Step a b) (Result a b)
  | Result a b

data Result a b = Yield b [a]
| Error String

 In this representation, Continue has two branches. One for receiving
 more data, and another to be returned if there is no more input. This
 avoids the divergent iteratee problem, since it's not possible for
 Continue to be returned in response to EOF.


Is this really true?  Consider iteratees that don't have a sensible default
value (e.g. head) and an empty stream.  You could argue that they should
really return a Maybe, but then they wouldn't be divergent in other
formulations either.  Although I do find it interesting that EOF is no
longer part of the stream at all.  That may open up some possibilities.

Also, I found this confusing because you're using Result as a data
constructor for the Step type, but also as a separate type constructor.  I
expect this could lead to very confusing error messages (What do you mean
'Result b a' doesn't have type 'Result'?)



 Enumerators are similarly modified, except they are allowed to return
 Continue when their inner data source runs out. Therefore, both the
 continue and eof parameters are Step.

type Enumerator a b = (a - Step a b) - Step a b - Step a b


I find this unclear as well, because you've unpacked the continue parameter
but not the eof.  I would prefer to see this as:
type Enumerator a b = (a - Step a b) - Result a b - Step a b

However, is it useful to do so?  That is, would there ever be a case where
you would want to use branches from separate iteratees?  If not, then why
bother unpacking instead of just using
type Enumerator a b = Step a b - Step a

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


[Haskell-cafe] [CUFP 2010] Birds of a Feather sessions

2010-08-25 Thread Anil Madhavapeddy
=
  Birds of a Feather sessions (BOFs)

  Commercial Uses of Functional Programming Workshop (CUFP 2010)

  http://cufp.org/bofs-2010
  Baltimore, Maryland, September 30 - October 1
=

This year, the Commercial Uses of Function Programming (CUFP)
workshop has a new feature to bring industry and academics together
to promote real-world uses of functional programming. Birds of a
Feature (BoF) sessions provide a place for our community to gather
informally at ICFP and reach consensus on matters of importance.
Any CUFP attendee can propose a BoF session, and grab one of the
spare rooms in the evening slots below.  Attendance in the evening
is open to all.

BoF sessions facilitate ad-hoc discussions and provide a place to
gather and start off the chat, before moving on during the evening
to a local Baltimore restaurant or pub. We particularly encourage
cross-language discussions that might not otherwise happen at one
of the bigger workshops.

Please see http://cufp.org/bofs-2010 for details on how to propose
a slot or confirm attendance at one of them.  There are a couple
of sessions already which may be of interest to Haskell developers:

Thu 30th Sep 6pm-8pm, Haskell for the Real World,
Bryan O'Sullivan and Johan Tibell
http://cufp.org/bofs-2010#haskellrw

Fri 1st Oct 6pm-8pm, Cross Language Serialisation,
Anton Lavrik
http://cufp.org/bofs-2010#xlangserial

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


[Haskell-cafe] Haddock: Documentation of instances with un-documentable type arguments

2010-08-25 Thread Alexander McPhail
Hi,

Here,
http://hackage.haskell.org/packages/archive/graphviz/2999.10.0.1/doc/html/Data-GraphViz-Commands.html#t%3AGraphvizCanvas,
there is an example of the internal implementation leaking.

I was taught to separate interface from implementation.  For example, header
versus c/cc/cpp files.  The privacy of typeclasses of
GeneralNewTypedDeriving'ed variety, such as MonadReader and MonadState,
should be hidable.  I may want the programmer to know my operations, as
provided in the interface, are monadic (and thus sequencable, temporally
deterministic operations) but not allow them to set/get, ask, tell, fetch,
push, throw, or pass my implementational details.

Perhaps Haddock could exclude class instance reporting when it cannot find a
documentable link to a parameter?

Vivian
-- 
---
yolar et elver.
---

DISCLAIMER

This transmission contains information that may be confidential. It is
intended for the named addressee only. Unless you are the named addressee
you may not copy or use it or disclose it to anyone else.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: ANNOUNCE: darcs 2.5 beta 4

2010-08-25 Thread Benjamin Franksen
Benjamin Franksen wrote:
 I have trouble building this latest beta.

I found that the build uses ghc-6.8.3 which, I think, is no longer supported 
for building darcs, IIRC.

Sorry for the noise.

Cheers
Ben


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


[Haskell-cafe] Re: Haddock: Documentation of instances with un-documentable type arguments

2010-08-25 Thread Johannes Waldmann
 Perhaps Haddock could exclude class instance reporting [...]

Instances are global, and cannot be hidden.
You cannot prevent their use, so you might as well document them.

Otherwise you'll have users complaining when they assume
the instance isn't there, and write their own,
and then see the error message, but don't find the explanation
in the documentation.

(rant follows)

Yes, globality is bad. - One could wish for (e.g.)
let foo :: [Foo] = sort bar where instance Ord Foo where ...
Of course this is not Haskell, and that's why there is sortBy etc,
where the extra argument corresponds to the dictionary
of the type class. Presumably this could be hidden as an
implicit parameter, so I guess local instances could be made to work.
And local types as well? Sometimes I want them.

Heretically speaking, since Java has this (local types),
1. there must be a reason, and 2. there is a way to implement it
(well, at least something like it).

J.W.

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


Re: [Haskell-cafe] Re: Fwd: Semantics of iteratees, enumerators, enumeratees?

2010-08-25 Thread John Lato

 From: Heinrich Apfelmus apfel...@quantentunnel.de

 Jason Dagit wrote:
  Heinrich Apfelmus wrote:
 
  I'm curious, can you give an example where you want to be explicit about
  chunking? I have a hard time imagining an example where chunking is
  beneficial compared to getting each character in sequence. Chunking
  seems to be common in C for reasons of performance, but how does that
  apply to Haskell?
 
  [...]
  I think it basically comes down to this: We replace lazy io with explicit
  chunking because lazy io is unsafe, but explicit chunking can be safe.

 Ah, I mean to compare Iteratees with chunking to Iteratees with single
 character access, not to lazy IO.

 In C, this would be a comparison between  read  and  getchar . If I
 remember correctly, the former is faster for copying a file simply
 because copying one character at a time with  getchar  is too granular
 (you have to make an expensive system call every time). Of course, this
 reasoning only applies to C and not necessarily to Haskell.

 Do you have an example where you want chunking instead of single
 character access?


I am unable to think of any examples where you want chunking for any reason
other than efficiency.  Yesterday I spent some time on an element-wise
iteratee implementation, and unfortunately it's significantly slower than
any of the chunked implementations.  I'm certain there's room for
optimization, but I don't know if it's possible to make up the whole
difference.  I'd need to make some examination of the core to figure out
where it could be improved.

It's also possible that certain other implementations, such as your ProgramT
version or the simplified implementation John Millikin recently posted to
this list, would be more amenable to compiler magic for this purpose.

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


Re: [Haskell-cafe] Re: Haddock: Documentation of instances with un-documentable type arguments

2010-08-25 Thread Ivan Lazar Miljenovic
On 25 August 2010 21:36, Johannes Waldmann waldm...@imn.htwk-leipzig.de wrote:
 Perhaps Haddock could exclude class instance reporting [...]

 Instances are global, and cannot be hidden.
 You cannot prevent their use, so you might as well document them.

Yes you can; in that example Alexander linked to before, you can't use
the class methods of GraphvizResult; try it, they are:

outputCall :: (GraphvizResult o) = o - String
isBinary :: (GraphvizResult o) = o - Bool

In this case, the class is one defined inside that module and used
solely for those two data types; it isn't exported, and the only way
you can tell it exists is that Haddock mentions the instances.

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Haddock: Documentation of instances with un-documentable type arguments

2010-08-25 Thread Johannes Waldmann

 In this case, the class is one defined inside that module and used
 solely for those two data types; it isn't exported, and the only way
 you can tell it exists is that Haddock mentions the instances.

OK. 

I was confused because the text of the posting
mentioned MonadReader and MonadState (and their methods set/get/ask/...), 
which are globally known.

J.W.




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


Re: [Haskell-cafe] Re: Fwd: Semantics of iteratees, enumerators, enumeratees?

2010-08-25 Thread Daniel Fischer
On Wednesday 25 August 2010 13:53:47, John Lato wrote:
  From: Heinrich Apfelmus apfel...@quantentunnel.de
 
  Do you have an example where you want chunking instead of single
  character access?

 I am unable to think of any examples where you want chunking for any
 reason other than efficiency.

For many hashing or de/encryption algorithms, chunking is more natural than 
single-character access.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haddock: Documentation of instances with un-documentable type arguments

2010-08-25 Thread David Waern
2010/8/25 Alexander McPhail haskell.vivian.mcph...@gmail.com:

 Perhaps Haddock could exclude class instance reporting when it cannot find a
 documentable link to a parameter?

Yes, it should. BTW, we have a trac ticket for it:

  http://trac.haskell.org/haddock/ticket/37

You can add yourself to the CC list to show that you want this feature.

Currently we don't have many people working on these types of tickets
in Haddock (I'm mostly fixing bugs, others are working on bigger
improvements), so if more people would volunteer to help out, that'd
be great. The mailing list hadd...@projects.haskell.org can be used to
ask for directions and help.

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


Re: [Haskell-cafe] Fwd: Semantics of iteratees, enumerators, enumeratees?

2010-08-25 Thread John Millikin
On Wed, Aug 25, 2010 at 01:33, John Lato jwl...@gmail.com wrote:
 Is this really true?  Consider iteratees that don't have a sensible default
 value (e.g. head) and an empty stream.  You could argue that they should
 really return a Maybe, but then they wouldn't be divergent in other
 formulations either.  Although I do find it interesting that EOF is no
 longer part of the stream at all.  That may open up some possibilities.

Divergent iteratees, using the current libraries, will simply throw an
exception like enumEOF: divergent iteratee. There's no way to get
useful values out of them. Disallowing returning Continue when given
an EOF prevents this invalid state.

 Also, I found this confusing because you're using Result as a data
 constructor for the Step type, but also as a separate type constructor.  I
 expect this could lead to very confusing error messages (What do you mean
 'Result b a' doesn't have type 'Result'?)

Oh, sorry, those constructors should be something like this (the
system on which I wrote that email has no Haskell compiler, so I
couldn't verify types before sending):

   data Step a b = Continue (a - Step a b) (Result a b)
 | GotResult (Result a b)

The goal is to let the iteratee signal three states:

* Can accept more input, but terminating the stream now is acceptable
* Requires more input, and terminating the stream now is an error
* Cannot accept more input

 I find this unclear as well, because you've unpacked the continue parameter
 but not the eof.  I would prefer to see this as:
     type Enumerator a b = (a - Step a b) - Result a b - Step a b

 However, is it useful to do so?  That is, would there ever be a case where
 you would want to use branches from separate iteratees?  If not, then why
 bother unpacking instead of just using
 type Enumerator a b = Step a b - Step a

When an enumerator terminates, it needs to pass control to the next
enumerator (the final enumerator is enumEOF). Thus, the second step
parameter is actually the next enumerator to run in the chain (aka the
calling enumerator).
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [darcs-users] ANNOUNCE: darcs 2.5 beta 4

2010-08-25 Thread Eric Kow
On Wed, Aug 25, 2010 at 13:01:59 +0200, Benjamin Franksen wrote:
 I found that the build uses ghc-6.8.3 which, I think, is no longer supported 
 for building darcs, IIRC.
 
 Sorry for the noise.

Not noise because it resulted in http://bugs.darcs.net/patch365
which attempts to enforce this dependency by raising the base
package floor from = 3 to =4, which I imagine is not a mistake.

I'm keeping the haskell-cafe CC because I was puzzled for a while about
how to make Darcs explicitly depend on GHC 6.10 and wanted to share the
steps I eventually took:

1. visit GHC download page (we're looking for older versions)
   http://www.haskell.org/ghc/download.html

2. scroll down to earliest GHC 6.10

3. click on release notes

4. search for 'base package'

Maybe somebody will shout if this turns out to be the wrong way to
approach things, or if it's fundamentally unwise.

-- 
Eric Kow http://www.nltg.brighton.ac.uk/home/Eric.Kow
For a faster response, try +44 (0)1273 64 2905 or
xmpp:ko...@jabber.fr (Jabber or Google Talk only)


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


Re: [Haskell-cafe] Function signatures and type class constraints

2010-08-25 Thread Oscar Finnsson
Thanks for the tip. You saved my day (and code)!

So what is the point of having the constraint on the left side of the
'='? Will it allow me to do anything that the right-side constraint
won't?

-- Oscar

On Mon, Aug 23, 2010 at 11:06 PM, Daniel Fischer
daniel.is.fisc...@web.de wrote:
 On Monday 23 August 2010 22:30:03, Oscar Finnsson wrote:
 Hi,

 I'm wondering why I have to repeat the class constraints at every
 function.

 If I got the data type

  data (Eq a, Show a, Data a, Eq b, Show b, Data b, Eq c, Show c, Data
  c) = Foo a b c = Foo a b c


 Type class constraints on datatypes are considered a wart. They don't do
 what people expect, in particular they don't make the constraints available
 at the use site.

 It works if you move the constraints across the '=':

 {-# LANGUAGE ExistentialQuantification #-}

 data Foo a b c = (Eq a, Show a, ...) = Foo a b c

 or with GADT syntax:

 {-# LANGUAGE GADTs #-}

 data Foo x y z where
  Foo :: (Eq a, Show a, ...) = a - b - c - Foo a b c

 Both make the constraints available at the use site,

 bar :: Foo a b c - String
 bar (Foo a b c)
    = Foo  ++ show a ++   ++ show b ++   ++ show c ++ , Yay!

 and then a function from Foo to String I have to supply the signature

  bar :: (Eq a, Show a, Data a, Eq b, Show b, Data b, Eq c, Show c, Data
  c) = Foo a b c - String

 even though it should be clear that a, b and c *must* fulfill the
 constraints already so I should be able to just supply the signature

 One would think so. It's a wart.


  bar :: Foo a b c - String


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


Re: [Haskell-cafe] Code that writes code

2010-08-25 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 8/24/10 17:51 , Richard O'Keefe wrote:
 On Aug 22, 2010, at 7:34 PM, Jesse Schalken wrote:
 I would also like to strongly discourage code generators.
 
 I've used ad hoc code generators a lot, and never had
 reason to regret it.
 
 The key point is that ALL maintenance of the generated code
 must be done by maintaining the generator and its input,
 NOT by patching the output.

I have one additional exception:  I will sometimes autogenerate a skeleton
by e.g. grepping over a source tree.  This has the opposite constraint:
once generated, you don't regenerate it unless you can characterize it well
enough that you can treat it as above; but usually it's a one-time code
refactoring.

- -- 
brandon s. allbery [linux,solaris,freebsd,perl]  allb...@kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university  KF8NH
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkx1VcMACgkQIn7hlCsL25WYTQCglf5U3GZNVLO/Zta42IXcztzj
uJQAnRKE5svSoYMag0gb3YIeDfuc3AMn
=52i1
-END PGP SIGNATURE-
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Function signatures and type class constraints

2010-08-25 Thread Ryan Ingram
It uses less space.

Conceptually:
 data X a = Num a = ConX a

looks like this in memory:
{ ConX tag, a, proof of Num a }

where the proof is usually a pointer to the dictionary for that
typeclass at that type.

Whereas
 data Num a = Y a = ConY a

looks like this:
{ ConY tag, a }

This is why the rhs constraint lets you access methods of the
typeclass inside the function; pattern matching on ConX provides a Num
dictionary for the code to call.  For ConY, it has to get that
dictionary from somewhere-- the caller has to pass it in.

  -- ryan

On Wed, Aug 25, 2010 at 9:59 AM, Oscar Finnsson
oscar.finns...@gmail.com wrote:
 Thanks for the tip. You saved my day (and code)!

 So what is the point of having the constraint on the left side of the
 '='? Will it allow me to do anything that the right-side constraint
 won't?

 -- Oscar

 On Mon, Aug 23, 2010 at 11:06 PM, Daniel Fischer
 daniel.is.fisc...@web.de wrote:
 On Monday 23 August 2010 22:30:03, Oscar Finnsson wrote:
 Hi,

 I'm wondering why I have to repeat the class constraints at every
 function.

 If I got the data type

  data (Eq a, Show a, Data a, Eq b, Show b, Data b, Eq c, Show c, Data
  c) = Foo a b c = Foo a b c


 Type class constraints on datatypes are considered a wart. They don't do
 what people expect, in particular they don't make the constraints available
 at the use site.

 It works if you move the constraints across the '=':

 {-# LANGUAGE ExistentialQuantification #-}

 data Foo a b c = (Eq a, Show a, ...) = Foo a b c

 or with GADT syntax:

 {-# LANGUAGE GADTs #-}

 data Foo x y z where
  Foo :: (Eq a, Show a, ...) = a - b - c - Foo a b c

 Both make the constraints available at the use site,

 bar :: Foo a b c - String
 bar (Foo a b c)
    = Foo  ++ show a ++   ++ show b ++   ++ show c ++ , Yay!

 and then a function from Foo to String I have to supply the signature

  bar :: (Eq a, Show a, Data a, Eq b, Show b, Data b, Eq c, Show c, Data
  c) = Foo a b c - String

 even though it should be clear that a, b and c *must* fulfill the
 constraints already so I should be able to just supply the signature

 One would think so. It's a wart.


  bar :: Foo a b c - String


 ___
 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 signatures and type class constraints

2010-08-25 Thread Daniel Fischer
On Wednesday 25 August 2010 18:59:26, Oscar Finnsson wrote:
 Thanks for the tip. You saved my day (and code)!

 So what is the point of having the constraint on the left side of the
 '='?

I don't really know. What it does is preventing users from constructing 
values with arguments whose types don't satisfy the constraints.
That probably seemed more useful before the experience than it really is.

Says the report:
http://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-680004.2

For example, the declaration
  data Eq a = Set a = NilSet | ConsSet a (Set a)

introduces a type constructor Set of kind ∗→∗, and constructors NilSet and 
ConsSet with types
NilSet ::  ∀ a.  Set  a
ConsSet ::  ∀ a.  Eq   a  ⇒  a  →  Set   a  →  Set   a
In the example given, the overloaded type for ConsSet ensures that ConsSet 
can only be applied to values whose type is an instance of the class Eq. 
Pattern matching against ConsSet also gives rise to an Eq a constraint. For 
example:
  f (ConsSet a s) = a

the function f has inferred type Eq a = Set a - a. The context in the 
data declaration has no other effect whatsoever.

ghci case (NilSet :: Set (Int - Bool)) of { NilSet - True; _ - False }
True

Note that the constraint doesn't apply to NilSet, because that constructor 
has no arguments (how the context on the data declaration is mapped to type 
class constraints on the constructors is explained in the report).

 Will it allow me to do anything that the right-side constraint
 won't?


Nothing useful, as far as I know.

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


Re: [Haskell-cafe] Hackage on Linux

2010-08-25 Thread Joachim Breitner
Hi,

Am Mittwoch, den 25.08.2010, 12:03 +1000 schrieb Ivan Lazar Miljenovic:
 On 24 August 2010 21:18, Joachim Breitner m...@joachim-breitner.de wrote:
  Am Dienstag, den 24.08.2010, 09:30 +0100 schrieb Magnus Therning:
  On Tue, Aug 24, 2010 at 06:50, Mathew de Detrich dete...@gmail.com wrote:
   - in some situations doing a general update with arch (through clyde or
   packer)  breaks ghc (last time it happened packer tried to 
   uninstall/update
   arch packages which failed because those packages had dependencies. The
   files got removed but since unregister failed ghc thought they still
   existed)
 
  This is arguably an error in the Arch packages.  The dependencies aren't 
  quite
  as strict as they really should be.  I've taken the approach of never 
  letting
  pacman update any haskell-* package.  Instead I do a small song-and-dance
  where I first remove the packages in question, and any package that 
  depends on
  them, then I re-install what I just removed.
 
  In Debian, this cannot happen any more, as libraries are tied to the
  packages of their dependencies via the ABI hash used by ghc. (If I am
  correctly understanding the symptoms). So using apt-get upgrade will
  never break any Debian-installed packages.
 
 Interesting; I've been discussing with Ciaran McCreesh on a
 possibility of getting something like that into Paludis for use with
 Exherbo (a few non-Haskell related things are starting to annoy me
 with the petty politics, etc. of Gentoo and Exherbo has some really
 nice ideas).  How exactly do you do this?  Register the ABI hash upon
 installation and check if it ever changes?  Or is this all done when
 you build the package since Debian uses binary packages?

the latter. Build-Dependencies are unversioned or matching the Cabal
range. At build time, the ABI of the library is used to construct the
name of a „virtual package“ which is then Provide:’ed. For each
dependency, the „virtual package“ containing the hash is depended upon.
The code is at
http://darcs.debian.org/pkg-haskell/haskell-devscripts/
and the (not particularly pretty) result can be seen at
http://packages.debian.org/sid/libghc6-xmonad-contrib-dev

  OTOH, you cannot expect Debian to always and immediately install the
  latest Cabal versions – there are possibly good reasons for not
  upgrading.
 
 Yes, least of which is someone spending the time to notice that a
 package is out of date and bothering to update it + test that update
 (including any packages that depend upon it).

..and consider whether the update is an improvement and worth the
trouble. New is not always better.

Greetings,
Joachim

-- 
Joachim nomeata Breitner
  mail: m...@joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C
  JID: nome...@joachim-breitner.de | http://www.joachim-breitner.de/
  Debian Developer: nome...@debian.org


signature.asc
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] Low level problem with Data.Text.IO

2010-08-25 Thread Pieter Laeremans
Hello,

I have a strange (low level) problem with the Data.Text library.

Running the simple program below on a certain text file causes a low level
error.


 runghc ./ReadFiles.hs testfile
ghc(16402,0xb0103000) malloc: *** error for object 0x2501710: pointer being
freed was not allocated
*** set a breakpoint in malloc_error_break to debug
ghc(16402,0xb0103000) malloc: *** error for object 0x2501710: pointer being
freed was not allocated
*** set a breakpoint in malloc_error_break to debug
ReadFiles.hs: testfile: hGetContents: invalid argument (Illegal byte
sequence)


module Main where

import qualified Data.Text.IO as TI
import qualified Data.Text as T
import System


main = do
  args - getArgs
  let fileName:_  = args
  txt - TI.readFile fileName

  putStrLn $ show txt


Unfortunately I can 't post the specific data file.
But according to the file program it is a text file with :
 Non-ISO extended-ASCII text, with very long lines, with CRLF, LF line
terminators encoding.


How can I debug this problem ? What would you guys do ?  Trying gdb ?

 thanks in advance,

Pieter


-- 
Pieter Laeremans pie...@laeremans.org

The future is here. It's just not evenly distributed yet.  W. Gibson
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Low level problem with Data.Text.IO

2010-08-25 Thread Bryan O'Sullivan
On Wed, Aug 25, 2010 at 1:34 PM, Pieter Laeremans pie...@laeremans.orgwrote:


 I have a strange (low level) problem with the Data.Text library.


Thanks for bringing this up.


 Running the simple program below on a certain text file causes a low level
 error.


This only happens on a single file? Can you mail it to me directly, perhaps?

I might be able to reproduce it based on the Illegal byte sequence error
you are seeing, which makes me think it's not a UTF-8-encoded file, but that
low-level crash should of course not happen.

What version of GHC and the text library are you using?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Type families - how to resolve ambiguities?

2010-08-25 Thread DavidA
Hi,

The code below defines a type synonym family:

{-# LANGUAGE MultiParamTypeClasses, TypeFamilies #-}
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}

data Vect k b = V [(b,k)] deriving (Eq,Show)

data TensorBasis a b = T a b deriving (Eq, Ord, Show)

type family Tensor k u v :: *

type instance Tensor k (Vect k a) (Vect k b) = Vect k (TensorBasis a b) 

class Algebra k v where -- v is a k-algebra
unit :: k - v
mult :: Tensor k v v - v

instance Algebra Integer (Vect Integer [Int]) where
unit 0 = V []
unit x = V [([],x)]
mult (V ts) = V [(g++h,x) | (T g h, x) - ts]

Naively I think of the type instance declaration as saying that the two types
are synonyms, so I should be able to use one in a context where the other
is expected. However, when I try to use the code, I don't seem to be able
to get the type inferencer to recognise an object as being of both types at
the same time. For example:

* mult $ (V [(T [1] [2],3)] :: Vect Integer (TensorBasis [Int] [Int]))

interactive:1:8:
Couldn't match expected type `Tensor k v v'
   against inferred type `Vect Integer (TensorBasis [Int] [Int])'
  NB: `Tensor' is a type function, and may not be injective
In the second argument of `($)', namely
`(V [(T [1] [2], 3)] :: Vect Integer (TensorBasis [Int] [Int]))'
In the expression:
  mult
$ (V [(T [1] [2], 3)] :: Vect Integer (TensorBasis [Int] [Int]))
In the definition of `it':
it = mult
   $ (V [(T [1] [2], 3)] :: Vect Integer (TensorBasis [Int] [Int]))


* mult $ (V [(T [1] [2],3)] :: Tensor Integer (Vect Integer [Int])
(Vect Integer [Int]))

interactive:1:8:
Couldn't match expected type `Tensor k v v'
   against inferred type `Vect Integer (TensorBasis [Int] [Int])'
  NB: `Tensor' is a type function, and may not be injective
In the second argument of `($)', namely
`(V [(T [1] [2], 3)] ::
Tensor Integer (Vect Integer [Int]) (Vect Integer [Int]))'
In the expression:
  mult
$ (V [(T [1] [2], 3)] ::
 Tensor Integer (Vect Integer [Int]) (Vect Integer [Int]))
In the definition of `it':
it = mult
   $ (V [(T [1] [2], 3)] ::
Tensor Integer (Vect Integer [Int]) (Vect Integer [Int]))

Are type families the right mechanism to express what I'm trying to express?
If so, what am I doing wrong, and how do I fix it?


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


Re: [Haskell-cafe] Type families - how to resolve ambiguities?

2010-08-25 Thread Dan Doel
On Wednesday 25 August 2010 5:05:11 pm DavidA wrote:
 Hi,
 
 The code below defines a type synonym family:
 
 {-# LANGUAGE MultiParamTypeClasses, TypeFamilies #-}
 {-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
 
 data Vect k b = V [(b,k)] deriving (Eq,Show)
 
 data TensorBasis a b = T a b deriving (Eq, Ord, Show)
 
 type family Tensor k u v :: *
 
 type instance Tensor k (Vect k a) (Vect k b) = Vect k (TensorBasis a b)
 
 class Algebra k v where -- v is a k-algebra
 unit :: k - v
 mult :: Tensor k v v - v
 
 instance Algebra Integer (Vect Integer [Int]) where
 unit 0 = V []
 unit x = V [([],x)]
 mult (V ts) = V [(g++h,x) | (T g h, x) - ts]
 
 Naively I think of the type instance declaration as saying that the two
 types are synonyms, so I should be able to use one in a context where the
 other is expected. However, when I try to use the code, I don't seem to be
 able to get the type inferencer to recognise an object as being of both
 types at the same time. For example:
 
 Are type families the right mechanism to express what I'm trying to
 express? If so, what am I doing wrong, and how do I fix it?

The problem with mult is that k is not specified unambiguously. You either 
need v to determine k (which is probably not what you want, at a guess), mult 
to take a dummy argument that determines what k is:

  mult :: k - Tensor k v v - v

or

  mult :: D k - Tensor k v v - v  -- D k being some datatype

or, to make Tensor a data family instead of a type family.

If you used functional dependencies, for instance, this would be something 
like:

  class Algebra k v t | k v - t where
unit :: k - v
mult :: t - v

and mult is obviously problematic in not mentioning all the necessary 
parameters.

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


[Haskell-cafe] ANN: Bugfix release for timezone-olson

2010-08-25 Thread Yitzchak Gale
Version 0.1.1 of the timezone-olson package is now
available on Hackage.

http://hackage.haskell.org/package/timezone-olson

The timezone-olson package provides a parser and renderer
for binary Olson timezone files whose format is specified
by the tzfile(5) man page on Unix-like systems. These files
are often found in /usr/share/zoneinfo on Unix-like systems.
Functions are provided for converting the parsed data into
TimeZoneSeries objects from the timezone-series package.

Now that Version 2 format Olson files are beginning to
appear in the wild, we can see the full details of how the
specification in the tzfile(5) man page is applied in real
life. This release fixes several bugs related to parsing
and rendering Version 2 format Olson files, as well as
a few other small issues. Updating is recommended.

A new version of the timezone-series package, also
version 0.1.1, is also now available on Hackage.

http://hackage.haskell.org/package/timezone-olson

The timezone-series package endows Data.Time, from the
time package, with several data types and functions for
enhanced processing of timezones. Among them is
TimeZoneSeries,which represents all of the clock settings
that occur in a time zone, and functions to convert
between UTCTime and LocalTime without knowing in
advance what clock setting is in effect at the given moment.

This release of timezone-series only adds a few type
signatures and more documentation for isValidLocalTime
and isRedundantLocalTime and friends. Aristid Breitkreuz
provided a proof for the basic fact about time change
gaps and overlaps that is used to implement them.
The proof can be seen here:

http://projects.haskell.org/time-ng/gaps_and_overlaps.html

Many thanks to Aristid who, in addition to providing
the above proof, assisted in finding bugs and preparing
for the release of these two updates.

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


Re: [Haskell-cafe] Low level problem with Data.Text.IO

2010-08-25 Thread John Millikin
For debugging the error, we'll need to know what your locale's
encoding is. You can see this by echoing the $LANG environment
variable. For example:

$ echo $LANG
en_US.UTF-8

means my encoding is UTF-8.

Haskell doesn't currently have any decoding libraries with good error
handling (that I know of), so you might need to use an external
library or program.

My preference is Python, since it has very descriptive errors. I'll
load a file, attempt to decode it with my locale encoding, and then
see what errors pop up:

$ python
 content = open(testfile, rb).read()
 text = content.decode(utf-8)
Traceback (most recent call last):
  File stdin, line 1, in module
UnicodeDecodeError: 'utf8' codec can't decode byte 0x9d in position 1:
unexpected code byte

The exact error will help us generate a test file to reproduce the problem.

If you don't see any error, then the bug will be more difficult to
track down. Compile your program into a binary (ghc --make
ReadFiles.hs) and then run it with gdb, setting a breakpoint in the
malloc_error_break procedure:

$ ghc --make ReadFiles.hs
$ gdb ./ReadFiles
(gdb) break malloc_error_break
(gdb) run testfile

... program runs ...
BREAKPOINT

(gdb) bt

stack trace here, copy and paste it into an email for us

The stack trace might help narrow down where the memory corruption is occuring.

-

If you don't care much about debugging, and just want to read the file:

First step is to figure out what encoding the file's in. Data.Text.IO
is intended for decoding files in the system's local encoding
(typically UTF-8), not general-purpose this file has letters in it
IO. Web browsers are pretty good at auto-detecting encodings. For
example, if you load the file into Firefox and then look at the (View
- Character Encoding) menu, which option is selected?

Next, you'll need to read the file in as bytes and then decode it. Use
Data.ByteString.hGetContents to read it in.

If it's encoded in one of the common UTF encodings (UTF-8, UTF-16,
UTF-32), then you can use the functions in Data.Text.Encoding to
convert from the file's bytes to text.

If it's an unusual encoding (windows-1250, shift_jis, gbk, etc) then
you'll need a decoding library like text-icu. Create the proper
decoder, feed in the bytes, receive text.

If all else fails, you can use this function to decode the file as
iso8859-1, but it'll be too slow to use on any file larger than a few
dozen megabytes. Furthermore, it will likely cause any special
characters in the file to become corrupted.

import Data.ByteString.Char8 as B8
import Data.Text as T

iso8859_1 :: ByteString - Text
iso8859_1 = T.pack . B8.unpack

If any corruption occurs, please reply with *what* characters were
corrupted; this might help us reproduce the error.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] foreign function interface Invalid type signature

2010-08-25 Thread Ken Takusagawa
What am I doing wrong?

module Ffi2 where
{
import Foreign.C.Types;

foo :: CInt - CInt;
foo x = x;

foreign export ccall foo :: CInt - CInt;

}

$ ghc -c Ffi2.hs

Ffi2.hs:8:0: Invalid type signature

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


Re: [Haskell-cafe] foreign function interface Invalid type signature

2010-08-25 Thread Ivan Lazar Miljenovic
On 26 August 2010 10:41, Ken Takusagawa ken.takusagaw...@gmail.com wrote:
 What am I doing wrong?

 module Ffi2 where
 {
 import Foreign.C.Types;

 foo :: CInt - CInt;
 foo x = x;

 foreign export ccall foo :: CInt - CInt;

 }

Did you enable the


 $ ghc -c Ffi2.hs

 Ffi2.hs:8:0: Invalid type signature

You need to call it with -XForeignFunctionInterface to enable FFI methinks.


-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] foreign function interface Invalid type signature

2010-08-25 Thread Ken Takusagawa
Thanks, that fixed it.

On Aug 25, 2010 8:47 PM, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com
wrote:
 On 26 August 2010 10:41, Ken Takusagawa ken.takusagaw...@gmail.com
wrote:
 What am I doing wrong?

 module Ffi2 where
 {
 import Foreign.C.Types;

 foo :: CInt - CInt;
 foo x = x;

 foreign export ccall foo :: CInt - CInt;

 }

 Did you enable the


 $ ghc -c Ffi2.hs

 Ffi2.hs:8:0: Invalid type signature

 You need to call it with -XForeignFunctionInterface to enable FFI
methinks.


 --
 Ivan Lazar Miljenovic
 ivan.miljeno...@gmail.com
 IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Low level problem with Data.Text.IO

2010-08-25 Thread Bryan O'Sullivan
On Wed, Aug 25, 2010 at 1:34 PM, Pieter Laeremans pie...@laeremans.orgwrote:


 I have a strange (low level) problem with the Data.Text library.


Thanks again for your bug report, Pieter. I've reproduced it, written a
HUnit test for it, fixed it (the HUnit test is to ensure that it stays
fixed), and pushed the fix to the main darcs repo (
http://code.haskell.org/text).

The next version of text is almost ready to release. Until then, building
and running from darcs should be fine.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] How to generate dependend values with QuickCheck

2010-08-25 Thread Jürgen Nicklisch-Franken
I want to generate values, so that i have some arbitrary object, which has a
certain set of signals, and each set of signals has a certain set of sensor
value pairs, were the values are arbitrary.
However to demonstrate my problem I have an easy example, were I want to
generate an instance of

data QCExample =  QCExample Int Int
deriving Show

and the second value should always be the double of the first. So I tried
this:

instance Arbitrary QCExample where
arbitrary =
let i1 = arbitrary
i2 = fmap (* 2) i1
in liftM2 QCExample i1 i2

but showing some of the generated test cases in ghci does not give me what I
expected:

let gen :: Gen (QCExample) =  arbitrary
Test.QuickCheck.Gen.sample gen

 QCExample (-2) 0
 QCExample (-4) (-6)
 QCExample 3 30
 ...
I know that I can filter, but this would be to inefficient.

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


Re: [Haskell-cafe] How to generate dependend values with QuickCheck

2010-08-25 Thread John Millikin
You're generating two random values, where you probably want to just
generate one and then calculate the second from it. Try this:

instance Arbitrary QCExample where
arbitrary = do
i1 - arbitrary
return (QCExample i1 (i1 * 2))

2010/8/25 Jürgen Nicklisch-Franken j...@arcor.de:
 I want to generate values, so that i have some arbitrary object, which has a
 certain set of signals, and each set of signals has a certain set of sensor
 value pairs, were the values are arbitrary.
 However to demonstrate my problem I have an easy example, were I want to
 generate an instance of

 data QCExample =  QCExample Int Int
     deriving Show

 and the second value should always be the double of the first. So I tried
 this:

 instance Arbitrary QCExample where
     arbitrary =
     let i1 = arbitrary
     i2 = fmap (* 2) i1
     in liftM2 QCExample i1 i2

 but showing some of the generated test cases in ghci does not give me what I
 expected:

 let gen :: Gen (QCExample) =  arbitrary
 Test.QuickCheck.Gen.sample gen

 QCExample (-2) 0
 QCExample (-4) (-6)
 QCExample 3 30
 ...
 I know that I can filter, but this would be to inefficient.

 Jürgen

 ___
 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 generate dependend values with QuickCheck

2010-08-25 Thread Edward Z. Yang
Excerpts from Jürgen Nicklisch-Franken's message of Wed Aug 25 23:32:51 -0400 
2010:
 instance Arbitrary QCExample where
 arbitrary =
 let i1 = arbitrary
 i2 = fmap (* 2) i1
 in liftM2 QCExample i1 i2

What's happening here is that you are evaluating the random value generator
too late in the game: when you set i1 = arbitrary, no random value has been
generated yet, and i2 is thus another generator which has no relation to
what i1 might produce.  You could instead do this:

arbitrary = do
i1 - arbitrary
let i2 = i1 * 2
return (QCExample i1 i2)

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


Re: [Haskell-cafe] How to generate dependend values with QuickCheck

2010-08-25 Thread Ivan Lazar Miljenovic
2010/8/26 Jürgen Nicklisch-Franken j...@arcor.de:
 I want to generate values, so that i have some arbitrary object, which has a
 certain set of signals, and each set of signals has a certain set of sensor
 value pairs, were the values are arbitrary.
 However to demonstrate my problem I have an easy example, were I want to
 generate an instance of

 data QCExample =  QCExample Int Int
     deriving Show

 and the second value should always be the double of the first. So I tried
 this:

 instance Arbitrary QCExample where
     arbitrary =
     let i1 = arbitrary
     i2 = fmap (* 2) i1
     in liftM2 QCExample i1 i2

You're saying that i1 is equal to the arbitrary action, not the result
of such an action.  As such, i2 is based upon a different arbitrary
action.

Consider this:

instance Arbitrary QCExample where
arbitrary = do i1 - arbitrary
 let i2 = 2*i1
 return $ QCExample i1 i2

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to generate dependend values with QuickCheck

2010-08-25 Thread Jürgen Nicklisch-Franken
Thank you all, (you are responding so quick that I consider to stop
thinking myself in the future and just ask).
Jürgen

Am Donnerstag, den 26.08.2010, 00:02 -0400 schrieb Edward Z. Yang:
 Excerpts from Jürgen Nicklisch-Franken's message of Wed Aug 25 23:32:51 -0400 
 2010:
  instance Arbitrary QCExample where
  arbitrary =
  let i1 = arbitrary
  i2 = fmap (* 2) i1
  in liftM2 QCExample i1 i2
 
 What's happening here is that you are evaluating the random value generator
 too late in the game: when you set i1 = arbitrary, no random value has been
 generated yet, and i2 is thus another generator which has no relation to
 what i1 might produce.  You could instead do this:
 
 arbitrary = do
 i1 - arbitrary
 let i2 = i1 * 2
 return (QCExample i1 i2)
 
 Cheers,
 Edward


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


Re: [Haskell-cafe] How to generate dependend values with QuickCheck

2010-08-25 Thread Ivan Lazar Miljenovic
2010/8/26 Jürgen Nicklisch-Franken j...@arcor.de:
 Thank you all, (you are responding so quick that I consider to stop
 thinking myself in the future and just ask).

No, no, don't stop thinking: if you stop thinking, how are you going
to be able to instantly answer someone else's question?

(You are aware that a condition of asking anything on this mailing
list requires you to answer at least 3 questions from other people in
return, aren't you? :p)

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] On to applicative

2010-08-25 Thread michael rice
From: http://en.wikibooks.org/wiki/Haskell/Applicative_Functors

=
import Control.Applicative

f :: (a - b - c)
fmap :: Functor f = (d - e) - f d - f e
fmap f :: Functor f = f a - f (b - c)    -- Identify d with a, and e with (b 
- c)

sumsqr :: Int - Int - Int    -- my f
sumsqr i j = i*i+j*j
=

I'm trying to understand how the above works but... 

[mich...@localhost ~]$ ghci
GHCi, version 6.12.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude :l bozo.hs
[1 of 1] Compiling Main ( bozo.hs, interpreted )

bozo.hs:5:0: Invalid type signature
Failed, modules loaded: none.
Prelude 


Michael




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