Re: [Haskell-cafe] parsec: parserFail multiple error messages

2012-08-09 Thread Christian Maeder
The error message can be improved in your examples by using count 5 
instead of many1.


C.

Am 08.08.2012 21:24, schrieb silly:

I am trying to create a parsec parser that parses an integer and then
checks if that integer has the right size. If not, it generates an
error.
I tried the following:

8---
import Text.Parsec
import Text.Parsec.String

integer :: Parser Int
integer  = do s - many1 digit
   let n = read s
   if n  65535 then
   parserFail integer overflow
   else
   return n
8---

The problem is that when I try this

parse integer  7

I get the following error:

Left (line 1, column 6):
unexpected end of input
expecting digit
integer overflow

ie there are three error messages but I only want the last one. Is
there something I can do about this?



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


Re: [Haskell-cafe] mutable arrays of tuples

2012-08-09 Thread Ketil Malde
David Feuer david.fe...@gmail.com writes:

 So I was thinking about a mutable array of tuples, but to avoid allocating
 tuples to modify their fields, I guess I really want an immutable array of
 tuples of STRefs. Just how much less efficient is this than a plain mutable
 array? might it even make sense to use parallel mutable arrays? The thought
 of that is disgusting to me, but at least one of the arrays could likely be
 made unboxed...

Maybe you could use a tuple of (unboxed) arrays instead?  Or if you use
Vector instead of Array, I think tuples are member of Unbox (as long as
the tuple elements are), and can be used directly in unboxed vectors.

-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


Re: [Haskell-cafe] Fwd: 'let' keyword optional in do notation?

2012-08-09 Thread Tillmann Rendel

Hi,

Martijn Schrage wrote:

Would expanding each let-less binding to a separate let feel more
sound to you?


That was actually my first idea, but then two declarations at the same
level will not be in the same binding group, so

do x = y
   y = 1

would not compile. This would create a difference with all the other
places where bindings may appear.


But it would be in line with - bindings in the do notation, so maybe it 
wouldn't feel so wrong.


  Tillmann

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


[Haskell-cafe] Data.Data and OverlappingInstances

2012-08-09 Thread Timo von Holtz
Hi cafe,

in my code I use Data.Data and OverlappingInstances. My problem now is,
that I can't use functions using these instances as arguments for
fromConstrM.

This is what my problem looks like:

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Data

class Test a where
  foo :: Monad m = m a

instance Num a = Test a where
  foo = return 1

instance Test Int where
  foo = return 2

test constr = fromConstrM foo constr


but when I compile I get:

test.hs:15:26:
Overlapping instances for Test d
  arising from a use of `foo' at test.hs:15:26-28
Matching instances:
  instance [overlap ok] (Num a) = Test a
-- Defined at test.hs:9:9-23
  instance [overlap ok] Test Int -- Defined at test.hs:12:9-16
(The choice depends on the instantiation of `d'
 To pick the first instance above, use -XIncoherentInstances
 when compiling the other instance declarations)
In the first argument of `fromConstrM', namely `foo'
In the expression: fromConstrM foo constr
In the definition of `test': test constr = fromConstrM foo constr
Failed, modules loaded: none.

Is there a way out? Right now I use a case (typeOf x) of kind of
construct, but it gets pretty messy and I even have to unsafeCoerce at one
point.

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


Re: [Haskell-cafe] 3 level hierarchy of Haskell objects

2012-08-09 Thread Patrick Browne
On 09/08/12, Jay Sulzberger  j...@panix.com wrote:Here we are close to the distinction between a class of objectswhich satisfy a condition vs objects with added structure, forwhich see:  http://math.ucr.edu/home/baez/qg-spring2004/discussion.html  http://ncatlab.org/nlab/show/stuff,+structure,+propertyoo--JS.This seems to be addressing my my  question, but I am not sure that I can relate the above ideas to Haskell.Below is my current (naive) understanding and some further question:objects which satisfy a condition Could these objects be models that have the same signature (instances in Haskell). Haskell type classes seem to be signature only (no equations, ignoring default methods) so in general  they provide an empty theory with no logical consequences.objects with added structureI am struggling with this concept both in general and in relation to the hierarchy from my earlier posting.Could this be model expansion where a theory describing an existing model is enriched with additional axioms.The enriched theory is then satisfied by models with more structure (operations).I am unsure about the size of this expanded model and the number of potential expanded models. Would a expanded model have less elements?Would there be  fewer models for the enriched theory?In relation to Haskell data types also have structure (constructors). The data types can be used to build other data types (is this model expansion?)I am not sure if the model (instance) of a sub-class could be considered as expanded model of its super-class.Your reply was very helpfulThanks,Pat
 Tá an teachtaireacht seo scanta ó thaobh ábhar agus víreas ag Seirbhís Scanta Ríomhphost de chuid Seirbhísí Faisnéise, ITBÁC agus meastar í a bheith slán.  http://www.dit.ie
This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean.  http://www.dit.ie



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


Re: [Haskell-cafe] mutable arrays of tuples

2012-08-09 Thread Jake McArthur
In fact, unboxed arrays of tuples are represented in vector as tuples of
unboxed arrays.
On Aug 9, 2012 4:35 AM, Ketil Malde ke...@malde.org wrote:

 David Feuer david.fe...@gmail.com writes:

  So I was thinking about a mutable array of tuples, but to avoid
 allocating
  tuples to modify their fields, I guess I really want an immutable array
 of
  tuples of STRefs. Just how much less efficient is this than a plain
 mutable
  array? might it even make sense to use parallel mutable arrays? The
 thought
  of that is disgusting to me, but at least one of the arrays could likely
 be
  made unboxed...

 Maybe you could use a tuple of (unboxed) arrays instead?  Or if you use
 Vector instead of Array, I think tuples are member of Unbox (as long as
 the tuple elements are), and can be used directly in unboxed vectors.

 -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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] 3 level hierarchy of Haskell objects

2012-08-09 Thread Tillmann Rendel

Hi,

Patrick Browne wrote:

Haskell type classes seem to be signature only (no equations, ignoring
default methods) so in general they provide an empty theory with no
logical consequences.


Note that many type classes in Haskell have equations annotated as 
comments. For example, the monad laws are mentioned in the documentation 
of the Monad type class:


http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#t:Monad

In this context, see also the current thread about what equations we can 
expect to hold for Eq instances:


http://thread.gmane.org/gmane.comp.lang.haskell.cafe/99517

  Tillmann

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


Re: [Haskell-cafe] 3 level hierarchy of Haskell objects

2012-08-09 Thread Tom Nielsen
Hello,

On Thu, Aug 9, 2012 at 1:52 PM, Tillmann Rendel 
ren...@informatik.uni-marburg.de wrote:

Note that many type classes in Haskell have equations annotated as
 comments. For example, the monad laws are mentioned in the documentation of
 the Monad type class:


One of the reasons why I chose Haskell over Scheme about 4 years ago was
that in the PLT Scheme (now Racket) libraries, type annotation were given
in the comments. I thought: maybe those things are in fact useful.

Perhaps in Haskell we could have a lightweight Quasi-quoting/Template
Haskell library for adding laws to class definitions?

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


Re: [Haskell-cafe] Data.Data and OverlappingInstances

2012-08-09 Thread Brandon Allbery
On Thu, Aug 9, 2012 at 6:00 AM, Timo von Holtz timo.v.ho...@gmail.comwrote:

 instance Num a = Test a where
   foo = return 1

 instance Test Int where
   foo = return 2


Erm, this isn't going to work anyway, is it?  I think the first instance
matches all types and then throws an error if the result isn't an instance
of Num?

-- 
brandon s allbery  allber...@gmail.com
wandering unix systems administrator (available) (412) 475-9364 vm/sms
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] parsec: parserFail multiple error messages

2012-08-09 Thread silly8888
On Thu, Aug 9, 2012 at 3:59 AM, Christian Maeder
christian.mae...@dfki.de wrote:
 The error message can be improved in your examples by using count 5
 instead of many1.

Yes, I know. That's what I ended up doing. But this is an ad hoc
solution. I think parsec should offer a more general solution.

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


Re: [Haskell-cafe] Possible bug in Criterion or Statistics package

2012-08-09 Thread Aleksey Khudyakov

On 07.08.2012 19:15, Aleksey Khudyakov wrote:

On 07.08.2012 18:16, Till Berger wrote:

Dear all,

So I am not sure if this is a bug in Criterion itself, the Statistics
package or any dependency or if I am doing something obviously wrong. I
would be grateful if someone could look into this as it is holding me
back from using Criterion for benchmarking my code.


I would suspect Statistics.Resampling.resample. From quick glance
criterion doesn't use any concurrent stuff. I'll try create smaller test
case


It looks like I'm wrong. I obtained event log from crashing program and 
resample completed its work without problems. Crash occured later. Next

suspect is bootstrapBCA itself. It uses monad-par to obtain parallelism[1].

I tried to create smaller test case without any success.



[1] 
https://github.com/bos/statistics/blob/master/Statistics/Resampling/Bootstrap.hs#L84


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


[Haskell-cafe] Parsec type error with Flexible Contexts

2012-08-09 Thread Marco Túlio Gontijo e Silva
Hi.

I wanted to generalize the definitions in Text.Parsec.Language to be
able to use them with Parsec Text instead of Parsec String.  I'm
getting a type error with the following code snippet:
http://hpaste.org/72844

I don't really understand the error, specially with regard to the fact
that the if I comment one of the marked lines on the code pasted the
program build.

Any help is welcome.

Greetings.

-- 
marcot
http://marcot.eti.br/

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


Re: [Haskell-cafe] 3 level hierarchy of Haskell objects

2012-08-09 Thread wren ng thornton

On 8/8/12 9:41 PM, Jay Sulzberger wrote:

Haskell's type classes look to me to be a provision for declaring
a signature in the sense of the above article.


Just to clarify this in the context of my previous post, type classes 
define signatures in two significantly different ways.


(1) The first way is as you suggest: the methods of a type class specify 
a signature, and for convenience we give that signature a name (i.e., 
the type class' name). However, this is a signature for the term level 
of Haskell (i.e., a signature in the Term sort not discussed previously; 
elements of Type classify elements of Term, just as elements of Kind 
classify elements of Type).


(2) The second way is that, at the type level, the collection of type 
class names together form a signature. Namely they form the signature 
comprising the majority of the Context sort.


Both senses are important for understanding the role of type classes in 
Haskell, but I believe that some of Patrick Browne's confusion is due to 
trying to conflate these into a single notion. Just as terms and types 
should not be confused, neither should methods and type classes. In both 
cases, each is defined in terms of the other, however they live in 
separate universes. This is true even in languages which allow terms to 
occur in type expressions and allow types to occur in term expressions. 
Terms denote values and computations (even if abstractly); whereas, 
types denote collections of expressions (proper types denote collections 
of term expressions; kinds denote collections of type expressions;...).


--
Live well,
~wren

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


Re: [Haskell-cafe] Parsec type error with Flexible Contexts

2012-08-09 Thread Felipe Almeida Lessa
Hello!

I've managed to reduce your code to a much simpler test case (without
parsec) but I'm still not sure why this is happening:


{-# LANGUAGE MultiParamTypeClasses, FlexibleContexts #-}

data D m
  = D { bar1 :: P m ()
  , bar2 :: P m ()
  }

data P m c = P

class S m c where

foo :: S m () = P m ()
foo = undefined

emptyDef :: S m () = D m
emptyDef
  = D
{ bar1 = foo
, bar2 = foo
}

haskellStyle :: S m () = D m
haskellStyle
  = emptyDef
{ bar1 = foo
, bar2 = foo
}


Cheers,

-- 
Felipe.

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


Re: [Haskell-cafe] Parsec type error with Flexible Contexts

2012-08-09 Thread Felipe Almeida Lessa
Here's an even smaller one:


{-# LANGUAGE MultiParamTypeClasses, FlexibleContexts #-}

data D m = D { bar :: P m () }
data P m c = P
class S m c where

foo :: S m () = P m ()
foo = undefined

emptyDef :: S m () = D m
emptyDef = D foo

haskellStyle :: S m () = D m
haskellStyle = emptyDef { bar = foo }


Cheers,

-- 
Felipe.

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


Re: [Haskell-cafe] parsec: parserFail multiple error messages

2012-08-09 Thread Albert Y. C. Lai

On 12-08-08 03:24 PM, silly wrote:

The problem is that when I try this

parse integer  7

I get the following error:

Left (line 1, column 6):
unexpected end of input
expecting digit
integer overflow

ie there are three error messages but I only want the last one. Is
there something I can do about this?


import Text.Parsec
import Text.Parsec.String

integer :: Parser Int
integer = try integ3r ? number at most 65535
integ3r  = do s - many1 digit
  let n = read s
  if n  65535 then
  unexpected number overflow
  else
  return n

main = do
  parseTest integer a7
  parseTest integer 7


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


[Haskell-cafe] [Wadler 89] Philip Wadler. Theorems for free!: Can't get the same results in Haskell

2012-08-09 Thread Stayvoid
Hi there,

I was reading Real World Haskell and found this paper. [1]

On the first page of the paper there is an example:

inc* (odds_Int [1,2,3])
= [2,4]
/= [4]
= odds_Int (inc* [1,2,3])

I tried to implement it in Haskell:
(I'm a newbie. I guess it's possible to write a better version.)

module Param where
import Prelude

odds :: [Int] - [Int]
odds [] = []
odds [x] = if odd x
   then [x]
   else []
odds (x:xs) = if odds [x] == []
  then odds xs
  else [x] ++ odds xs

inc :: [Int] - [Int]
inc [] = error Empty list
inc [x] = [succ x]
inc (x:xs) = inc [x] ++ inc xs

Looks fine:

*Param odds [1,2,3]
[1,3]
*Param inc [1,2,3]
[2,3,4]

But my results differ from the paper's:

*Param inc (odds [1,2,3])
[2,4]
*Param odds (inc [1,2,3])
[3]

I doubt that there is an error in the paper. So it seems that
something is wrong with my code. But I can't find the error. Could you
help me?
(Or there is no error at all and I misunderstood something.)

[1] http://ttic.uchicago.edu/~dreyer/course/papers/wadler.pdf

Thanks

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


Re: [Haskell-cafe] [Wadler 89] Philip Wadler. Theorems for free!: Can't get the same results in Haskell

2012-08-09 Thread David Feuer
It looks to me like Wadler made a typo. Even great minds like his slip up
like that sometimes. However, I do have some comments below on your code.

On Aug 9, 2012 8:53 PM, Stayvoid stayv...@gmail.com wrote:

 I tried to implement it in Haskell:
 (I'm a newbie. I guess it's possible to write a better version.)

 module Param where
 import Prelude

The prelude is imported automatically. You only need to mention it as an
import if you need to *avoid* importing some functions, or want some
functions to be imported only qualified. This is done if you want to use
a name that clashes with one in the prelude. You'll see things like
import Prelude hiding (foldl',foldl, foldr)
import Prelude qualified as P
in a module implementing a data structure that supports folds.


 odds :: [Int] - [Int]
 odds [] = []

This is a very awkward approach. There's no reason to have a special case
for the one-element list, and certainly no reason to use ++ to add a single
element to the front of a list. You should do the work in the (x:xs) case
instead:

odds [] = []
odds (x:xs)
  | odd x = x : odds xs
  | otherwise = odds xs

In fact, there's a function called filter that captures this pattern, so
you can even write:

odds = filter odd

 odds [x] = if odd x
then [x]
else []
 odds (x:xs) = if odds [x] == []
   then odds xs
   else [x] ++ odds xs

 inc :: [Int] - [Int]
 inc [] = error Empty list
 inc [x] = [succ x]
 inc (x:xs) = inc [x] ++ inc xs

Again, this is bizarre. You should be writing:

inc [] = []
inc (x:xs) = succ x : inc xs

Again, there is a function that captures this pattern, so you can shorten
it to

inc = map succ


 Looks fine:

 *Param odds [1,2,3]
 [1,3]
 *Param inc [1,2,3]
 [2,3,4]

 But my results differ from the paper's:

 *Param inc (odds [1,2,3])
 [2,4]
 *Param odds (inc [1,2,3])
 [3]

 I doubt that there is an error in the paper.

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


[Haskell-cafe] MIN_VERSION_base

2012-08-09 Thread 山本和彦
Hello,

The stable branch of the network library includes the following code:

#if !(MIN_VERSION_base(4,6,0))

I cannot compile the stable branch with HP 2011.4.0.0 on Linux 2:

Preprocessing library network-2.3.0.14...
BSD.hsc:115:23: error: missing binary operator before token (
BSD.hsc:115:23: error: missing binary operator before token (
BSD.hsc:115:23: error: missing binary operator before token (
compiling dist/build/Network/BSDhsc_make.c failed (exit code 1)
command was: /usr/bin/gcc -c dist/build/Network/BSD_hsc_make.c -o 
dist/build/Network/BSD_hsc_make.o -fno-stack-protector -fno-stack-protector 
-DGLASGOW_HASKELL_=700 -Dlinux_BUILD_OS -Dlinux_HOST_OS -Di386_BUILD_ARCH 
-Di386_HOST_ARCH -Iinclude -DCALLCONV=ccall 
-I/ghc7.0.4/lib/ghc-7.0.4/unix-2.4.2.0/include 
-I/ghc7.0.4/lib/ghc-7.0.4/bytestring-0.9.1.10/include 
-I/ghc7.0.4/lib/ghc-7.0.4/base-4.3.1.0/include 
-I/ghc7.0.4/lib/ghc-7.0.4/include -I/ghc7.0.4/lib/ghc-7.0.4/include 
-I/ghc7.0.4/lib/ghc-7.0.4/include/

dist/build/autogen/cabal_macros.h defines MIN_VERSION_base but
dist/build/Network/BSD_hsc_make.c does not include it.

If you guys know why this happens, please let me know.

For more information, please refer to:
https://github.com/haskell/network/issues/43

--Kazu

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


Re: [Haskell-cafe] MIN_VERSION_base

2012-08-09 Thread Johan Tibell
On Thu, Aug 9, 2012 at 8:50 PM, Kazu Yamamoto k...@iij.ad.jp wrote:
 Hello,

 The stable branch of the network library includes the following code:

 #if !(MIN_VERSION_base(4,6,0))

 I cannot compile the stable branch with HP 2011.4.0.0 on Linux 2:

 Preprocessing library network-2.3.0.14...
 BSD.hsc:115:23: error: missing binary operator before token (
 BSD.hsc:115:23: error: missing binary operator before token (
 BSD.hsc:115:23: error: missing binary operator before token (
 compiling dist/build/Network/BSDhsc_make.c failed (exit code 1)
 command was: /usr/bin/gcc -c dist/build/Network/BSD_hsc_make.c -o 
 dist/build/Network/BSD_hsc_make.o -fno-stack-protector -fno-stack-protector 
 -DGLASGOW_HASKELL_=700 -Dlinux_BUILD_OS -Dlinux_HOST_OS -Di386_BUILD_ARCH 
 -Di386_HOST_ARCH -Iinclude -DCALLCONV=ccall 
 -I/ghc7.0.4/lib/ghc-7.0.4/unix-2.4.2.0/include 
 -I/ghc7.0.4/lib/ghc-7.0.4/bytestring-0.9.1.10/include 
 -I/ghc7.0.4/lib/ghc-7.0.4/base-4.3.1.0/include 
 -I/ghc7.0.4/lib/ghc-7.0.4/include -I/ghc7.0.4/lib/ghc-7.0.4/include 
 -I/ghc7.0.4/lib/ghc-7.0.4/include/

 dist/build/autogen/cabal_macros.h defines MIN_VERSION_base but
 dist/build/Network/BSD_hsc_make.c does not include it.

 If you guys know why this happens, please let me know.

 For more information, please refer to:
 https://github.com/haskell/network/issues/43

I should note that it compiles on GHC 7.0.3 and a bunch of other versions:

http://ci.johantibell.com/job/network/

I suspect that it's either a GHC problem (not passing the right
arguments to hsc2hs) or a cabal problem.

-- Johan

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