Re: [GHC] #3169: Bad occurs-check error message

2011-02-02 Thread GHC
#3169: Bad occurs-check error message
--+-
  Reporter:  simonpj  |  Owner:  
  Type:  bug  | Status:  closed  
  Priority:  low  |  Milestone:  7.0.2   
 Component:  Compiler (Type checker)  |Version:  6.10.2  
Resolution:  fixed|   Keywords:  
  Testcase:  gadt/T3169   |  Blockedby:  
Difficulty:  Unknown  | Os:  Unknown/Multiple
  Blocking:   |   Architecture:  Unknown/Multiple
   Failure:  None/Unknown |  
--+-
Changes (by simonpj):

  * status:  new = closed
  * testcase:  = gadt/T3169
  * resolution:  = fixed


Comment:

 Happily with the new type checker the error message is almost exactly as I
 said it should be 22 months ago:
 {{{
 T3169.hs:13:13:
 Couldn't match type `elt' with `Map b elt'
   `elt' is a rigid type variable bound by
 the type signature for
   lookup :: (a, b) - Map (a, b) elt - Maybe elt
 at T3169.hs:12:3
 Expected type: Maybe (Map b elt)
   Actual type: Maybe elt
 In the return type of a call of `lookup'
 In the expression: lookup a m :: Maybe (Map b elt)
 }}}
 I've added a regression test, and will close.

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/3169#comment:8
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #2599: Improve error message for type rigidity

2011-02-02 Thread GHC
#2599: Improve error message for type rigidity
--+-
  Reporter:  simonpj  |  Owner:  simonpj 
  Type:  feature request  | Status:  closed  
  Priority:  low  |  Milestone:  7.0.2   
 Component:  Compiler |Version:  6.8.3   
Resolution:  invalid  |   Keywords:  
  Testcase:   |  Blockedby:  
Difficulty:  Unknown  | Os:  Unknown/Multiple
  Blocking:   |   Architecture:  Unknown/Multiple
   Failure:  None/Unknown |  
--+-
Changes (by simonpj):

  * status:  new = closed
  * failure:  = None/Unknown
  * resolution:  = invalid


Comment:

 The whole story about rigidity has changed, so I don't think this ticket
 makes sense any more.

 Simon

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/2599#comment:6
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #4896: Deriving Data does not work for attached code

2011-02-02 Thread GHC
#4896: Deriving Data does not work for attached code
-+--
Reporter:  mitar |Owner:  
Type:  bug   |   Status:  new 
Priority:  normal|Milestone:  
   Component:  Compiler  |  Version:  7.1 
Keywords:| Testcase:  
   Blockedby:|   Difficulty:  
  Os:  Unknown/Multiple  | Blocking:  
Architecture:  Unknown/Multiple  |  Failure:  None/Unknown
-+--

Comment(by dreixel):

 Let me sketch quickly how I think this should work. We have a type family
 `T` and a data family `D`:
 {{{
 type family T :: * - *
 type instance T Int = ()
 ...

 data family D a
 data instance D Int = DInt Float
 ...
 }}}

 Regarding the type family `T`, I don't think deriving instances makes much
 sense. We want `typeOf (() :: T Int) == typeOf ()`, because `T Int ~ ()`.
 The same goes for `Data` and any other class, I guess: we just use the
 instance of the synonym, if there is one, and complain if there isn't.

 Data families are more interesting. For `Typeable`, I guess it is sensible
 to allow deriving at the declaration spot:
 {{{
 -- deriving instance Typeable1 D
 -- Should generate
 instance Typeable1 D where
   typeOf1 _ = mkTyConApp (mkTyCon Test.D) []
 }}}
 Although I find the empty list above a bit suspicious, this seems to be
 similar to the instance given for lists as well, for instance. The
 `Typeable` instance follows automatically from this `Typeable1` instance.

 `Data` is another story. We certainly cannot derive anything at the
 declaration point, since we know nothing about the constructors. For each
 instance, however, we know something:
 {{{
 instance Data (D Int) where
   toConstr (DInt f) = dintConstr
   dataTypeOf _ = dDatatype
   gfoldl k z (DInt f) = z DInt `k` f
   gunfold k z c = case constrIndex c of
 _ - undefined -- what do we do here?

 dintConstr :: Constr
 dintConstr = mkConstr dDatatype DInt [] Prefix

 dDatatype :: DataType
 dDatatype = mkDataType Test.D [dintConstr] -- trouble!
 }}}
 But there is one major problem (which raises the two issues above in the
 derived code). In the datatype description `dDatatype` we have to list all
 the constructors, but the set of constructors of a data family is open, so
 we can't do this.

 Interestingly, `gfoldl` doesn't seem problematic. So I guess there are
 three options here:

 1) Allow deriving `Data` for data family instances filling out only
 `gfoldl` and throwing errors for the others.

 2) Refuse to generate `Data` instances for data families, as this is not
 possible in general.

 3) Redesign `syb` such that it allows such instances.

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/4896#comment:2
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


[GHC] #4943: Another odd missed SpecConstr opportunity

2011-02-02 Thread GHC
#4943: Another odd missed SpecConstr opportunity
-+--
Reporter:  batterseapower|   Owner: 
Type:  bug   |  Status:  new
Priority:  normal|   Component:  Compiler   
 Version:  7.1   |Keywords: 
Testcase:|   Blockedby: 
  Os:  Unknown/Multiple  |Blocking: 
Architecture:  Unknown/Multiple  | Failure:  Runtime performance bug
-+--
 Compiling the attached code with HEAD (and without case liberation) has
 this in the output of SpecConstr:

 {{{
 Rec {
 $wa_s1G0 [Occ=LoopBreaker]
   :: forall s_aIU.
  Data.Array.Base.STUArray s_aIU GHC.Types.Int GHC.Types.Int
  - GHC.Types.Int
  - GHC.Prim.Int#
  - GHC.Prim.Int#
  - GHC.Prim.State# s_aIU
  - (# GHC.Prim.State# s_aIU, () #)
 [LclId, Arity=5, Str=DmdType L]
 $wa_s1G0 =
   \ (@ s_aIU)
 (w_s1FA
:: Data.Array.Base.STUArray s_aIU GHC.Types.Int GHC.Types.Int)
 (w_s1FB :: GHC.Types.Int)
 (ww_s1FE :: GHC.Prim.Int#)
 (ww_s1FI :: GHC.Prim.Int#)
 (w_s1FK :: GHC.Prim.State# s_aIU) -
 case GHC.Prim.# ww_s1FE ww_s1FI of wild_Xk [Dmd=Just A] {
   GHC.Types.False -
 case w_s1FA
 of wild_aRL [Dmd=Just L]
 { Data.Array.Base.STUArray ds2_aRN [Dmd=Just U]
ds3_aRO [Dmd=Just U]
ds4_aRP [Dmd=Just U]
marr#_aRQ [Dmd=Just L] -
 case GHC.Prim.readIntArray# @ s_aIU marr#_aRQ ww_s1FE w_s1FK
 of wild2_aRX [Dmd=Just A]
 { (# s2#_aRZ [Dmd=Just L], e#_aS0 [Dmd=Just L] #) -
 case w_s1FB
 of wild1_aSy [Dmd=Just L] { GHC.Types.I# y_aSA [Dmd=Just L] -
 case GHC.Prim.writeIntArray#
@ s_aIU marr#_aRQ ww_s1FE (GHC.Prim.+# e#_aS0 y_aSA)
 s2#_aRZ
 of s2#_aSp [Dmd=Just L] { __DEFAULT -
 $wa_s1G0
   @ s_aIU w_s1FA w_s1FB (GHC.Prim.+# ww_s1FE 1) ww_s1FI s2#_aSp
 }
 }
 }
 };
   GHC.Types.True - (# w_s1FK, GHC.Unit.() #)
 }
 end Rec }
 }}}

 i.e. we know the form of the first STUArray argument after the first
 iteration, but we leave it boxed and hence do the case every time around
 the loop.

 Is constructor specialisation not meant to hit this case? It seems so
 simple that I feel that this problem must come from my misunderstanding
 rather than a compiler error.

 Full command line:

 {{{
 ghc -fforce-recomp -c -dverbose-core2core -O2 -fno-liberate-case STUArray-
 Rewrite2.hs
 }}}

 (I disabled case liberation because I suspect it of having a bad effect
 elsewhere, but my understanding is that SpecConstr should still hit this
 case - IIRC all that CaseLib does that SpecConstr does not is deal with is
 hoisting case scrutinisation of the free variables of a function)

 Note that this is a GHC version *with* the patch Improve Simplifier and
 SpecConstr behaviour. I can reproduce this with the GHC 7.0 RC as well.

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/4943
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #4928: Add primops for copying/cloning an array

2011-02-02 Thread GHC
#4928: Add primops for copying/cloning an array
-+--
 Reporter:  tibbe|  Owner:  
 Type:  feature request  | Status:  patch   
 Priority:  normal   |  Component:  Runtime System  
  Version:  7.0.1| Resolution:  
 Keywords:   |   Testcase:  
Blockedby:   | Os:  Unknown/Multiple
 Blocking:   |   Architecture:  Unknown/Multiple
  Failure:  None/Unknown |  
-+--

Comment(by pumpkin):

 These last two patches change the signature of cloneArray# to not pass
 around an unnecessary State# token, and update the associated test to work
 again with the new signature.

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/4928#comment:8
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #4928: Add primops for copying/cloning an array

2011-02-02 Thread GHC
#4928: Add primops for copying/cloning an array
-+--
 Reporter:  tibbe|  Owner:  
 Type:  feature request  | Status:  patch   
 Priority:  normal   |  Component:  Runtime System  
  Version:  7.0.1| Resolution:  
 Keywords:   |   Testcase:  
Blockedby:   | Os:  Unknown/Multiple
 Blocking:   |   Architecture:  Unknown/Multiple
  Failure:  None/Unknown |  
-+--

Comment(by tibbe):

 This should now be ready to merge. Please merge copyarray-
 clonearray.dpatch (ghc) and copyarray-clonearray-test.dpatch (testsuite).

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/4928#comment:9
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #1333: core lint failures from arrow notation + HPC

2011-02-02 Thread GHC
#1333: core lint failures from arrow notation + HPC
-+--
Reporter:  igloo |Owner:
 
Type:  bug   |   Status:  merge 
 
Priority:  high  |Milestone:  7.0.2 
 
   Component:  Compiler  |  Version:  6.7   
 
Keywords:| Testcase:  arrowrun001 arrowrun002 
arrowrun003
   Blockedby:|   Difficulty:  Unknown   
 
  Os:  Unknown/Multiple  | Blocking:
 
Architecture:  Unknown/Multiple  |  Failure:  None/Unknown  
 
-+--
Changes (by ross):

  * status:  new = merge


Comment:

 Fixed by
 {{{
 Wed Feb  2 21:14:25 GMT 2011  Ross Paterson r...@soi.city.ac.uk
   * avoid adding HPC ticks to arrow constructs (fixes #1333)
 }}}

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/1333#comment:20
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #4838: LLVM mangler takes too long at runtime

2011-02-02 Thread GHC
#4838: LLVM mangler takes too long at runtime
-+--
Reporter:  benl  |Owner:  dterei  
Type:  bug   |   Status:  new 
Priority:  normal|Milestone:  7.2.1   
   Component:  Compiler (LLVM)   |  Version:  7.0.1   
Keywords:| Testcase:  
   Blockedby:|   Difficulty:  
  Os:  MacOS X   | Blocking:  
Architecture:  Unknown/Multiple  |  Failure:  Compile-time performance bug
-+--

Comment(by dterei):

 Yeah there were some pretty bad design issues with the Mangler. I've just
 had an initial crack at a revision.

 Current Mangler:
 {{{
 time ./Driver WordsVect.s
 ./Driver WordsVect.s  4899.54s user 3.72s system 99% cpu 1:21:47.95 total
 }}}

 New Mangler:
 {{{
 time ./Driver WordsVect.s
 ./Driver WordsVect.s  117.79s user 0.38s system 93% cpu 2:06.15 total
 }}}

 So much better already. I still want to try a few different designs before
 I submit a patch though. Progress at long last though :)

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/4838#comment:3
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #4938: Core2 CPU not detected correctly

2011-02-02 Thread GHC
#4938: Core2 CPU not detected correctly
-+--
Reporter:  altaic|   Owner: 
Type:  bug   |  Status:  new
Priority:  normal|   Component:  Compiler   
 Version:  7.1   |Keywords: 
Testcase:|   Blockedby: 
  Os:  Unknown/Multiple  |Blocking: 
Architecture:  Unknown/Multiple  | Failure:  Building GHC failed
-+--

Comment(by altaic):

 The workaround no longer works.

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/4938#comment:2
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


[GHC] #4944: -fvia-C/asm mangler broken on regiserised powerpc-linux build

2011-02-02 Thread GHC
#4944: -fvia-C/asm mangler broken on regiserised powerpc-linux build
+---
Reporter:  kgardas  |   Owner:  
Type:  bug  |  Status:  new 
Priority:  normal   |   Component:  Compiler
 Version:  7.0.1|Keywords:  
Testcase:   |   Blockedby:  
  Os:  Linux|Blocking:  
Architecture:  powerpc  | Failure:  None/Unknown
+---
 Hello,
 I've build 7.0.1 on powerpc-linux platform, but a lot (if not all) tests
 compiled with -fvia-C fails with:
 {{{
 Prologue junk?: .type   s166_ret, @function
 s166_ret:
  # 27 /tmp/ghc17899_0/ghc17899_0.hc 1
 }}}

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/4944
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: 4221 on new codegen

2011-02-02 Thread ezyang

Simon Peyton Jones, I have a question about optimization fuel and GHC panics.
When I vary the fuel using -dopt-fuel, I get the following varying behavior:

   ...
-dopt-fuel=144 = normal segfault (late in the program)
-dopt-fuel=143 = segfaults ~immediately
-dopt-fuel=142 = normal segfault
-dopt-fuel=141 = fails an assert in file compiler/cmm/CmmBuildInfoTables.hs,
line 128
-dopt-fuel=140 = ditto
-dopt-fuel=139 = resulting executable prints 'start' and then doesn't do
anything
   ...

My impression was that these optimizations should not affect program behavior,
in which case the first thing I should figure out is why -dopt-fuel results in
the programming terminating after it prints 'start'. However, I'm not sure if
this is a red herring. Am I on the right track?

Cheers,
Edward

Quoting Simon Marlow marlo...@gmail.com:


On 02/02/2011 00:29, Edward Z. Yang wrote:

More Hoopling later, I see this segment in the rewrite function:

   middle m@(CmmUnsafeForeignCall _ fs _) live = return $
 case map spill  (filter (flip elemRegSet (on_stack live)) fs) ++
  map reload (uniqSetToList (kill fs (in_regs live))) of
   []  -  Nothing
   reloads -  Just $ mkMiddles (m : reloads)

So, if I understand this code correctly, it unilaterally reloads
/anything/ in the registers according to the analysis at that point.

Well, I could see that resulting in the behavior below.

It's not so clear to me what the correct rewrite is; according to
Marlow's comment on IRC, we ought not to be spilling/reloading foreign
calls yet, so maybe the whole bit should get excised? Otherwise, it seems
to me that transfer function needs to accomodate unsafe foreign
functions.


Right, there's no need to spill/reload anything around an *unsafe* 
foreign call in the Cmm code generator.  The NCG's register allocator 
will do any necessary spilling/reloading around foreign calls.


Cheers,
Simon




Cheers,
Edward

Excerpts from Simon Marlow's message of Tue Feb 01 03:44:41 -0500 2011:

On 01/02/2011 00:01, Edward Z. Yang wrote:

Current theory:

c1jj:
_s1ep::I32 = I32[(slot_s1ep::I32   + 4)];   // CmmAssign
_s1fP::I32 = I32[(slot_s1fP::I32   + 4)];   // CmmAssign
// outOfLine should follow:
_s1eq::F64 = F64[_s1fP::I32 + 3];   // CmmAssign
I32[(youngc1jh   + 4)] = c1jh;   // CmmStore
foreign call ccall arg hints:  [PtrHint,]  result hints: 
 [] call_fn_blob(...) returns to c1jh args: ([_s1ep::I32,
   
  _s1eq::F64]) ress: 
([_s1ev::F64]) with update frame 4;   // CmmForeignCall

c1jh:
_s1ev::F64 = F64[(slot_s1ev::F64   + 8)];   // CmmAssign
// emitReturn: Sequel: Assign
_s1ev::F64 = _s1ev::F64;   // CmmAssign
F64[(slot_s1ev::F64   + 8)] = _s1ev::F64;   // CmmStore
goto u1Ak;   // CmmBranch

Note the line immediately after c1jh, where we reload the ostensibly
spilled _s1ev back into a register. Except that it was never spilled
there in the first place, and we just clobbered the real value. Oops.

Is this interpretation correct?


It sounds plausible, but I really have no idea.  The code generator does
not have to generate spill/reloads around foreign calls, the register
allocator will do that.

Cheers,
 Simon







___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: Kernel panic when building HEAD on OS X 10.6.4

2011-02-02 Thread Johan Tibell
The issue seems to be related to PGP encryption of the disk. Creating
a new disk image, mounting it, and building GHC on it works.

Johan

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


[Haskell] Haskell Weekly News: Issue 167 - February 02, 2011

2011-02-02 Thread Daniel Santa Cruz
   Welcome to issue 167 of the HWN, a newsletter covering developments in
   the [1]Haskell community. This release covers the week of January 23 to
   29, 2011.

   This week I've added a section which compiles a list of the top answers
   given in StackOverflow during the week. These seem to be of more
   interest to more experienced Haskell users than the newbie questions
   usually posted on the site. See what you think.

Announcements

   R. Emre Basar [2]annouced the release of follower, a tool that allows
   you to follow people's tweets without having an account with Twitter.

   Alberto Ruiz [3]announced hmatrix version 0.11, a package for numerical
   computation based on LAPACK and SGL.

   Michael Snoyman [4]made some point updates for WAI and Warp. They fix
   some documentation issues, add some status aliases, make it possible to
   handle exceptions more easily, and make things more responsive on
   Windows.

   Antoine Latter [5]announced a minor point release for Parsec 3.1.0.

   John Meacham [6]announced version 0.7.7 of jhc is out! This release
   fixes a large number of bugs that cropped up when compiling haskell out
   in the wild as well as adds some more features. A major one being the
   garbage collector is enabled by default.

Quotes of the Week

 * Twey: Maybe Bool: the Haskell equivalent to True/False/FileNotFound
 * elliott: Only two things in the universe are certain: Death, and
   two of the libraries you've decided to use taking different types
   of ByteString.
 * shapr: my personal heuristics judge Haskell as totally practical,
   perhaps too practical.
 * monochrom: the guys that I see when I look into the irc window
   believe that I'm just a bunch of text.
 * bernardh: Refactoring: spend a week to get where you were
 * Question: How do I use fix, and how does it work? Answer (by
   TomMD): The prank answer is fix has no real use, it's just there
   so you can type 'fix error' in ghci and feel good about yourself.

Top Reddit Stories

   * Haskell at Bump
 Domain: devblog.bu.mp, Score: 44, Comments: 9
 On Reddit: http://www.reddit.com/r/haskell/comments/f8cr8/haskell_at_bump/
 Original: http://devblog.bu.mp/haskell-at-bump

   * How to write a simple TCP Server in Haskell
 Domain: catonmat.net, Score: 35, Comments: 5
 On Reddit:
http://www.reddit.com/r/haskell/comments/faa80/how_to_write_a_simple_tcp_server_in_haskell/
 Original: http://catonmat.net/blog/simple-haskell-tcp-server

   * Snap Framework article in IEEE Internet Computing
 Domain: steve.vinoski.net, Score: 32, Comments: 1
 On Reddit:
http://www.reddit.com/r/haskell/comments/fa0e0/snap_framework_article_in_ieee_internet_computing/
 Original: 
http://steve.vinoski.net/blog/2011/01/21/column-on-the-snap-framework/

   * My Dream GHCi Session, Take 2
 Domain: cdsmith.wordpress.com, Score: 23, Comments: 5
 On Reddit:
http://www.reddit.com/r/haskell/comments/f8im5/my_dream_ghci_session_take_2/
 Original: 
http://cdsmith.wordpress.com/2011/01/24/my-dream-ghci-session-take-2/

   * Text: a visual programming language based on Haskell, demo
 Domain: vimeo.com, Score: 20, Comments: 3
 On Reddit:
http://www.reddit.com/r/haskell/comments/fbgxd/text_a_visual_programming_language_based_on/
 Original: http://vimeo.com/19273744

   * Hoogle Embed
 Domain: neilmitchell.blogspot.com, Score: 16, Comments: 3
 On Reddit: http://www.reddit.com/r/haskell/comments/f7iqa/hoogle_embed/
 Original: http://neilmitchell.blogspot.com/2011/01/hoogle-embed.html

   * What does this mean for Haskell on Android?
 Domain: reddit.com, Score: 15, Comments: 12
 On Reddit:
http://www.reddit.com/r/haskell/comments/f9o67/what_does_this_mean_for_haskell_on_android/
 Original: 
http://www.reddit.com/r/Android/comments/f97zh/google_not_happy_with_number_of_android_app/c1ebkji

   * Evolving a computer with Genprog (exercises from the TECS book)
 Domain: jpmoresmau.blogspot.com, Score: 13, Comments:
 On Reddit:
http://www.reddit.com/r/haskell/comments/f7y6a/evolving_a_computer_with_genprog_exercises_from/
 Original: 
http://jpmoresmau.blogspot.com/2011/01/evolving-computer-with-tecs-and-genprog.html

   * All about MVars : Inside T5
 Domain: blog.ezyang.com, Score: 13, Comments: 4
 On Reddit:
http://www.reddit.com/r/haskell/comments/fduxb/all_about_mvars_inside_t5/
 Original: http://blog.ezyang.com/2011/02/all-about-mvars/

   * What textbooks would be useful to start approaching the
low-hanging fruit on the ghc project?
 Domain: self.haskell, Score: 12, Comments: 8
 On Reddit:
http://www.reddit.com/r/haskell/comments/f8dm5/what_textbooks_would_be_useful_to_start/
 Original: 
/r/haskell/comments/f8dm5/what_textbooks_would_be_useful_to_start/

Top StackOverflow Answers

   * What is an idiomatic way to add lists in Haskell?
 Votes: 14
 Read on SO:

[Haskell] a quick question

2011-02-02 Thread Navin Rustagi
Hi all, 

I am stuck at a piece of code and am not able to figure out the error.  


uptable::[[Char]]-[([Char],Int,Int,Int,Int)]-[([Char],Int,Int,Int,Int)]
uptable (xf:xs) main_array = map (\(x,y,z,r,t)- do if x==xf then tupup x y z r 
t second xs ) main_array


here tupup and second are functions which are working .  When compiling this it 
gives the error 

Syntax error in expression (unexpected `)')


I am not able to figure out where I could have gone wrong. I have tried all 
bracketing combinations and nothing works. 

Navin 


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


Re: [Haskell] a quick question

2011-02-02 Thread Ramy Abdel-Azim
Missing else?

On Wed, Feb 2, 2011 at 8:49 PM, Navin Rustagi navin_ku...@yahoo.com wrote:

 Hi all,

 I am stuck at a piece of code and am not able to figure out the error.


 uptable::[[Char]]-[([Char],Int,Int,Int,Int)]-[([Char],Int,Int,Int,Int)]
 uptable (xf:xs) main_array = map (\(x,y,z,r,t)- do if x==xf then tupup x y
 z r t second xs ) main_array


 here tupup and second are functions which are working .  When compiling
 this it gives the error

 Syntax error in expression (unexpected `)')


 I am not able to figure out where I could have gone wrong. I have tried all
 bracketing combinations and nothing works.

 Navin


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


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


Re: [Haskell] a quick question

2011-02-02 Thread Navin Rustagi
Sorry, dumb of me  doesn't give this error anymore. 
thanks, 
Navin



From: Ramy Abdel-Azim ramy.abdela...@gmail.com
To: Navin Rustagi navin_ku...@yahoo.com
Cc: Haskell@haskell.org
Sent: Wed, February 2, 2011 7:55:09 PM
Subject: Re: [Haskell] a quick question

Missing else?


On Wed, Feb 2, 2011 at 8:49 PM, Navin Rustagi navin_ku...@yahoo.com wrote:

Hi all, 


I am stuck at a piece of code and am not able to figure out the error.  




uptable::[[Char]]-[([Char],Int,Int,Int,Int)]-[([Char],Int,Int,Int,Int)]
uptable (xf:xs) main_array = map (\(x,y,z,r,t)- do if x==xf then tupup x y z 
r 
t second xs ) main_array




here tupup and second are functions which are working .  When compiling this 
it 
gives the error 


Syntax error in expression (unexpected `)')




I am not able to figure out where I could have gone wrong. I have tried all 
bracketing combinations and nothing works. 


Navin 

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





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


Re: [Haskell] a quick question

2011-02-02 Thread Ramy Abdel-Azim
No need to apologize. Not dumb of you. The mandatory else is unusual. I
don't personally know of any other language that requires an else for every
if.

On Wed, Feb 2, 2011 at 9:07 PM, Navin Rustagi navin_ku...@yahoo.com wrote:

 Sorry, dumb of me  doesn't give this error anymore.
 thanks,
 Navin
 --
 *From:* Ramy Abdel-Azim ramy.abdela...@gmail.com
 *To:* Navin Rustagi navin_ku...@yahoo.com
 *Cc:* Haskell@haskell.org
 *Sent:* Wed, February 2, 2011 7:55:09 PM
 *Subject:* Re: [Haskell] a quick question

 Missing else?

 On Wed, Feb 2, 2011 at 8:49 PM, Navin Rustagi navin_ku...@yahoo.comwrote:

 Hi all,

 I am stuck at a piece of code and am not able to figure out the error.


 uptable::[[Char]]-[([Char],Int,Int,Int,Int)]-[([Char],Int,Int,Int,Int)]
 uptable (xf:xs) main_array = map (\(x,y,z,r,t)- do if x==xf then tupup x
 y z r t second xs ) main_array


 here tupup and second are functions which are working .  When compiling
 this it gives the error

 Syntax error in expression (unexpected `)')


 I am not able to figure out where I could have gone wrong. I have tried
 all bracketing combinations and nothing works.

 Navin


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




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


[Haskell] ANNOUNCE: time-1.2.0.4

2011-02-02 Thread Ashley Yakeley
A small update, time-1.2.0.4 fixes a bug in parseTime reported to me by 
Michael Gurlitz:


 import Data.Time
 import Data.Time.Clock
 import System.Locale

 main = print (parseTime defaultTimeLocale %e %B %Y April 2000 :: 
 Maybe Day)

 -- Just *** Exception: Prelude.read: no parse

Specifically:

 parseTime defaultTimeLocale %e  :: Maybe Day
 -- Just *** Exception: Prelude.read: no parse

In time-1.2.0.4, they now correctly evaluate to Nothing. I've updated 
the unit tests to catch this too.


--
Ashley Yakeley


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


Re: [Haskell] a quick question

2011-02-02 Thread Julian Gilbey
On Wed, Feb 02, 2011 at 10:01:08PM -0500, Ramy Abdel-Azim wrote:
 No need to apologize. Not dumb of you. The mandatory else is unusual. I
 don't personally know of any other language that requires an else for every
 if.

Indeed.  Haskell's if ... then ... else ... is akin to C's ... ? ... :
... ternary operator rather than standard if/then/else clauses.

Remember that if ... then ... else ... is an _expression_, so must
have a value irrespective of whether the condition is true or false;
therefore, there must be an else clause.

   Julian

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


Re: Local definitions in the class instances

2011-02-02 Thread Max Bolingbroke
On 2 February 2011 02:25, Sebastian Fischer fisc...@nii.ac.jp wrote:
 It's a nice trick! Although it does look strange, it may be reasonable to
 allow pattern bindings in instance declarations regardless of the original
 proposal. Is it correct that, currently, pattern bindings are allowed
 everywhere but in instance declarations? If so, why not in instance
 declarations too?

Unfortunately, they are not allowed. I ran up against this limitation
even before this thread. Here is an example:


{-# LANGUAGE NoMonoPatBinds #-}
data I a = I { unI :: a }

instance Monad I where
(return, (=)) = (I, \mx f - f (unI mx))

main = return ()


And the error:


/Users/mbolingbroke/Junk/InstancePattern.hs:5:5:
Pattern bindings (except simple variables) not allowed in instance
declarations
  (return, =) = (I, \ mx f - f (unI mx))


This behaviour does seem to be as per the Haskell 98 spec, but I'm not
sure of the motivation behind it.

 I think the proposals to make pattern bindings monomorphic only concern
 pattern bindings without type annotations. Instance methods do have type
 annotations in the class declaration so even if pattern bindings without
 type signatures would be monomorphic, instance methods bound using pattern
 bindings need not be.

This was what I used to think too, but I recently found out (again,
unrelated to this thread) that they won't work even with explicit
signatures! See for example
http://hackage.haskell.org/trac/ghc/ticket/4940

I'm personally not in favour of MonoPatBinds anyway, but it is
*particularly* annoying that they don't work even with a signature.

Cheers,
Max

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


Re: [Haskell-cafe] Loading bitmap with xlib

2011-02-02 Thread Francesco Mazzoli
Conrad Parker conrad at metadecks.org writes:

 
 On 31 January 2011 21:40, Francesco Mazzoli f at mazzo.li wrote:
  Francesco Mazzoli f at mazzo.li writes:
 
  At the end I gave up and I wrote the function myself:
 
  http://hpaste.org/43464/readbitmapfile
 
 
 cool ... the listed maintainer for the Xlib bindings is
 libraries at haskell.org. Perhaps you could prepare a patch and send it
 there? (does anyone know if there is an actual maintainer?)
 
 Conrad.
 
I will send a patch, but I'm sure there must be a reason behind the
fact that those functions were not included, even if I can't see it.

Francesco.




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


Re: [Haskell-cafe] Instancing Typeable for monad transformers?

2011-02-02 Thread oleg

One can do something a bit shorter

 instance (Typeable a, Typeable1 m) = Typeable1 (Iteratee a m) where
   typeOf1 i = mkTyConApp (mkTyCon Data.Enumerator.Iteratee) 
   [typeOf a, typeOf1 m]
where
(a,m) = peel i
peel :: Iteratee a m w - (a, m ())
peel = undefined


still a bother to write every time one needs it, but tolerable. Only
the signature of 'peel' matters.




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


[Haskell-cafe] ANN: HackageOneFive: Reverse dependency lookup for all packages on Hackage

2011-02-02 Thread Simon Hengel
Hello,
I wrote a tiny Snap app that provides reverse dependency lookup for all
packages on Hackage.

A git repository is at:

https://github.com/sol/HackageOneFive

Setup instructions are provide in the README[1] file.

It uses a PostgreSQL database for storage but it should be trivial to
port this to e.g. SQLite.

As always feedback and patches are gladly welcome!

btw: Is there still progress on Hackage 2.0?

Cheers,
Simon

[1] https://github.com/sol/HackageOneFive#readme

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


Re: [Haskell-cafe] ANN: HackageOneFive: Reverse dependency lookup for all packages on Hackage

2011-02-02 Thread Max Bolingbroke
On 2 February 2011 11:57, Simon Hengel simon.hen...@wiktory.org wrote:
 Hello,
 I wrote a tiny Snap app that provides reverse dependency lookup for all
 packages on Hackage.

Are you familiar with Roel van Djik's revdep Hackage?
http://bifunctor.homelinux.net/~roel/hackage/packages/hackage.html

It's usually quite up to date, and very useful.

 btw: Is there still progress on Hackage 2.0?

Last I heard was that Matt Gruen had done quite a lot of work on it in
the last Summer of Code (see http://cogracenotes.wordpress.com/), but
they haven't got around to actually deploying the new version - but
that was a few months ago.

Cheers,
Max

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


[Haskell-cafe] http-enumerator: redirects, streaming and keep-alive

2011-02-02 Thread Michael Snoyman
Hi all,

There are a number of new feature requests for http-enumerator, and I
wanted to discuss some possible API changes with everyone:

* Allow keep-alive requests, which will reuse the same connection.
* Allow client code to determine whether it accepts a server's SSL certificate.
* Allow the request body to be an Enumerator so we can send large
request bodies without using lazy IO. This is already implemented via
streamingHttp, but it would make more sense to modify the Request
datatype to replace L.ByteString with (Int, Enumerator ByteString IO
()).
* Fix redirect behavior. It seems that the right thing to do is change
a POST into a GET and remove the request body for a 303, and resend
the same request for all other 3xx codes. However, when using an
Enumerator for the request body, it is not guaranteed that we can
resend an Enumerator.

For addressing the last two, my plan is to:

* Change the Request datatype as mentioned, but provide a convenience
method for converting a lazy ByteString into a (Int, Enumerator
ByteString IO ()).
* Implement redirecting as I have described, and explain in the
documentation that automatic redirecting can only work with
Enumerators that can be run multiple times. AFAIK, this works with
most standard Enumerators, such as enumFile, and with the helper
function I will provide to convert lazy ByteStrings to Enumerators.
* Remove streamingHttp, as it will no longer be necessary.

As far as keep-alive goes, I still need to do a bit more research, but
my basic idea (with credit to Bryan O'Sullivan):

* http (and family) will all take an extra argument, Maybe Manager.
* Manager will be an abstract type that will keep an MVar (Map (Host,
Port, IsSecure) Socket).
* If http is provided with a Manager, then it uses the Socket
available in the Manager. If none is available, it creates a new
Socket and places it in the Manager.
* If http is *not* provided with a Manager, then it creates a new
socket and closes it before returning.
* There will be a newManager :: IO Manager, and a closeManager ::
Manager - IO (), which closes all Sockets in the Manager and empties
out the inner Map.

Some open questions are:

* Who is responsible to recover if a server is no longer responding on
a Socket from the Manager: http or the client code? I would assume
http.
* I haven't fully thought through how this will work with secure
connections: most likely in addition to storing the Socket in the
Manager I will need to store some certificate data.

And speaking of certificates, the main concern I have here is data
types: since http-enumerator can use either tls or OpenSSL, there
isn't a single certificate datatype I can use. If someone wants to
help out and write some code to convert an OpenSSL X509 datatype into
a Certificate from the certificate package (which tls uses), I will be
very grateful.

Assuming we had such a unified datatype, I would recommend changing
Request's secure record to be Certificate - IO Bool, where returning
True means the certificate is accepted and False means it is rejected.
To get the current functionality of trusting any certificate, we would
use (const $ return True).

Any thoughts?

Michael

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


Re: [Haskell-cafe] Haskell function help

2011-02-02 Thread Houdini

*can't
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/Haskell-function-help-tp3365994p3368001.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] Haskell function help

2011-02-02 Thread Houdini

I didn't write it like that...because since I'm using the dot notation I can
specify aguments for the function...I rectified that...sorry I forgot to
mention
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/Haskell-function-help-tp3365994p3368000.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] Gedit Haskell mode plugin indentation

2011-02-02 Thread yukkuri yu!yu!yu!
Update.

Current version: v0.8

Changelog:

* Fixed some issues with nested lists

---
ftp://neverb.net/soft/mine/gedit_haskell_mode/haskell_indentation-latest.tar.gz

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


[Haskell-cafe] Haskell DPLL

2011-02-02 Thread Houdini

One :Thank you Carsten Schultz,Daniel Fischer and all the other for your
help. 
Two:After my last post I wrote some function that should help me in the
future,but I need some help with the followint as I'm tired and have to fit
in a schedule.I know it is long so I'll try and explain it as short and
consice as I can.
The DPLL procedure has two main stages: a simplification stage and a search
stage. In the simplification
stage, functions are applied to the formula to assign truth values to
certain propositional variables. The
simplifications are made because if there is a satisfying assignment for the
simplified formula then it is also
a satisfying assignment for the original formula. This reduces the need for
search which can take a long
time. The search stage is performed when no more simplifications can be
made. In this stage a literal is
chosen and is assigned true or false leading to two new branches in the
search space.
I wrote some function wich should be helpfull,but I have to fit in a
schedule and I'm getting tired I need some additional help if possible.

module Algorithm where

import System.Random
import Data.Maybe
import Data.List

type Atom = String
type Literal = (Bool,Atom)
type Clause = [Literal]
type Formula = [Clause]
type Model = [(Atom, Bool)]
type Node = (Formula, ([Atom], Model))

-- This function  takess a Clause and return the set of Atoms of that
Clause.
atomsClause :: Clause - [Atom]
   

-- This function  takes a Formula returns the set of Atoms of a Formula
atoms :: Formula - [Atom]


-- This function returns True if the given Literal can be found within
-- the Clause.
isLiteral :: Literal - Clause - Bool


-- this function takes a Model and an Atom and flip the truthvalue of
-- the atom in the model
flipSymbol :: Model - Atom - Model -- is this ok?
  
Additional functions that I wrote:
remove :: (Eq a) )a -[a] -[a] 
-This function removes an item from a list.
 
 neg :: Literal-Literal
-This function flips a literal (ie. from P to :P and from :P to P).
falseClause :: Model - Clause - Bool 
-This function takes a Model and a Clause and returns True
if the clause is unsatisfied by the model or False otherwise.
falseClauses :: Formula - Model - [Clause]
-This function takes a Formula and a Model and returns the list of
clauses of the  formula that are not satisfied.
 assignModel :: Model - Formula - Formula 
 -This function applies the assign function for all the assignments of a
given model.
 checkFormula :: Formula - Maybe Bool This function checks whether a
formula can be  decided to be satisfiable or unsatisfiable based on the
effects of the assign function.
 satisfies :: Model - Formula -. Bool This function checks whether a
model satisfies a formula. This is done with the combination of the
assignModel and checkFormula functions.


--Where do I need help:

   removeTautologies :: Formula-Formula 
This function should output a simplified formula if tautologies
can be found in one or more clauses in the input
Notes: If in a clause, a literal and its negation are found, it means that
the clause will be true, regardless of the value
finally assigned to that propositional variable. Consider the following
example:
(A v B v -A) ^ (B v C v A)
The first clause contains the literals A and -A. This means that the clause
will always be true, in which case
it can be simplify the whole set to simply (B v C v A) (the second clause
alone)

 pureLiteralDeletion :: Formula-Formula
This function is suppose to implement a simplification step that assumes as
true any atom in a formula that appears exclusively in a positive or
negative form (not both). Consider the formula:
(P v Q v R) ^ (P v Q v -R) ^ (-Q v R)
Note that in this formula P is present but -P is not. Using Pure Literal
Deletion  it can be assumed that the value of P will be True thus
simplifying the formula to (-Q v R). If the literal were false then the
literal would simply be deleted from the clauses it appears in. In that case
any satisfying model for the resulting formula would also be a satisfying
model for the formula when we assume that the literal is true. Hence this
simplification is sound in that if there is a solution to the simplified
formula then there is a solution to the original formula.
   
  propagateUnits :: Formula-Formula
If a clause in a propositional formula contains only one literal, then that
literal must be true (so that the particular clause can be satisfied). When
this happens,we can remove the unit clauses (the ones that contain only one
literal), all the clauses where the literal appears and also, from the
remaining clauses, we can delete the negation of the literal (because if P
is true, -P will be false).For example, in the formula (P v Q v R) ^ (-P v Q
v -R) ^ (P) we have one unit clause (the third clause(P) ). Because this 

Re: [Haskell-cafe] Haskell DPLL

2011-02-02 Thread Houdini

I didn't upload the code for the funtion I wrote because of the space...I ca
do so If you require.
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/Haskell-DPLL-tp3368123p3368130.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] Loading bitmap with xlib

2011-02-02 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 2/2/11 04:03 , Francesco Mazzoli wrote:
 Conrad Parker conrad at metadecks.org writes:
 On 31 January 2011 21:40, Francesco Mazzoli f at mazzo.li wrote:
 Francesco Mazzoli f at mazzo.li writes:
 At the end I gave up and I wrote the function myself:
 http://hpaste.org/43464/readbitmapfile

 cool ... the listed maintainer for the Xlib bindings is
 libraries at haskell.org. Perhaps you could prepare a patch and send it
 there? (does anyone know if there is an actual maintainer?)

 I will send a patch, but I'm sure there must be a reason behind the
 fact that those functions were not included, even if I can't see it.

Pretty much what the comment says.  Graphics.X11 was never really a complete
set of bindings, just what people needed at the time.  The Extras stuff in
there was driven by xmonad development, for example (and named so because
originally it was a separate library before it got folded in, so the module
names were difficult to change while maintaining compatibility).  Dealing
with structs in the FFI is painful enough that I can easily imagine someone
saying we don't need those, let someone else figure it out --- which you
have done.  Patch away.

- -- 
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 v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1Jq9cACgkQIn7hlCsL25XaJgCfc+CCngSmZlL9JOeZ21vZwkBO
BHkAn128z1dH2entJKEfH6pKJ2Y7qW4w
=LOMj
-END PGP SIGNATURE-

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


[Haskell-cafe] SYB: extending a generic reader with a type class

2011-02-02 Thread Sugar Bzzz
Dear -cafe,

Is it possible to extend a generic reader (extR / ext1R from syb) with a
type class?


For example, let

foo :: (Integral a) = SomeMonad a

I could write:

reader = ... `extR` (foo :: SomeMonad Int) `extR` (foo :: SomeMonad Integer)

However, that is tedious.  Could I do something like

reader = ... `extR` foo

and have it apply to all instances of Integral?


I hope I am being clear.

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


Re: [Haskell-cafe] SYB: extending a generic reader with a type class

2011-02-02 Thread José Pedro Magalhães
Hi,

I don't think you can do that, since `ext` relies on Typeable and Typeable
only works for monomorphic types.


Cheers,
Pedro

On Wed, Feb 2, 2011 at 20:31, Sugar Bzzz sugarbz...@gmail.com wrote:

 Dear -cafe,

 Is it possible to extend a generic reader (extR / ext1R from syb) with a
 type class?


 For example, let

 foo :: (Integral a) = SomeMonad a

 I could write:

 reader = ... `extR` (foo :: SomeMonad Int) `extR` (foo :: SomeMonad
 Integer)

 However, that is tedious.  Could I do something like

 reader = ... `extR` foo

 and have it apply to all instances of Integral?


 I hope I am being clear.

 Thank you.

 ___
 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] [web-devel] http-enumerator: redirects, streaming and keep-alive

2011-02-02 Thread Felipe Almeida Lessa
On Wed, Feb 2, 2011 at 11:57 AM, Michael Snoyman mich...@snoyman.com wrote:
 As far as keep-alive goes, I still need to do a bit more research, but
 my basic idea (with credit to Bryan O'Sullivan):

 * http (and family) will all take an extra argument, Maybe Manager.
 * Manager will be an abstract type that will keep an MVar (Map (Host,
 Port, IsSecure) Socket).
 * If http is provided with a Manager, then it uses the Socket
 available in the Manager. If none is available, it creates a new
 Socket and places it in the Manager.
 * If http is *not* provided with a Manager, then it creates a new
 socket and closes it before returning.
 * There will be a newManager :: IO Manager, and a closeManager ::
 Manager - IO (), which closes all Sockets in the Manager and empties
 out the inner Map.

How about concurrent use of Manager?  Should we do

A)
  do m - newManager
   forM xs $ forkIO $ doSomething m

B)
  forM xs $ forkIO $ do
m - newManager
doSomething m

While B) should work with any sane Manager implementation, it is not
optimal.  If all your connections are to the same host, than both
approaches are the same.  But if access hosts O and P, for example,
than it is possible that Manager m1 has an open connection to O, but
you try connect to O using another Manager m2.  That means that
ideally we should support approach A) as well.  However, to support A
a simple Map inside an MVar isn't sufficient.

Cheers! =)

-- 
Felipe.

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


Re: [Haskell-cafe] [web-devel] http-enumerator: redirects, streaming and keep-alive

2011-02-02 Thread Michael Snoyman
On Wed, Feb 2, 2011 at 10:15 PM, Felipe Almeida Lessa
felipe.le...@gmail.com wrote:
 On Wed, Feb 2, 2011 at 11:57 AM, Michael Snoyman mich...@snoyman.com wrote:
 As far as keep-alive goes, I still need to do a bit more research, but
 my basic idea (with credit to Bryan O'Sullivan):

 * http (and family) will all take an extra argument, Maybe Manager.
 * Manager will be an abstract type that will keep an MVar (Map (Host,
 Port, IsSecure) Socket).
 * If http is provided with a Manager, then it uses the Socket
 available in the Manager. If none is available, it creates a new
 Socket and places it in the Manager.
 * If http is *not* provided with a Manager, then it creates a new
 socket and closes it before returning.
 * There will be a newManager :: IO Manager, and a closeManager ::
 Manager - IO (), which closes all Sockets in the Manager and empties
 out the inner Map.

 How about concurrent use of Manager?  Should we do

 A)
  do m - newManager
       forM xs $ forkIO $ doSomething m

 B)
  forM xs $ forkIO $ do
    m - newManager
    doSomething m

 While B) should work with any sane Manager implementation, it is not
 optimal.  If all your connections are to the same host, than both
 approaches are the same.  But if access hosts O and P, for example,
 than it is possible that Manager m1 has an open connection to O, but
 you try connect to O using another Manager m2.  That means that
 ideally we should support approach A) as well.  However, to support A
 a simple Map inside an MVar isn't sufficient.

Good point: it should be a MVar (Map HostInfo (MVar Socket)) I think*

Thanks,
Michael

* It's late here, just make sure I'm not saying something stupid ;).

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


Re: [Haskell-cafe] [web-devel] http-enumerator: redirects, streaming and keep-alive

2011-02-02 Thread Antoine Latter
On Wed, Feb 2, 2011 at 2:28 PM, Michael Snoyman mich...@snoyman.com wrote:
 On Wed, Feb 2, 2011 at 10:15 PM, Felipe Almeida Lessa
 felipe.le...@gmail.com wrote:
 On Wed, Feb 2, 2011 at 11:57 AM, Michael Snoyman mich...@snoyman.com wrote:
 As far as keep-alive goes, I still need to do a bit more research, but
 my basic idea (with credit to Bryan O'Sullivan):

 * http (and family) will all take an extra argument, Maybe Manager.
 * Manager will be an abstract type that will keep an MVar (Map (Host,
 Port, IsSecure) Socket).
 * If http is provided with a Manager, then it uses the Socket
 available in the Manager. If none is available, it creates a new
 Socket and places it in the Manager.
 * If http is *not* provided with a Manager, then it creates a new
 socket and closes it before returning.
 * There will be a newManager :: IO Manager, and a closeManager ::
 Manager - IO (), which closes all Sockets in the Manager and empties
 out the inner Map.

 How about concurrent use of Manager?  Should we do

 A)
  do m - newManager
       forM xs $ forkIO $ doSomething m

 B)
  forM xs $ forkIO $ do
    m - newManager
    doSomething m

 While B) should work with any sane Manager implementation, it is not
 optimal.  If all your connections are to the same host, than both
 approaches are the same.  But if access hosts O and P, for example,
 than it is possible that Manager m1 has an open connection to O, but
 you try connect to O using another Manager m2.  That means that
 ideally we should support approach A) as well.  However, to support A
 a simple Map inside an MVar isn't sufficient.

 Good point: it should be a MVar (Map HostInfo (MVar Socket)) I think*


Or you could remove the socket from the map while it's in use.

Antoine

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


Re: [Haskell-cafe] [web-devel] http-enumerator: redirects, streaming and keep-alive

2011-02-02 Thread Felipe Almeida Lessa
On Wed, Feb 2, 2011 at 6:30 PM, Antoine Latter aslat...@gmail.com wrote:
 Or you could remove the socket from the map while it's in use.

And what about connection limits?  We shouldn't create a thousand
connections to the same host =).

-- 
Felipe.

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


Re: [Haskell-cafe] timely shutdown of timer threads

2011-02-02 Thread Warren Harris
Interesting. I hadn't thought of this solution. You're forking the timer to yet 
a third thread so that if it continues waiting beyond the checkpoint thread 
shutdown it doesn't really matter. I guess that works as long as the main 
thread doesn't wait for all other threads to terminate before terminating the 
app.

It still seems to me that haskell is lacking when it comes to operations that 
can wait for multiple conditions.

Warren


On Feb 1, 2011, at 6:25 PM, Albert Y. C. Lai wrote:

 On 11-02-01 02:58 PM, Warren Harris wrote:
 I have an application that forks a thread to run an activity on a timer. 
 (The activity happens to be Berkeley DB checkpointing, but that's actually 
 beside the point here.) The problem is that when the application wants to 
 quit, I would like my main thread to be able to tell the timer thread to 
 shut down in a timely way. However, I don't see a primitive in haskell that 
 allows me to both wait for a timeout, or a notification. (If I were to do 
 this in java, I would use wait/notify.)
 
 Use an MVar for signalling; use a two-valued data type to represent 
 time-to-work or time-to-die. For extra correctness, use a second MVar to be 
 notified that the child thread is really done --- because otherwise there 
 would be the race condition of the child thread still in the middle of 
 critical I/O when the program quits.
 
 import Control.Concurrent
 import Control.Exception(finally)
 
 data DoOrDie = Do | Die
 
 main = do
  v - newEmptyMVar
  finale - newEmptyMVar
  forkIO (timeloop v `finally` putMVar finale ())
  putStrLn press enter to quit
  getLine
  putMVar v Die
  takeMVar finale
 
 timeloop v = run where
  run = do
forkIO (threadDelay 1500  putMVar v Do)
m - takeMVar v
case m of
  Do - putStrLn checkpoint  run
  Die - putStrLn checkmate
 
 ___
 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] [web-devel] http-enumerator: redirects, streaming and keep-alive

2011-02-02 Thread Antoine Latter
On Wed, Feb 2, 2011 at 3:01 PM, Felipe Almeida Lessa
felipe.le...@gmail.com wrote:
 On Wed, Feb 2, 2011 at 6:30 PM, Antoine Latter aslat...@gmail.com wrote:
 Or you could remove the socket from the map while it's in use.

 And what about connection limits?  We shouldn't create a thousand
 connections to the same host =).


Not a bad idea, but that may be creeping outside the scope of the bug
as reported.

If you're writing a web-scraper/spider, it is true you might need some
sort of higher-level manager to handle concurrent access. I'm not sure
what that would look like, though

 --
 Felipe.


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


Re: [Haskell-cafe] timely shutdown of timer threads

2011-02-02 Thread Johan Tibell
On Wed, Feb 2, 2011 at 10:42 PM, Warren Harris warrensomeb...@gmail.com wrote:
 Interesting. I hadn't thought of this solution. You're forking the timer to 
 yet a third thread so that if it continues waiting beyond the checkpoint 
 thread shutdown it doesn't really matter. I guess that works as long as the 
 main thread doesn't wait for all other threads to terminate before 
 terminating the app.

 It still seems to me that haskell is lacking when it comes to operations that 
 can wait for multiple conditions.

I think we can make waiting for both I/O activity and timers at the
same time using the I/O manager. I will need to do this for my planned
timeout support in the network package.

Johan

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


Re: [Haskell-cafe] timely shutdown of timer threads

2011-02-02 Thread Warren Harris

On Feb 2, 2011, at 2:02 PM, Johan Tibell wrote:

 On Wed, Feb 2, 2011 at 10:42 PM, Warren Harris warrensomeb...@gmail.com 
 wrote:
 Interesting. I hadn't thought of this solution. You're forking the timer to 
 yet a third thread so that if it continues waiting beyond the checkpoint 
 thread shutdown it doesn't really matter. I guess that works as long as the 
 main thread doesn't wait for all other threads to terminate before 
 terminating the app.
 
 It still seems to me that haskell is lacking when it comes to operations 
 that can wait for multiple conditions.
 
 I think we can make waiting for both I/O activity and timers at the
 same time using the I/O manager. I will need to do this for my planned
 timeout support in the network package.

I could see wanting to wait for an MVar, timeout, IO activity, STM channels 
(anything that could block), all in the same event handler. (Rather like the 
old WaitForMultipleObjects on Windows.) This would also require a way to test 
each condition without blocking (MVar has this with tryTakeMVar, but it doesn't 
look like they all support it.)

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


[Haskell-cafe] Haskell Weekly News: Issue 167 - February 02, 2011

2011-02-02 Thread Daniel Santa Cruz
   Welcome to issue 167 of the HWN, a newsletter covering developments in
   the [1]Haskell community. This release covers the week of January 23 to
   29, 2011.

   This week I've added a section which compiles a list of the top answers
   given in StackOverflow during the week. These seem to be of more
   interest to more experienced Haskell users than the newbie questions
   usually posted on the site. See what you think.

Announcements

   R. Emre Basar [2]annouced the release of follower, a tool that allows
   you to follow people's tweets without having an account with Twitter.

   Alberto Ruiz [3]announced hmatrix version 0.11, a package for numerical
   computation based on LAPACK and SGL.

   Michael Snoyman [4]made some point updates for WAI and Warp. They fix
   some documentation issues, add some status aliases, make it possible to
   handle exceptions more easily, and make things more responsive on
   Windows.

   Antoine Latter [5]announced a minor point release for Parsec 3.1.0.

   John Meacham [6]announced version 0.7.7 of jhc is out! This release
   fixes a large number of bugs that cropped up when compiling haskell out
   in the wild as well as adds some more features. A major one being the
   garbage collector is enabled by default.

Quotes of the Week

 * Twey: Maybe Bool: the Haskell equivalent to True/False/FileNotFound
 * elliott: Only two things in the universe are certain: Death, and
   two of the libraries you've decided to use taking different types
   of ByteString.
 * shapr: my personal heuristics judge Haskell as totally practical,
   perhaps too practical.
 * monochrom: the guys that I see when I look into the irc window
   believe that I'm just a bunch of text.
 * bernardh: Refactoring: spend a week to get where you were
 * Question: How do I use fix, and how does it work? Answer (by
   TomMD): The prank answer is fix has no real use, it's just there
   so you can type 'fix error' in ghci and feel good about yourself.

Top Reddit Stories

   * Haskell at Bump
 Domain: devblog.bu.mp, Score: 44, Comments: 9
 On Reddit: http://www.reddit.com/r/haskell/comments/f8cr8/haskell_at_bump/
 Original: http://devblog.bu.mp/haskell-at-bump

   * How to write a simple TCP Server in Haskell
 Domain: catonmat.net, Score: 35, Comments: 5
 On Reddit:
http://www.reddit.com/r/haskell/comments/faa80/how_to_write_a_simple_tcp_server_in_haskell/
 Original: http://catonmat.net/blog/simple-haskell-tcp-server

   * Snap Framework article in IEEE Internet Computing
 Domain: steve.vinoski.net, Score: 32, Comments: 1
 On Reddit:
http://www.reddit.com/r/haskell/comments/fa0e0/snap_framework_article_in_ieee_internet_computing/
 Original: 
http://steve.vinoski.net/blog/2011/01/21/column-on-the-snap-framework/

   * My Dream GHCi Session, Take 2
 Domain: cdsmith.wordpress.com, Score: 23, Comments: 5
 On Reddit:
http://www.reddit.com/r/haskell/comments/f8im5/my_dream_ghci_session_take_2/
 Original: 
http://cdsmith.wordpress.com/2011/01/24/my-dream-ghci-session-take-2/

   * Text: a visual programming language based on Haskell, demo
 Domain: vimeo.com, Score: 20, Comments: 3
 On Reddit:
http://www.reddit.com/r/haskell/comments/fbgxd/text_a_visual_programming_language_based_on/
 Original: http://vimeo.com/19273744

   * Hoogle Embed
 Domain: neilmitchell.blogspot.com, Score: 16, Comments: 3
 On Reddit: http://www.reddit.com/r/haskell/comments/f7iqa/hoogle_embed/
 Original: http://neilmitchell.blogspot.com/2011/01/hoogle-embed.html

   * What does this mean for Haskell on Android?
 Domain: reddit.com, Score: 15, Comments: 12
 On Reddit:
http://www.reddit.com/r/haskell/comments/f9o67/what_does_this_mean_for_haskell_on_android/
 Original: 
http://www.reddit.com/r/Android/comments/f97zh/google_not_happy_with_number_of_android_app/c1ebkji

   * Evolving a computer with Genprog (exercises from the TECS book)
 Domain: jpmoresmau.blogspot.com, Score: 13, Comments:
 On Reddit:
http://www.reddit.com/r/haskell/comments/f7y6a/evolving_a_computer_with_genprog_exercises_from/
 Original: 
http://jpmoresmau.blogspot.com/2011/01/evolving-computer-with-tecs-and-genprog.html

   * All about MVars : Inside T5
 Domain: blog.ezyang.com, Score: 13, Comments: 4
 On Reddit:
http://www.reddit.com/r/haskell/comments/fduxb/all_about_mvars_inside_t5/
 Original: http://blog.ezyang.com/2011/02/all-about-mvars/

   * What textbooks would be useful to start approaching the
low-hanging fruit on the ghc project?
 Domain: self.haskell, Score: 12, Comments: 8
 On Reddit:
http://www.reddit.com/r/haskell/comments/f8dm5/what_textbooks_would_be_useful_to_start/
 Original: 
/r/haskell/comments/f8dm5/what_textbooks_would_be_useful_to_start/

Top StackOverflow Answers

   * What is an idiomatic way to add lists in Haskell?
 Votes: 14
 Read on SO:

Re: [Haskell-cafe] timely shutdown of timer threads

2011-02-02 Thread Albert Y. C. Lai

On 11-02-02 04:42 PM, Warren Harris wrote:

It still seems to me that haskell is lacking when it comes to operations that 
can wait for multiple conditions.


STM opens the avenue to waiting for multiple conditions.

import Control.Concurrent
import Control.Concurrent.STM
import Control.Exception(finally)

data DoOrDie = Do | Die

main = do
  die - atomically newEmptyTMVar
  finale - atomically newEmptyTMVar
  forkIO (timeloop die `finally` atomically (putTMVar finale ()))
  putStrLn press enter to quit
  getLine
  atomically (putTMVar die Die)
  atomically (takeTMVar finale)

timeloop die = run where
  run = do
w - atomically newEmptyTMVar
i - forkIO (threadDelay 1500  atomically (putTMVar w Do))
r - atomically (takeTMVar w `orElse` takeTMVar die)
case r of
  Do - putStrLn checkpoint  run
  Die - killThread i  putStrLn checkmate

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


[Haskell-cafe] Problems with iteratees

2011-02-02 Thread wren ng thornton
I'm working on a project that's using John Lato's old implementation of 
iteratees (iteratee = 0.3.5   0.4; I'm hoping to migrate to 0.7 
soon, but that's a ways off yet) and I'm running into some issues I 
haven't been able to untangle. Maybe a new set of eyes can help...


The overarching program brings three things together for doing some 
interprocess communication: the medium is Posix FIFOs, the messages 
themselves are encoded with Google's Protocol Buffers[1], and the 
control flow for getting and processing the messages is handled by 
iteratees. The error message indicates iteratees are at fault, though it 
could be an error elsewhere instead.


First, some boilerplate.

-- For messageWithLengthEnumeratee only
{-# LANGUAGE ScopedTypeVariables #-}

import qualified Text.ProtocolBuffers.Reflections as R
import qualified Text.ProtocolBuffers.WireMessage as W
import qualified Text.ProtocolBuffers.Get as G
import qualified Data.ByteString  as S
import qualified Data.ByteString.Lazy as L
import qualified Data.Iterateeas I
import   Data.Iteratee.WrappedByteString
import   Data.Word(Word8)
import   Control.Monad(liftM)


-- | Return a final value, and the remainder of the stream.
idone :: a - c el - I.IterGV c el m a
idone a xs = I.Done a (I.Chunk xs)
{-# INLINE idone #-}


-- | Convert a continuation into 'I.IterGV'.
icontinue
:: (I.StreamG c el - m (I.IterGV c el m a))
- I.IterGV c el m a
icontinue k = I.Cont (I.IterateeG k) Nothing
{-# INLINE icontinue #-}


-- | Throw an error message.
ifail :: (Monad m) = String - I.IterGV c el m a
ifail msg = ierror (I.Err msg)
{-# INLINE ifail #-}


-- | An 'I.IterGV' variant of 'I.throwErr'.
ierror :: (Monad m) = I.ErrMsg - I.IterGV c el m a
ierror err = I.Cont (I.throwErr err) (Just err)
{-# INLINE ierror #-}


toLazyBS :: S.ByteString - L.ByteString
toLazyBS = L.fromChunks . (:[])
{-# INLINE toLazyBS #-}


toStrictBS :: L.ByteString - S.ByteString
toStrictBS = S.concat . L.toChunks
{-# INLINE toStrictBS #-}

Now we have the code for converting the Get monad used by protocol 
buffers into an iteratee. This should be correct, and it's pretty 
straightforward.


-- | Convert a 'G.Result' iteratee state into a 'I.IterGV'
-- iteratee state.
result2iterv
:: (Monad m)
= G.Result a
- I.IterGV WrappedByteString Word8 m a
result2iterv (G.Finished rest _ a) = idone a (WrapBS $ toStrictBS rest)
result2iterv (G.Failed _ msg)  = ifail msg
result2iterv (G.Partial k) = I.Cont (iterify k) Nothing


-- | Convert a protobuf-style continuation into an
-- iteratee-style continuation.
iterify
:: (Monad m)
= (Maybe L.ByteString - G.Result a)
- I.IterateeG WrappedByteString Word8 m a
iterify k =
I.IterateeG $ \s - return $!
case s of
I.Chunk (WrapBS xs) - result2iterv $ k (Just $ toLazyBS xs)
I.EOF Nothing   - result2iterv $ k Nothing
I.EOF (Just err)- ierror err


-- | A variant of 'G.runGet' as an iteratee.
runGetIteratee
:: (Monad m, R.ReflectDescriptor a, W.Wire a)
= G.Get a
- I.IterateeG WrappedByteString Word8 m a
runGetIteratee g =
I.IterateeG $ \s - return $!
case s of
I.Chunk (WrapBS xs) - result2iterv $ G.runGet g (toLazyBS xs)
I.EOF Nothing   - result2iterv $ G.runGet g L.empty
I.EOF (Just err)- ierror err

Okay, now we have an iteratee which consumes a stream of bytestrings and 
will render a protocol buffer message. But what we really want is an 
enumeratee to do this repeatedly so we can use an iteratee to consume 
the stream of messages. I have the following definition which 
typechecks, but doesn't seem to work. The call to convStream seems like 
it always hangs:


-- | A variant of 'G.runGet' as an enumeratee.
runGetEnumeratee
:: (Monad m, R.ReflectDescriptor a, W.Wire a)
= G.Get a
- I.EnumeratorN WrappedByteString Word8 [] a m b
runGetEnumeratee =
I.convStream . liftM (Just . (:[])) . runGetIteratee

Once we have a working definition of runGetEnumeratee, then we can 
define the specific enumeratee we need:


-- | An enumeratee for converting bytestrings into protocol
-- buffer messages.
messageWithLengthEnumeratee
:: forall m msg a
.  (Monad m, R.ReflectDescriptor msg, W.Wire msg)
= I.EnumeratorN WrappedByteString Word8 [] msg m a
messageWithLengthEnumeratee =
   runGetEnumeratee (W.messageWithLengthGetM :: G.Get msg)

And then at the use site we have the following:

let processRequest = ... :: msg - IO ()
I.run -- run 

Re: [Haskell-cafe] Inheritance and Wrappers

2011-02-02 Thread Brandon Moore

OK, what about this as a use case then. I want to create a type class 'Term' 
with only one function in it. The function returns a 'termTag' which labels 
the 

kind of a value in a DSL.  

class Term a where
   termTag :: a - String


A user of this type-class can happily provide an instance without any other 
type 

class requirement. However, I want those types which are instances of Data to 
be 

an instance of Term automatically. On top of that, I don't want to stop the 
user 

from creating a special instance for their data type.

I want to be able to write the following instance to accomplish that:

instance Data t = Term t where
termTag = show . toConstr


A much more predictable option is to provide this default implementation
as a function

termTagData :: (Data t) = (t - String)

and let the library clients use it in their instances if the behavior is fine:

instance Term MyT where
  termTag = termTagData

And if the user wants to write a more specific instance, they should be 
welcome 

to do so:

instance Term UserDT where
termTag (...) = ...

I am not very much interested in the technical details about how things 
currently are, I am more interested in a discussion about why (if?) this would 
be considered a design flaw?


Here's one thing to consider:

Can you write a function

f :: (Data a) = a - String
f x = termTag x

It would seem the Data a = Term a instance justifies
this function, and it will always use the default instance.

Now, what happens if f is applied to a value of some type
T which is an instance of Data, but has a custom Term instance?

Brandon.


  

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


Re: [Haskell-cafe] Problems with iteratees

2011-02-02 Thread Maciej Wos
I think the problem is that the iteratee you give to I.convStream
always returns Just [something] while you should return Nothing on
EOF.

Suppose you want to have an enumeratee that adds 1 to each integer in
the stream and then use stream2list to get an iteratee that consumes
the result stream and returns it as a list:

 let iter = joinI $ (convStream (head = return . Just . (:[]) . (+1))) 
 stream2list :: IterateeG [] Int IO [Int]
 run iter
*** Exception: control message: Just (Err EOF)

Note that run simply passes EOF to iter and extracts the result.
Instead of throwing an error the code above should produce an [] (i.e.
no stream to consume, no elements in the list). This can be fixed by
checking whether the stream is empty:

 let iter = joinI $ (convStream (isFinished = maybe (head = return . Just 
 . (:[]) . (+1)) (\_ - return Nothing))) stream2list :: IterateeG [] Int IO 
 [Int]
 run iter
[]

I think you should do the same in your code:

runGetEnumeratee get =
I.convStream $ isFinished = maybe convIter (\_ - return Nothing)
where
convIter = (Just . return) `liftM` (runGetIteratee get)

When the stream is not empty, it runs (runGetIteratee get) and returns
its result wrapped in Just . (:[]). When the stream is empty, it
returns Nothing so convStream knows it is done.

-- Maciej

On Thu, Feb 3, 2011 at 10:06 AM, wren ng thornton w...@freegeek.org wrote:
 I'm working on a project that's using John Lato's old implementation of
 iteratees (iteratee = 0.3.5   0.4; I'm hoping to migrate to 0.7 soon,
 but that's a ways off yet) and I'm running into some issues I haven't been
 able to untangle. Maybe a new set of eyes can help...

 The overarching program brings three things together for doing some
 interprocess communication: the medium is Posix FIFOs, the messages
 themselves are encoded with Google's Protocol Buffers[1], and the control
 flow for getting and processing the messages is handled by iteratees. The
 error message indicates iteratees are at fault, though it could be an error
 elsewhere instead.

 First, some boilerplate.

    -- For messageWithLengthEnumeratee only
    {-# LANGUAGE ScopedTypeVariables #-}

    import qualified Text.ProtocolBuffers.Reflections as R
    import qualified Text.ProtocolBuffers.WireMessage as W
    import qualified Text.ProtocolBuffers.Get         as G
    import qualified Data.ByteString                  as S
    import qualified Data.ByteString.Lazy             as L
    import qualified Data.Iteratee                    as I
    import           Data.Iteratee.WrappedByteString
    import           Data.Word                        (Word8)
    import           Control.Monad                    (liftM)


    -- | Return a final value, and the remainder of the stream.
    idone :: a - c el - I.IterGV c el m a
    idone a xs = I.Done a (I.Chunk xs)
    {-# INLINE idone #-}


    -- | Convert a continuation into 'I.IterGV'.
    icontinue
        :: (I.StreamG c el - m (I.IterGV c el m a))
        - I.IterGV c el m a
    icontinue k = I.Cont (I.IterateeG k) Nothing
    {-# INLINE icontinue #-}


    -- | Throw an error message.
    ifail :: (Monad m) = String - I.IterGV c el m a
    ifail msg = ierror (I.Err msg)
    {-# INLINE ifail #-}


    -- | An 'I.IterGV' variant of 'I.throwErr'.
    ierror :: (Monad m) = I.ErrMsg - I.IterGV c el m a
    ierror err = I.Cont (I.throwErr err) (Just err)
    {-# INLINE ierror #-}


    toLazyBS :: S.ByteString - L.ByteString
    toLazyBS = L.fromChunks . (:[])
    {-# INLINE toLazyBS #-}


    toStrictBS :: L.ByteString - S.ByteString
    toStrictBS = S.concat . L.toChunks
    {-# INLINE toStrictBS #-}

 Now we have the code for converting the Get monad used by protocol buffers
 into an iteratee. This should be correct, and it's pretty straightforward.

    -- | Convert a 'G.Result' iteratee state into a 'I.IterGV'
    -- iteratee state.
    result2iterv
        :: (Monad m)
        = G.Result a
        - I.IterGV WrappedByteString Word8 m a
    result2iterv (G.Finished rest _ a) = idone a (WrapBS $ toStrictBS rest)
    result2iterv (G.Failed _ msg)      = ifail msg
    result2iterv (G.Partial k)         = I.Cont (iterify k) Nothing


    -- | Convert a protobuf-style continuation into an
    -- iteratee-style continuation.
    iterify
        :: (Monad m)
        = (Maybe L.ByteString - G.Result a)
        - I.IterateeG WrappedByteString Word8 m a
    iterify k =
        I.IterateeG $ \s - return $!
            case s of
            I.Chunk (WrapBS xs) - result2iterv $ k (Just $ toLazyBS xs)
            I.EOF Nothing       - result2iterv $ k Nothing
            I.EOF (Just err)    - ierror err


    -- | A variant of 'G.runGet' as an iteratee.
    runGetIteratee
        :: (Monad m, R.ReflectDescriptor a, W.Wire a)
        = G.Get a
        - I.IterateeG WrappedByteString Word8 m a
    runGetIteratee g =
        I.IterateeG $ \s - return $!
            case s of
            I.Chunk (WrapBS xs) - result2iterv $ G.runGet 

Re: [Haskell-cafe] [web-devel] http-enumerator: redirects, streaming and keep-alive

2011-02-02 Thread Michael Snoyman
On Thu, Feb 3, 2011 at 12:00 AM, Antoine Latter aslat...@gmail.com wrote:
 On Wed, Feb 2, 2011 at 3:01 PM, Felipe Almeida Lessa
 felipe.le...@gmail.com wrote:
 On Wed, Feb 2, 2011 at 6:30 PM, Antoine Latter aslat...@gmail.com wrote:
 Or you could remove the socket from the map while it's in use.

 And what about connection limits?  We shouldn't create a thousand
 connections to the same host =).


 Not a bad idea, but that may be creeping outside the scope of the bug
 as reported.

 If you're writing a web-scraper/spider, it is true you might need some
 sort of higher-level manager to handle concurrent access. I'm not sure
 what that would look like, though

 --
 Felipe.



I think Felipe's point is that using the approach I outlined, we will
never spawn more than one connection to a single host. By simply
taking the socket out of the map, there's no limit to the number of
sockets that will be created.

Michael

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


Re: [Haskell-cafe] [web-devel] http-enumerator: redirects, streaming and keep-alive

2011-02-02 Thread Antoine Latter
On Wed, Feb 2, 2011 at 11:06 PM, Michael Snoyman mich...@snoyman.com wrote:
 On Thu, Feb 3, 2011 at 12:00 AM, Antoine Latter aslat...@gmail.com wrote:
 On Wed, Feb 2, 2011 at 3:01 PM, Felipe Almeida Lessa
 felipe.le...@gmail.com wrote:
 On Wed, Feb 2, 2011 at 6:30 PM, Antoine Latter aslat...@gmail.com wrote:
 Or you could remove the socket from the map while it's in use.

 And what about connection limits?  We shouldn't create a thousand
 connections to the same host =).


 Not a bad idea, but that may be creeping outside the scope of the bug
 as reported.

 If you're writing a web-scraper/spider, it is true you might need some
 sort of higher-level manager to handle concurrent access. I'm not sure
 what that would look like, though

 --
 Felipe.



 I think Felipe's point is that using the approach I outlined, we will
 never spawn more than one connection to a single host. By simply
 taking the socket out of the map, there's no limit to the number of
 sockets that will be created.

Ah, then you would block one thread on another if the host info is in
the map? I get it.

Strictly one socket per host might be a tricky invariant to maintain -
you'd have to insert an empty socket MVar in the map on lookup
failure, and the shuffling of the nested MVars seems tricky off the
top of my head.

But even without all of that I don't think you'd be flooding the host
any more than without any keepalive support, which was what I was
getting at.

This is just speculation on my part - I don't have a stake in this, it
just sounded like an interesting problem. I'd hate to be steering this
into a design black hole.

Antoine


 Michael


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


[Haskell-cafe] Another Question

2011-02-02 Thread Navin Rustagi
hi , 

I am stuck in the following problem. 

I am maintaining  a list of  tuples of the form 
([Char],Int,Int, Int,Int) . The purpose of maintaining the tuples is that the 
program reads from a file line by line , Matches the contents with the first 
element of the tuple and updates the tuple respectively.

The precise function I am using is as follows 


tupup::Bool-[Char]-Int-Int-Int-Int-Char-([Char],Int,Int,Int,Int) 
tupup val elf els elr ell elx ys= if val then 
  case ys of  'A'  - (elf, 
els+1,elr,ell,elx) 
  'G'  - (elf,els, elr 
+1,ell,elx)
  'C'  - (elf,els,elr,  
ell 
+1,elx) 
  'T'  - (elf,els,elr,ell, 
 elx +1)
   else (elf,els,elr,ell,elx)


uptable::[[Char]]-[([Char],Int,Int,Int,Int)]-[([Char],Int,Int,Int,Int)]
uptable (xf:xs) main_array = map (\(x,y,z,r,t)- tupup (x==xf) x y z r t 
(secvalue xs) ) main_array
   
 
It gives the error ERROR - Control stack overflow. I assume it is because of 
the 
lazy evaluation . 
Is there a way to enforce strict evaluation only for the function tupup. 



Thanks, 

Navin 


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


Re: [arch-haskell] Please do not delete packages from andromeda.kiwilight.com

2011-02-02 Thread Magnus Therning
On 02/02/11 22:57, Peter Hercek wrote:
 On 02/02/2011 11:26 PM, Magnus Therning wrote:

 A way to mitigate this would be to either keep at kill list of files
 to remove and when and/or having a separate repo for these archives.
 Are there any tools that would make it easier to maintain such a kill
 list?

 How about keeping the last two versions all the time. No need to
 have a kill list. And the repository is fairly small. It should not
 be a problem if it takes two times the size.

AFAICS repo-clean can't be used then; it always keeps only the very
latest version of a package.  Is there some other tool that is more
configurable that can be used to automate such a policy?

/M

-- 
Magnus Therning  OpenPGP: 0xAB4DFBA4
email: mag...@therning.org   jabber: mag...@therning.org
twitter: magthe   http://therning.org/magnus



signature.asc
Description: OpenPGP digital signature
___
arch-haskell mailing list
arch-haskell@haskell.org
http://www.haskell.org/mailman/listinfo/arch-haskell