Re: [Haskell-cafe] Monad laws

2010-03-03 Thread David Sabel
Hi,
 thanks for all the comments.

In ghc 6.12.1 the behavior is strange:

If f is defined in the interpreter via let, then the seq-expression converges

GHCi, version 6.12.1: http://www.haskell.org/ghc/  :? for help
 let f = \x - (undefined::IO Bool)
 seq (f True) True
True

but if you build a let-expression then it diverges

 let f = \x - (undefined::IO Bool) in seq (f True) True
*** Exception: Prelude.undefined


for the first way: if you use another type, then it diverges:

 let f = \x - (undefined::Bool)
 seq (f True) True
*** Exception: Prelude.undefined

Regards,
 David


 Andrés Sicard-Ramírez schrieb:
 
 On 2 March 2010 15:44, Luke Palmer lrpal...@gmail.com
 mailto:lrpal...@gmail.com wrote:
 
 On Tue, Mar 2, 2010 at 1:17 PM, David Sabel
 sa...@ki.informatik.uni-frankfurt.de
 mailto:sa...@ki.informatik.uni-frankfurt.de wrote:
  Hi,
  when checking the first monad law (left unit) for the IO-monad
 (and also for
  the ST monad):
 
  return a = f ≡ f a
 
  I figured out that there is the distinguishing context (seq []
 True) which
  falsifies the law
  for a and f defined below
 
 
  let a = True
  let f = \x - (undefined::IO Bool)
  seq (return a = f) True
  True
  seq (f a) True
  *** Exception: Prelude.undefined
 
  Is there a side-condition of the law I missed?
 
 No, IO just doesn't obey the laws.  However, I believe it does in the
 seq-free variant of Haskell, which is nicer for reasoning.  In fact,
 this difference is precisely what you have observed: the
 distinguishing characteristic of seq-free Haskell is that (\x -
 undefined) == undefined, whereas in Haskell + seq, (\x - undefined)
 is defined.
 
 
 In GHC 6.12.1 both expressions reduce to True, but it doesn't happen in
 GHC 6.10.4. Any ideas why the behaviour is different?
 
 -- 
 Andrés
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Real-time garbage collection for Haskell

2010-03-03 Thread Neil Davies


On 2 Mar 2010, at 21:38, Simon Marlow wrote:


On 02/03/10 20:37, Luke Palmer wrote:
On Tue, Mar 2, 2010 at 7:17 AM, Simon Marlowmarlo...@gmail.com   
wrote:

For games,
though, we have a very good point that occurs regularly where we  
know
that all/most short-lived objects will no longer be referenced -  
at the

start of a fresh frame.


System.Mem.performGC is your friend, but if you're unlucky it  
might do a

major GC and then you'll get more pause than you bargained for.


Some fine-grained control might be nice here.  Eg. I could do a major
GC as a player is opening a menu, on a loading screen, when the game
is paused, or some other key points, and it might still be annoying,
but at least it wouldn't interfere with gameplay.  There is of course
the question of what happens if one of these key points doesn't  
happen

when we need to do an allocation, but... oh well.  Perhaps that could
be mitigated by saying I would rather you allocate than major GC
right now.  Are any of these options impossible, or be unreasonably
difficult to implement (I don't suspect so)?


Actually that's one thing we can do relatively easily, i.e. defer  
major GC for a while.  Due to the way GHC has a two-layer memory  
manager, the heap is a list of discontiguous blocks, so we can  
always allocate some more memory.


So it would be pretty easy to provide something like

 disableMajorGC, enableMajorGC :: IO ()

Of course leaving it disabled too long could be bad, but that's your  
responsibility.


Oh, I just checked and System.Mem.performGC actually performs a  
major GC, here's its implementation:


foreign import ccall {-safe-} performMajorGC performGC :: IO ()

to perform a minor GC (or possibly a major GC if one is due), you  
want this:


foreign import ccall {-safe-} performGC performMinorGC :: IO ()

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


Is there a similar set of runes to be able to see how much mutation  
has occurred, how much was live last GC, etc?


Neil

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


Re: [Haskell-cafe] Real-time garbage collection for Haskell

2010-03-03 Thread Neil Davies

Sorry, no.

We wanted a basic bound on the jitter - the application is not one  
that creates much (if any) long lived heap.


Having just seen Simon's email on the fact that performGC forces a  
major GC - i think that there is some

new mileage here with making the speculative GC's minor ones.

More control needs some more instrumentation of how much mutation is  
occurring and ways of estimating
how much of that is short and long lived - I know that past history is  
not necessarily a good indicator
of future actions - but visibility of the counters that being kept  
would help.


Neil

On 3 Mar 2010, at 00:00, Jason Dusek wrote:


2010/02/28 Neil Davies semanticphilosop...@googlemail.com:
I've never observed ones that size. I have an application that runs  
in 'rate
equivalent real-time' (i.e. there may be some jitter in the exact  
time of
events but it does not accumulate). It does have some visibility of  
likely
time of future events and uses that to perform some speculative  
garbage

collection.


 Do you have information on how it behaves without speculative
 GC?

--
Jason Dusek


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


[Haskell-cafe] new syntax highlighting library (lexers wanted!)

2010-03-03 Thread John MacFarlane
Cafe:

I wanted to let you know about a new syntax highlighting library
I've been working on, called 'illuminate'.  The (BSD3 licensed) code
is on github: http://github.com/jgm/illuminate

illuminate is meant eventually to replace my other highlighting library,
highlighting-kate, which is too big, slow, and memory-hungry.
In my benchmarks, illuminate is around 70X faster than highlighting-kate
and uses half the memory. It can produce output in ANSI, HTML, XHTML,
and LaTeX.  Highlighting styles can be defined independently of any
output format.

So far I've written lexers for haskell, literate haskell, cabal,
alex, c, c++, c#, python, ruby, java, html, rhtml, xml, javascript, css,
tex, and bibtex.  Want to highlight a language not on this list?  Why
not help out by writing a lexer? (Study the lexer for a similar language
to get started; if you aren't familiar with Alex, you may want to look
at the Alex User Guide too. And let me know if you have any questions.)

John

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


Re: [Haskell-cafe] A few ideas about FRP and arbitrary access in time

2010-03-03 Thread Patai Gergely
 ...Are hereby presented at:
 http://www.ee.bgu.ac.il/~noamle/_downloads/gaccum.pdf
 
 Comments are more than welcome.
 (P.S Thanks to a whole bunch of people at #haskell for educating me about
 this, but most notably Conal Elliott)

Well, my impression is that trying to unite events and behaviours in
this manner is not the solution we're looking for. If you follow the
WWRD principle, you have to forget about events as fundamental building
blocks, because the concept of event is an abstraction over continuous
phenomena. Reality has a trivial solution: throw extreme parallelism at
the problem, set an extremely high sampling rate and shamelessly
'recalculate' unchanging parts of the system all the time (which is
exactly why you don't want to use Yampa or Elerea for GUI programming:
they are pull-based, so they'll keep the CPU churning even in the
absence of events; note also that both solve the problem of unlimited
access to the past). In this framework, events can only be introduced as
high-level abstractions that require much more computational power than
what would seem necessary. It is a bit like using a large and complex
neural network to perform basic arithmetic.

Also, if you think about the applicative, monad etc. type class
morphisms, you'll see that what makes sense for behaviours is completely
useless for events. For instance, the applicative instance for
behaviours (time functions) gives us a neat point-wise function
application. However, if you define events as functions that are
undefined almost everywhere, point-wise application of two events is
only defined at the times where both events yield a value
simultaneously. Same for monads: they capture the act of sampling for
behaviours, but they can't do much for temporal values that are mostly
undefined if interpreted as the reader monad. This suggests that events
and behaviours have a different nature. Either only behaviours have a
meaningful monad instance, or their meaningful monad instances are
different.

The unified system you're describing very much reminds me of Lucid
Synchrone, if we think of behaviours as signals synchronised to the base
clock, while events as signals with a slower clock. It might be
interesting to think about how clock calculus interacts with the type
class instances. However, that still doesn't say anything about the fact
that the set of operations meaningful for behaviours and events are
different, with only some overlap.

Gergely

-- 
http://www.fastmail.fm - Does exactly what it says on the tin

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


Re: [Haskell-cafe] Prelude.undefined

2010-03-03 Thread Ben Millwood
On Wed, Mar 3, 2010 at 6:15 AM, Ivan Miljenovic
ivan.miljeno...@gmail.com wrote:
 On 3 March 2010 16:11, Tom Hawkins tomahawk...@gmail.com wrote:
 -Wall only complains about shadow bindings, defined but not used, and
 no type signature.  But no unmatched patterns.

 Yes it does: one of the options it brings in is
 -fwarn-incomplete-patterns which tells you if you've missed a pattern
 match.

 http://www.haskell.org/ghc/docs/latest/html/users_guide/options-sanity.html


I think he meant that it doesn't because he doesn't have any :)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Real-time garbage collection for Haskell

2010-03-03 Thread Simon Marlow

On 03/03/2010 08:43, Neil Davies wrote:


On 2 Mar 2010, at 21:38, Simon Marlow wrote:


On 02/03/10 20:37, Luke Palmer wrote:

On Tue, Mar 2, 2010 at 7:17 AM, Simon Marlowmarlo...@gmail.com wrote:

For games,
though, we have a very good point that occurs regularly where we know
that all/most short-lived objects will no longer be referenced - at
the
start of a fresh frame.


System.Mem.performGC is your friend, but if you're unlucky it might
do a
major GC and then you'll get more pause than you bargained for.


Some fine-grained control might be nice here. Eg. I could do a major
GC as a player is opening a menu, on a loading screen, when the game
is paused, or some other key points, and it might still be annoying,
but at least it wouldn't interfere with gameplay. There is of course
the question of what happens if one of these key points doesn't happen
when we need to do an allocation, but... oh well. Perhaps that could
be mitigated by saying I would rather you allocate than major GC
right now. Are any of these options impossible, or be unreasonably
difficult to implement (I don't suspect so)?


Actually that's one thing we can do relatively easily, i.e. defer
major GC for a while. Due to the way GHC has a two-layer memory
manager, the heap is a list of discontiguous blocks, so we can always
allocate some more memory.

So it would be pretty easy to provide something like

disableMajorGC, enableMajorGC :: IO ()

Of course leaving it disabled too long could be bad, but that's your
responsibility.

Oh, I just checked and System.Mem.performGC actually performs a major
GC, here's its implementation:

foreign import ccall {-safe-} performMajorGC performGC :: IO ()

to perform a minor GC (or possibly a major GC if one is due), you want
this:

foreign import ccall {-safe-} performGC performMinorGC :: IO ()

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


Is there a similar set of runes to be able to see how much mutation has
occurred, how much was live last GC, etc?


No, but there could be - the information is collected by the RTS, it 
just isn't made available via a public API right now.


Cheers,
Simon

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


Re: [Haskell-cafe] references for compiler optimizations for functional languages

2010-03-03 Thread Chris Eidhof
I'd like to add Urban Boquist's thesis to that list:

http://www.cs.chalmers.se/~boquist/phd/index.html

(I've added it to the wiki page as well).

-chris

On 1 mrt 2010, at 22:26, Don Stewart wrote:

 mvanier42:
 Hi everyone,
 
 I'm interested in collecting good references for compiler optimizations  
 for functional languages (lazy, strict, statically-typed or not).  Any  
 suggestions?
 
 
 There's lots for what GHC implements on SimonPJ's site:
 
http://www.research.microsoft.com/~simonpj/Papers/inlining/index.htm
 
http://research.microsoft.com/en-us/um/people/simonpj/papers/cpr/index.htm
 

 http://research.microsoft.com/en-us/um/people/simonpj/papers/usage-types/usage.htm
 

 http://research.microsoft.com/en-us/um/people/simonpj/papers/comp-by-trans-scp.ps.gz
 

 http://research.microsoft.com/en-us/um/people/simonpj/papers/andy-thesis.ps.gz
 

 http://research.microsoft.com/en-us/um/people/simonpj/papers/deforestation-short-cut.ps.Z
 
http://www.cse.unsw.edu.au/~dons/papers/CLS07.html :)
 
 I've collected many of them here:
 

 http://haskell.org/haskellwiki/Research_papers/Compilation#Compiler_Analyses
 
 -- Don
 ___
 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] using haskell to serve with apache

2010-03-03 Thread Chris Eidhof
We run a couple of Happstack processes with FastCGI, and it works like a charm. 
We even wrote a module for it:

http://hackage.haskell.org/package/happstack-fastcgi

-chris

On 1 mrt 2010, at 20:19, Yitzchak Gale wrote:

 brad clawsie wrote:
 should i just try out something based on fastcgi?
 
 Obviously it depends on exactly what you want to do.
 
 For a simple very low volume page, even cgi should be
 just fine. I use it all the time.
 
 Regards,
 Yitz
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

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


[Haskell-cafe] Re: GHC's parallel garbage collector -- what am I doing wrong?

2010-03-03 Thread Simon Marlow

On 01/03/2010 21:20, Michael Lesniak wrote:

Hello Bryan,


The parallel GC currently doesn't behave well with concurrent programs that
uses multiple capabilities (aka OS threads), and the behaviour you see is
the known symptom of this.. I believe that Simon Marlow has some fixes in
hand that may go into 6.12.2.


It's more correct to say the parallel GC has difficulty when one of its 
threads is descheduled by the OS, because the other threads just spin 
waiting for it.  Presumably some kernels are more susceptible than 
others due to differences in scheduling policy, I know they've been 
fiddling around with this a lot in Linux recently.


You typically don't see a problem when there are spare cores, the 
slowdown manifests when you are trying to use all the cores in your 
machine, so it affects people on dual-cores quite a lot. This probably 
explains why I've not been particularly affected by this myself, since I 
do most of my benchmarking on an 8-core box.


The fix that will be in 6.12.2 is to insert some yields, so that threads 
will yield rather than spinning indefinitely, and this seems to help a lot.


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


Re: [Haskell-cafe] Monad laws

2010-03-03 Thread Yitzchak Gale
Hi Luke,

I wrote:
 For this reason, I consider it a bug in GHC that return :: IO a
 is lazy.

Luke Palmer wrote:
 Wait a minute...

   return undefined = const (return 42)
 = const (return 42) undefined
 = return 42

 But if return undefined = undefined, then that equals;

  undefined = const (return 42)

Hmm, this is true.

OK, so let's explicitly restate the monad laws in this context:

(= f) .! return == f
(= return) == id
(= f) .! (= g) == (= (= f) .! g)

David's original problem was with the second law, when
you apply the function on both sides to undefined. Let's
verify the existence of that problem in the current notation:

Prelude seq ((= return) (undefined :: IO Bool)) 42
42
Prelude seq (id (undefined :: IO Bool)) 42
*** Exception: Prelude.undefined

To satisfy the second law, we need:

(= return) undefined == undefined

Why is this not working? Apparently, (=)
is lazy in its first argument. Then, since
return is also lazy, GHC never even looks
at the first argument. It just stuffs the operation
that includes looking at the first argument into
the return-thunk.

So there are exactly two ways to satisfy the
second law:

either (=) must be strict in its first argument,
or return must be strict.

I thought the simplest way out of this would
be to make return strict. I didn't notice that
there is a problem with it. But you have pointed
out that I was being too cavalier.

So I now amend my GHC bug report to say:
(=) must be strict in its first argument.

Does that sound better to you?

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


Re: [Haskell-cafe] Prelude.undefined

2010-03-03 Thread Tom Hawkins
On Wed, Mar 3, 2010 at 7:15 AM, Ivan Miljenovic
ivan.miljeno...@gmail.com wrote:
 On 3 March 2010 16:11, Tom Hawkins tomahawk...@gmail.com wrote:
 -Wall only complains about shadow bindings, defined but not used, and
 no type signature.  But no unmatched patterns.

 Yes it does: one of the options it brings in is
 -fwarn-incomplete-patterns which tells you if you've missed a pattern
 match.

Sorry, I should have been more clear.  When I run the program with
-Wall, the only warnings I get are shadow bindings, values defined by
not used, and a couple values without a type signature.  But I don't
get any warnings about either unmatched patterns or overlapping
patterns.

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


Re: [Haskell-cafe] Prelude.undefined

2010-03-03 Thread Tom Hawkins
On Wed, Mar 3, 2010 at 7:24 AM, Alexander Dunlap
alexander.dun...@gmail.com wrote:
 On Tue, Mar 2, 2010 at 9:06 PM, Tom Hawkins tomahawk...@gmail.com wrote:
 How do I track down an reference to an undefined value?  My program
 must not be using a library correctly because the program makes no
 direct use of 'undefined'.  Running with +RTS -xc yields:


 While the debugger, etc., are very useful tools, I find that often the
 easiest way to track down this sort of bug is to test your code
 function-by-function.

The debugger was not that helpful, so I may have to resort to this.

Is there any work being done to improve reporting for these type of
errors?  It seems to be a fairly common problem.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] minimal interface

2010-03-03 Thread Sean McLaughlin
Hi Ivan,

  I ran SourceGraph on the program above.  Could you help me find where A.g
is unused?
In particular, I can't see a difference in the output in the following
cases:

main = do
  let a = A.f 7
  putStrLn $ show a

main = do
  let a = A.f $ A.g 7
  putStrLn $ show a

Thanks!

Sean

On Tue, Mar 2, 2010 at 5:14 PM, Ivan Miljenovic
ivan.miljeno...@gmail.comwrote:

 On 3 March 2010 08:25, Sean McLaughlin sean...@gmail.com wrote:
  For instance, if module A exports f, but A.f is never used in my compiled
 program,
  I would like to be warned of this fact.

 My SourceGraph program (
 http://hackage.haskell.org/package/SourceGraph ) does this, but you'll
 have to look through the generated report to find it.

 --
 Ivan Lazar Miljenovic
 ivan.miljeno...@gmail.com
 IvanMiljenovic.wordpress.com

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


Re: [Haskell-cafe] Prelude.undefined

2010-03-03 Thread Gwern Branwen
On Wed, Mar 3, 2010 at 10:56 AM, Tom Hawkins tomahawk...@gmail.com wrote:
 On Wed, Mar 3, 2010 at 7:24 AM, Alexander Dunlap
 alexander.dun...@gmail.com wrote:
 On Tue, Mar 2, 2010 at 9:06 PM, Tom Hawkins tomahawk...@gmail.com wrote:
 How do I track down an reference to an undefined value?  My program
 must not be using a library correctly because the program makes no
 direct use of 'undefined'.  Running with +RTS -xc yields:


 While the debugger, etc., are very useful tools, I find that often the
 easiest way to track down this sort of bug is to test your code
 function-by-function.

 The debugger was not that helpful, so I may have to resort to this.

 Is there any work being done to improve reporting for these type of
 errors?  It seems to be a fairly common problem.

You try the Interlude? http://hackage.haskell.org/package/interlude

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


[Haskell-cafe] Re: Prelude.undefined

2010-03-03 Thread Achim Schneider
Tom Hawkins tomahawk...@gmail.com wrote:

 The debugger was not that helpful, so I may have to resort to this.
 
 Is there any work being done to improve reporting for these type of
 errors?  It seems to be a fairly common problem.

http://hackage.haskell.org/trac/ghc/wiki/ExplicitCallStack

-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.


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


Re: [Haskell-cafe] Real-time garbage collection for Haskell

2010-03-03 Thread Sönke Hahn
On Monday 01 March 2010 03:16:25 pm Sönke Hahn wrote:
 
 Yes there are. I am working on a game with Haskell using OpenGL rendering.
 I've done some frame time measurements lately and encountered single frames
 needing more than 100ms to be rendered. I am currently trying to gather
 information on what is going on in these 100ms and why. From what i
 understand, the GC is running very often and just some (very few) of its
 runs are very slow.

FYI: These high frame times were caused by a space leak. With the help of the 
excellent hp2any-manager i found that out and where to put the needed 
strictness annotations.

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


[Haskell-cafe] how to get a string from file

2010-03-03 Thread Pradeep Wickramanayake
 

getItemFile :: IO String

getItemFile test = 

do

test - readFile input.txt

return test

 

this is the program I did to take a file and get all the data from that file
to a string. 

 

Can someone help me. 

 

I get this error

 

Type error in explicitly typed binding

*** Term   : getItemFile

*** Type   : a - IO [Char]

*** Does not match : IO String

 

What I need is to get the file to a string and then get it to a tuple by
checking each places where the file contain a blank space

 

Please help me 

 

Thanks

 

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


Re: [Haskell-cafe] how to get a string from file

2010-03-03 Thread Thomas DuBuisson
On Wed, Mar 3, 2010 at 10:26 AM, Pradeep Wickramanayake prad...@talk.lk wrote:
 getItemFile :: IO String

This says getItemFile is an action that returns a string.  No arguments.

 getItemFile test = ...

And your implementation obviously requires a file path as an argument.
 You wanted a type signature of:

getItemFile :: FilePath - IO String

or perhaps more simply (FilePath is just an alias for String):

getItemFile :: String - IO String

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


Re: [Haskell-cafe] How do you rewrite your code?

2010-03-03 Thread Stephen Tetley
On 2 March 2010 19:20, Sean Leather leat...@cs.uu.nl wrote:

 My question is simple:

    How do you rewrite your code to improve it?



Hi Sean - excellent question!

Some things I do...

Quite often I do a 'worker-wrapper-lite' rewrite i.e. change a
function to perform its recursive work in a step rather than calling
the function again with all the arguments, e.g.


 para :: (a - ([a], b) - b) - b - [a] - b
 para phi b = step
    where step []     = b
          step (x:xs) = phi x (xs, step xs)


rather than...

 para_ :: (a - ([a], b) - b) - b - [a] - b
 para_ phi b []     = b
 para_ phi b (x:xs) = phi x (xs, para_ phi b xs)

I'm doing no type changing to improve efficiency so it isn't a real
worker-wrapper, but I usually find the 'step' style more pleasing,
especially when the code is somewhat more complicated than the
paramorphism above.


Another one is to eliminate do-notation, generally I do this by using
the liftM2 family more appropriately, sometimes by using my own
monadic combinators - for instance quite a few operators in
Control.Exception are useful for other monads rather than IO so I've
versions with more general types in the Utils module that add to my
projects once they get above a certain size.

Generally my types change only when I realize I hadn't got them right
in the first instance. I can't think of instances where I've
generalized types to make them functors and so could use Traversable,
Foldable... But I have had a couple instances where I've needed to
change the type of a 'leaf' in a structure so realized that the
containing structure was obviously a functor.


Best wishes

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


Re: [Haskell-cafe] How do you rewrite your code?

2010-03-03 Thread Max Bolingbroke
Something I've been doing a lot lately is selective
defunctionalisation, transformation into continuation passing style,
and the combination of both things (CPS followed by defunctionalising
the continuations). This is probably because I'm playing around with
lambda calculus evaluators a lot though :-) (see Olivier Danvy's
homepage for more: http://www.cs.au.dk/~danvy/)

Cheers,
Max

On 2 March 2010 19:20, Sean Leather leat...@cs.uu.nl wrote:
 There are numerous threads on the Haskell Café involving rewriting,
 refactoring, refining, and in general improving code (for some definition of
 improve). I am interested in seeing examples of how Haskell code can be
 rewritten to make it better. Some general examples are:

 Eta-reduce
 Make more pointfree
 Introduce monadic operators or do-notation

 e.g. for Maybe, lists, State

 Eliminate monadic operators or do-notation
 Generalize types

 e.g. change map to fmap, (++) to mappend

 Use instances of Functor, Applicative, Alternative, Category, Arrow, Monoid,
 Traversable, etc.
 Use library functions from Data.List, Data.Map, Data.Set, etc.
 Use some form of generic programming (e.g. SYB, Uniplate, EMGM, Alloy)
 Use other libraries not included in the Platform

 My question is simple:

    How do you rewrite your code to improve it?

 You can answer this in any way you like, but I think the most useful answer
 is to show a reasonably small, concrete example of what your code looked
 like before and after. Also, please describe how you think the rewrite
 improves such code.

 Is it better style? More useful? More efficient?
 Are the types (before and after) the same?
 Are the semantics the same?
 How did you prove or test equivalence? (e.g. Can you use equational
 reasoning to confirm the rewrite is valid? Did you use QuickCheck?)

 Here is an example that I find myself doing occasionally.

 For all x, f:

 x = return . f
 --
 fmap f x
 or
 f $ x -- requires importing Control.Applicative

 I think the right-hand side (RHS) is more concise and simpler. The types
 here do change: the type constructor has a Monad constraint in the left-hand
 side and a Functor constraint in the RHS. Types that are Monad instances are
 generally also Functor instances, so this is often possible. I'm convinced
 the semantics are preserved, though I haven't proven it.

 What's an example of a rewrite that you've encountered?

 Thanks,
 Sean

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


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


[Haskell-cafe] Re: A few ideas about FRP and arbitrary access in time

2010-03-03 Thread sinelaw
 Well, my impression is that trying to unite events and behaviours in
 this manner is not the solution we're looking for. If you follow the
 WWRD principle, you have to forget about events as fundamental building
 blocks, because the concept of event is an abstraction over continuous
 phenomena.

I'm not sure I want to follow WWRD all the way. I do want events, for
example mouse clicks (for which there doesn't seem to be any logical
behavior representation). As you note the pull-based approach does a
lot more work in those cases than seems necessary.

In any case, what I'm discussing in that report is mostly centered on
the continuous-time values, so I'm more concerned with what we call
behaviors. The question is how to model memory-full operations with
point-wise operations. The only answer I've found for that in the
Yampa framework is feedback with pre, whose semantics seem to be the
value after a very short delay. This doesn't seem to hold water,
when we really want to take the idea of continuous time seriously.


 Reality has a trivial solution: throw extreme parallelism at
 the problem, set an extremely high sampling rate and shamelessly
 'recalculate' unchanging parts of the system all the time (which is
 exactly why you don't want to use Yampa or Elerea for GUI programming:
 they are pull-based, so they'll keep the CPU churning even in the
 absence of events; note also that both solve the problem of unlimited
 access to the past). In this framework, events can only be introduced as
 high-level abstractions that require much more computational power than
 what would seem necessary. It is a bit like using a large and complex
 neural network to perform basic arithmetic.

Right. You'll agree that it would be nice to have a general approach?
How will that work? That's what I'd like to find out.

 Also, if you think about the applicative, monad etc. type class
 morphisms, you'll see that what makes sense for behaviours is completely
 useless for events. For instance, the applicative instance for
 behaviours (time functions) gives us a neat point-wise function
 application. However, if you define events as functions that are
 undefined almost everywhere, point-wise application of two events is
 only defined at the times where both events yield a value
 simultaneously. Same for monads: they capture the act of sampling for
 behaviours, but they can't do much for temporal values that are mostly
 undefined if interpreted as the reader monad. This suggests that events
 and behaviours have a different nature. Either only behaviours have a
 meaningful monad instance, or their meaningful monad instances are
 different.

Interesting points, I didn't consider that at all when writing that
report. I'd like things to be unified, so maybe playing with the idea
of a total function to 'Maybe a' for events is the right direction. I
think this was already explored by some FRP incarnations, but I don't
recall what came out of it.

 The unified system you're describing very much reminds me of Lucid
 Synchrone, if we think of behaviours as signals synchronised to the base
 clock, while events as signals with a slower clock. It might be
 interesting to think about how clock calculus interacts with the type
 class instances. However, that still doesn't say anything about the fact
 that the set of operations meaningful for behaviours and events are
 different, with only some overlap.

But isn't Lucid Synchrone essentially discrete-timed? Also, events
shouldn't be semantically constrained to multiples of some basic
clock, they are defined over continuous time. Regarding the type
classes - again I haven't thought in that direction much.



 Gergely

P.S Thanks for the feedback!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] how to send a string to a tuple

2010-03-03 Thread Pradeep Wickramanayake
Hi

 

I have taken a string output from a file

 

But I want to send that string to another function which will convert in to
a tuple

 

Can someone teach me please

 

 

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


Re: [Haskell-cafe] how to send a string to a tuple

2010-03-03 Thread Magnus Therning
On 03/03/10 19:51, Pradeep Wickramanayake wrote:
 Hi
 
 I have taken a string output from a file
 
 But I want to send that string to another function which will convert in
 to a tuple
 
 Can someone teach me please

May I suggest that you move this over to haskell-beginners instead?

Also, include any code you have so far.  You're more likely to get answers if
you include the code you are having problems with.

/M

-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe



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


[Haskell-cafe] How do you set up windows enviroment

2010-03-03 Thread Maciej Piechotka
How do you set up Windows environment? I'd like to develop few
platform-specific code or rather port it to this platform.

I tried to set up environment but I failed (darcs hanging on copy via
ssh, command line is... well slightly better then in W98 etc.).

Does anyone have a tips for setting Haskell environment on Windows 7.

Regards


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


Re: [Haskell-cafe] segmentation fault with ghc-6.10.4 on linux-x86_x64

2010-03-03 Thread Thomas Schilling
This wiki page has some tips on how to debug compiled code.
http://hackage.haskell.org/trac/ghc/wiki/Debugging/CompiledCode

It mentions some parts specific to debugging the GHC code generator,
so some parts may not be relevant to your case.

HTH

On 2 March 2010 10:29, Wim Vanderbauwhede wim.vanderbauwh...@gmail.com wrote:
 Hello,

 I'm writing a compiler and it segfaults when compiled with  ghc-6.10.4
 on linux-x86_x64.
 It runs fine when compiled with ghc-6.10.4 on Mac OS X 10.5 (64-bit
 Intel) and with ghc-6.8.2 on Mac OS X 10.4 (32-bit PPC).
 I use the Haskell platform, the ghc -v output is

 Glasgow Haskell Compiler, Version 6.10.4, for Haskell 98, stage 2
 booted by GHC version 6.8.2
 Using package config file: /usr/local/lib/ghc-6.10.4/./package.conf
 Using package config file: /users/wim/.ghc/x86_64-linux-6.10.4/package.conf
 hiding package base-3.0.3.1 to avoid conflict with later version base-4.1.0.0
 hiding package network-2.2.1.2 to avoid conflict with later version
 network-2.2.1.4
 hiding package time-1.1.2.4 to avoid conflict with later version time-1.1.4
 wired-in package ghc-prim mapped to ghc-prim-0.1.0.0
 wired-in package integer mapped to integer-0.1.0.1
 wired-in package base mapped to base-4.1.0.0
 wired-in package rts mapped to rts-1.0
 wired-in package haskell98 mapped to haskell98-1.0.1.0
 wired-in package syb mapped to syb-0.1.0.1
 wired-in package template-haskell mapped to template-haskell-2.3.0.1
 wired-in package dph-seq mapped to dph-seq-0.3
 wired-in package dph-par mapped to dph-par-0.3



 The offending code is (simplified)

     mapM emit (sc_args sc)

 with

    sc::ServiceCall
    data ServiceCall = MkServiceCall { sc_args::[Expr], ... }
    data Expr = PureE (PString String) | ...

 and emit defined via a type class EmitG:

    emitExpr (PureE e) = emit e
   instance EmitG Expr where emit = emitExpr

    emitPureExpr (PString s) = return $ show s
    instance EmitG PureExpr where emit = emitPureExpr

 So it actually maps show over a list of strings.

 The compiler parses a test program, the segfault occurs when emitting
 code for lines like
  ImgBlock() img1 = img.in(img.raw);
 (a service call in my language)
 Replacing the string by a number of any other type of the AST makes no
 difference.

 It looks like a bug in ghc's memory allocation. Any suggestions on how
 to debug this?


 Thanks!

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




-- 
Push the envelope.  Watch it bend.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: A few ideas about FRP and arbitrary access in time

2010-03-03 Thread Donn Cave
Kind of a long shot, from what I can make out, but Timber might be
interesting - Haskell-like programming language with a reactive model
that supports time as a sort of event.  http://www.timber-lang.org/

Certainly not much like what we're talking about, but I haven't picked
up on the application domain of `behaviors' - for all I know that's
just about working around the lack of support for time events.

Donn

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


[Haskell-cafe] Re: A few ideas about FRP and arbitrary access in time

2010-03-03 Thread sinelaw
On Mar 3, 10:50 pm, Donn Cave d...@avvanta.com wrote:
 Kind of a long shot, from what I can make out, but Timber might be
 interesting - Haskell-like programming language with a reactive model
 that supports time as a sort of event.  http://www.timber-lang.org/

 Certainly not much like what we're talking about, but I haven't picked
 up on the application domain of `behaviors' - for all I know that's
 just about working around the lack of support for time events.

         Donn


Thanks, timber looks interesting and definitely worth looking at .

Behaviors are used to represent values that change continuously with
time. Even if the implementation is discrete (as all digital
hardware), it may be more natural to treat things such as a
temperature sensor, mouse position, and perhaps even video as
functions of continuous time, values that vary continuously. So
behaviors are not a workaround at all, in this sense.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How do you set up windows enviroment

2010-03-03 Thread Stephen Tetley
On 3 March 2010 20:26, Maciej Piechotka uzytkown...@gmail.com wrote:

 How do you set up Windows environment?

Hi Maciej

I use both Cygwin and MinGW / MSYS on Win XP.

Out of habit I'd always used Cygwin for non-Haskell stuff, so it was
natural to use it for Haskell. Then I found I needed to use MinGW /
MSYS to compile certain Haskell libs with C / FFI dependencies - some
libraries just won't build on Cygwin.

The terminal used to be below par for MSYS but its improved a lot
recently, if I was starting from fresh I'd probably see how far I
could go with just MinGW / MSYS. For darcs and SSH, Cygwin might be
better though.


For editing code I use Emacs - I've never got it to work viably with
the Cygwin Bash shell in inferior mode (?), so I simply have a Cygwin
terminal running GHCi under Bash and Emacs for editing code then
Alt-Tab between them.

Best wishes

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


[Haskell-cafe] Re: How do you rewrite your code?

2010-03-03 Thread Sean Leather
*How do you rewrite your code to improve it?*


Edward Kmett just introduced one in another thread. Simplifying, it would be
this:

For all x, y, f:

do { x' - x ; y' - y ; return (f x' y') }
--
f $ x * y

This is a great example, because (1) it reduces clutter and temporary
names and (2) requires significant background knowledge on monads and
idioms. We can also generalize this to functions f with increasing arity (f
$ x * y * z, etc.). Beginners would not get this, but once you know
this rule, it can greatly improve your coding style. Similarly with liftM2,
liftM3, etc. as mentioned by Stephen.

Any other useful tidbits to share?

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


Re: [Haskell-cafe] minimal interface

2010-03-03 Thread Ivan Miljenovic
On 4 March 2010 02:57, Sean McLaughlin sean...@gmail.com wrote:
 Hi Ivan,
   I ran SourceGraph on the program above.  Could you help me find where A.g
 is unused?
 In particular, I can't see a difference in the output in the following
 cases:
 main = do
   let a = A.f 7
   putStrLn $ show a
 main = do
   let a = A.f $ A.g 7
   putStrLn $ show a

Is that the complete file?  If so, then it's probably a bug.

(Maybe we should continue this off-list.)

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


Re: [Haskell-cafe] how to get a string from file

2010-03-03 Thread Ben Millwood
On Wed, Mar 3, 2010 at 6:30 PM, Thomas DuBuisson
thomas.dubuis...@gmail.com wrote:
 On Wed, Mar 3, 2010 at 10:26 AM, Pradeep Wickramanayake prad...@talk.lk 
 wrote:
 getItemFile :: IO String

 This says getItemFile is an action that returns a string.  No arguments.

 getItemFile test = ...

 And your implementation obviously requires a file path as an argument.
  You wanted a type signature of:

 getItemFile :: FilePath - IO String

 or perhaps more simply (FilePath is just an alias for String):

 getItemFile :: String - IO String

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


Or maybe you just want:
getItemFile = do
 test - readFile input.txt
 return test

i.e. exactly what you have but without the argument.
This is actually exactly the same as

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


Re: [Haskell-cafe] Real-time garbage collection for Haskell

2010-03-03 Thread Henning Thielemann

Jeremy Shaw schrieb:
My feeling right now is that the 'best' solution might be something 
similar to synthesis OS. I would create a DSL for the realtime DSP 
code. Using harpy, this DSL would be compiled to assembly with 
execution time guarantees (as much as can be predicted on modern 
hardware). For a 'modular synth' this might actually be better than C 
code, because the effects of certain choices could be 'compiled in' 
instead of having to check the setting via a compare. (that is what 
Synthesis OS does).
I'm currently doing this with LLVM - which is more portable and better 
optimizing than a plain X86 assembler:

  http://code.haskell.org/synthesizer/llvm/

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


Re: [Haskell-cafe] How do you set up windows enviroment

2010-03-03 Thread Magnus Therning
On Wed, Mar 3, 2010 at 20:26, Maciej Piechotka uzytkown...@gmail.com wrote:
 How do you set up Windows environment? I'd like to develop few
 platform-specific code or rather port it to this platform.

 I tried to set up environment but I failed (darcs hanging on copy via
 ssh, command line is... well slightly better then in W98 etc.).

 Does anyone have a tips for setting Haskell environment on Windows 7.

http://stackoverflow.com/questions/304614/haskell-on-windows-setup

/M

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


Re: [Haskell-cafe] How do you set up windows enviroment

2010-03-03 Thread Henk-Jan van Tuyl
On Wed, 03 Mar 2010 21:26:59 +0100, Maciej Piechotka  
uzytkown...@gmail.com wrote:



How do you set up Windows environment? I'd like to develop few
platform-specific code or rather port it to this platform.


You can find a lot of tips at:
  http://www.haskell.org/haskellwiki/Windows
Please add information to this page if you find something missing.

Regards,
Henk-Jan van Tuyl


--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How do you rewrite your code?

2010-03-03 Thread Henning Thielemann

Stephen Tetley schrieb:

On 2 March 2010 19:20, Sean Leather leat...@cs.uu.nl wrote:

  

My question is simple:

   How do you rewrite your code to improve it?





Hi Sean - excellent question!

Some things I do...

Quite often I do a 'worker-wrapper-lite' rewrite i.e. change a
function to perform its recursive work in a step rather than calling
the function again with all the arguments, e.g.


  

para :: (a - ([a], b) - b) - b - [a] - b
para phi b = step
   where step [] = b
 step (x:xs) = phi x (xs, step xs)




rather than...

  

para_ :: (a - ([a], b) - b) - b - [a] - b
para_ phi b [] = b
para_ phi b (x:xs) = phi x (xs, para_ phi b xs)



I'm doing no type changing to improve efficiency so it isn't a real
worker-wrapper, but I usually find the 'step' style more pleasing,
especially when the code is somewhat more complicated than the
paramorphism above.
  

Me too.
http://haskell.org/haskellwiki/Top-level_vs._local_recursion

I have written some articles in Category:Style on that topic.

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


Re: [Haskell-cafe] Re: A few ideas about FRP and arbitrary access in time

2010-03-03 Thread Conal Elliott

 Even if the implementation is discrete (as all digital hardware), it may be
 more natural to treat things such as a temperature sensor, mouse position,
 and perhaps even video as functions of continuous time, values that vary
 continuously. So behaviors are not a workaround at all, in this sense.


Just as we program with infinite lists etc even though the implementation is
finite.  In this way, implementations serve
abstractions/semantics/specifications, rather than vice versa.  See also
http://conal.net/blog/posts/why-program-with-continuous-time/ .

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


[Haskell-cafe] Re: How do you rewrite your code?

2010-03-03 Thread Günther Schmidt

Hi Sean,

that's certainly *the* question I try to solve too. My thoughts on this 
are a bit different from the answers I've seen here so far, apart maybe 
from the Contracts response.


All my code, whether neat or not so neat is still way too concrete, too 
direct.
I think the correct answer is one should try to find abstractions and 
not code straight down to the point. Which to me is still a really tough 
one, I have to admit.


Günther


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


[Haskell-cafe] Re: Has anybody translated Douglas Hofstadter's Scientific American articles introducting Scheme to a general audience into Haskell?

2010-03-03 Thread Benjamin L. Russell
Gwern Branwen gwe...@gmail.com writes:

 On Tue, Mar 2, 2010 at 1:04 AM, Benjamin L. Russell
 dekudekup...@yahoo.com wrote:
 There is an interesting, if somewhat dated, suggestion on Lambda the
 Ultimate (see http://lambda-the-ultimate.org/node/1748) that someone
 translate Doug Hofstadter's Scientific American columns introducing
 Scheme to a general audience into Haskell.

 (I came across this link while adding full titles and links to the
 HaskellWiki Books and tutorials page (see
 http://www.haskell.org/haskellwiki/Books_and_tutorials), where I clicked
 on the link to Tutorials (see
 http://www.haskell.org/haskellwiki/Tutorials), which contained a link to
 a Haskell vs. Scheme (see http://www.reddit.com/r/programming/tb/nq1k)
 article, which described the post containing the suggestion.)

 According to a comment by Ehud Lamm (see
 http://lambda-the-ultimate.org/node/1748#comment-21292) on the above
 post, the columns are in Hoftstadter's book _Metamagical Themas:
 Questing For The Essence Of Mind And Pattern_ [1] (see
 http://www.amazon.com/Metamagical-Themas-Questing-Essence-Pattern/dp/0465045669).

 Has anybody translated Hofstadter's articles from Scheme into Haskell?

 -- Benjamin L. Russell

 I have scans of the column and have meant to translate them; but you
 know how it is...

Branwen contacted me in private e-mail and allowed me to download a
copy, but the copy was missing at least two pages.  Does anybody know
where I can find a complete copy?

-- Benjamin L. Russell
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
Furuike ya, kawazu tobikomu mizu no oto. -- Matsuo Basho^ 

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


[Haskell-cafe] Re: How do you set up windows enviroment

2010-03-03 Thread Maciej Piechotka
On Wed, 2010-03-03 at 21:46 +, Stephen Tetley wrote:
 The terminal used to be below par for MSYS but its improved a lot
 recently, if I was starting from fresh I'd probably see how far I
 could go with just MinGW / MSYS. For darcs and SSH, Cygwin might be
 better though. 

I get the same behaviour - darcs hangs. In verbose output it seems that
it has some I/O errors on FD 4 whatever it is (i.e. socket, file etc.).
Any ideas?

Combining with Console and/or (x)emacs+Cygwin/X+eshell it should be
sufficient for my other needs.

Regards


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


[Haskell-cafe] Free theorem - what do we need it for

2010-03-03 Thread Maciej Piechotka
Some time ago I get knew about free theorem that states (omitting
undefined  co.) that there is 1 haskell function forall a. a - a.

The property seems to be workaround by Typeable but it stills not work
for all types so it cannot be used in, for example, Monad or Functor. 

I am afraid that I fail to see practical benefits (I mean that I don't
know all implication not that I think there is no benefits).
What are the benefits of free theorem except large chance that data will
obey he functor/monad laws? I.e. what advantage it gives over the
'reflection' from other languages?

Regards



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


[Haskell-cafe] Profiling help (Warning: Euler spoilers)

2010-03-03 Thread James Jackson
I have written the program below, which solves problem 14 from Project
Euler, which asks us to find the hailstone number below 1 million that
takes the longest to get to 1. The program solves the problem using
dynamic programming using a Data.Map.  It completes in under a minute
(barely), but allocates a ridiculous amount of memory and actually
runs slower than the naive one-liner it was supposed to replace.  I
have an intuition on what the problem is, but would like to verify it
by profiling.

Unfortunately, I don't know enough about how profiling works in GHC to
diagnose the problem.  Hopefully the Cafe can help.


Here's the code.

scratch.hs: This is the main program, which just calls the
problemFourteen function.

The EP datatype just contains an int representing the problem number
and an (IO ()) which prints out the solution

---
import Euler1to20 -- contains problems 1 through 20
import Euler -- Contains various utility functions including the EC
type which represents Euler Problems
main =  proc
   where (EP num proc) = problemFourteen
---

Euler1to20.hs:  contains the following lines, among others
---
problemFourteen = EP 14 $ print $ (key, fromJust $ findIndex (==key) keys)
   where (keys, results) = runState (mapM findChainLength [1..10^6])
   $ M.fromList [(1,1)]
 key = maximum keys

findChainLength::Integer-State (M.Map Integer Integer) Integer
findChainLength n = do
 m - get
 case M.lookup n m of
   Nothing - let nextLink = if even n then div n 2 else 3*n+1
  in do
len - liftM (1+) (findChainLength nextLink)
m2 - get
m2 `seq` put (M.insert n len m2)
return len
   Just n'- return n'
---

My guess is that the problem is in the recursive call to
findChainLength, which is not in tail position.  I think that this is
causing the code to keep too many old copies of the map around.
Before I go rewriting everything, however, I'd like to verify that
this is indeed the problem, so the next step is to compile and run
with profiling turned on.  After quickly looking at the Real World
Haskell chapter on profiling,  I do the following.

Compiling and running:

---
ghc -prof --make -auto-all -fforce-recomp scratch.hs
[1 of 3] Compiling Euler( Euler.hs, Euler.o )
[2 of 3] Compiling Euler1to20   ( Euler1to20.hs, Euler1to20.o )
[3 of 3] Compiling Main ( scratch.hs, scratch.o )
Linking scratch ...

./scratch +RTS -sstderr -hc -p -K100M
(525,837798)
9,503,907,112 bytes allocated in the heap
42,785,764,376 bytes copied during GC (scavenged)
15,697,610,688 bytes copied during GC (not scavenged)
421,548,032 bytes maximum residency (193 sample(s))

 17787 collections in generation 0 (650.00s)
   193 collections in generation 1 (1748.37s)

   782 Mb total memory in use

 INIT  time0.00s  (  0.00s elapsed)
 MUT   time   18.68s  ( 19.19s elapsed)
 GCtime  2398.37s  (2401.47s elapsed)
 RPtime0.00s  (  0.00s elapsed)
 PROF  time   50.48s  ( 50.50s elapsed)
 EXIT  time0.00s  (  0.00s elapsed)
 Total time  2467.53s  (2471.17s elapsed)

 %GC time  97.2%  (97.2% elapsed)

 Alloc rate508,742,769 bytes per MUT second

 Productivity   0.8% of total user, 0.8% of total elapsed

---
I can see from the above that the maximum resident memory at one time
is 782Mb, which seems excessive, since I don't expect the Map to
contain more than around 2M entries. Also, I had to use -K 100M to
increase the stack space or the program bombs out with a stack
overflow exception.

Since I compiled with profiling information, running the program
produced the following scratch.prof:

---
   Wed Mar  3 19:41 2010 Time and Allocation Profiling Report  (Final)

  scratch +RTS -sstderr -hc -p -K100M -RTS

   total time  =   18.68 secs   (934 ticks @ 20 ms)
   total alloc = 5,327,238,992 bytes  (excludes profiling overheads)

COST CENTREMODULE   %time %alloc

findChainLengthEuler1to2093.8   90.5
CAFEuler1to20 5.28.0
problemFourteen   

[Haskell-cafe] Profiling help (Warning: Euler spoilers)

2010-03-03 Thread Louis Wasserman
James,

Which version of Control.Monad.State are you importing?

If you're just importing vanilla Control.Monad.State, that's actually
sending you to Control.Monad.State.Lazy.

Using Control.Monad.State.Strict might solve your problems, srsly.  Laziness
can result in epically failing memory leaks.

Louis Wasserman
wasserman.lo...@gmail.com
http://profiles.google.com/wasserman.louis
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: uuid-0.1.2

2010-03-03 Thread Antoine Latter
2010/1/5 Mark Lentczner ma...@glyphic.com:
 Antione and I are please to announce the release of uuid-0.1.2.

 CHANGES:
 - added functions toByteString and fromByteString
 - added 'nil' UUID
 - added unit tests and benchmarks, built when configured -ftest
 - major speed up of to/from functions (as well as in general)
 - added version-3 generation (deterministic based on MD5)
 - major changes to internal representation
        - now uses four strict Word32 values
        - internal ByteSource classes for easy construction (see Builder.hs)
 - Storable instance now stores in memory as system libraries in C do:
    16 bytes derived from the network order of the fields, no matter what
    the host native endianess is.
 - fixed bugs in V1 time and clock stepping, and V1 generated values
 - builds cleanly under GHC's -Wall
 - added CHANGES file


I'd like to announce a point-release to the UUID library: version 1.2.1

The uuid package includes an implementation of UUID generation via the
current time, machine MAC address, and persistent state kept in the
library.

Previously this state was kept using a top-level IORef, and if you hit
it too quickly with the threaded run-time it would return duplicate
UUIDs.

Now the internal state is stored in an MVar. This does have additional
run-time overhead, but such is the price of correctness.

Thanks to Neil Mitchell for the bug report and test-case.

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


Re: [Haskell-cafe] Free theorem - what do we need it for

2010-03-03 Thread Janis Voigtländer

Maciej Piechotka wrote:


I am afraid that I fail to see practical benefits (I mean that I don't
know all implication not that I think there is no benefits).
What are the benefits of free theorem except large chance that data will


Lots of applications. See page 34 (along with the references starting
from page 218) of http://www.iai.uni-bonn.de/~jv/ppl2010-slides.pdf for
a list of some of them.

Ciao,
Janis

--
Jun.-Prof. Dr. Janis Voigtländer
http://www.iai.uni-bonn.de/~jv/
mailto:j...@iai.uni-bonn.de

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


[Haskell-cafe] ANNOUNCE: Parsec 3.1.0

2010-03-03 Thread Derek Elkins
Parsec is a monadic combinator library that is well-documented, simple
to use, and produces good error messages.   Parsec is not inherently
lazy/incremental and is not well-suited to handling large quantities
of simply formatted data.  Parsec 3 adds to Parsec the ability to use
Parsec as a monad transformer and generalizes the input Parsec
accepts.  Parsec 3 includes a compatibility layer for Parsec 2 and
should be a drop-in replacement for code using Parsec 2.  Code using
the features of Parsec 3 should use the modules in Text.Parsec.

Due almost entirely to the work of Antoine Latter there is a new
version of Parsec 3 available.  He documented some of his thoughts on
this in this series of blog posts:
http://panicsonic.blogspot.com/2009/12/adventures-in-parsec.html

The main features of this release are:
- the performance should be much better and comparable to Parsec 2
- notFollowedBy's type and behavior have been generalized

Changes:
- the changes to the core of Parsec lead to some changes to when
things get executed when it is used as a monad transformer
In the new version bind, return and mplus no longer run in
the inner monad, so if the inner monad was side-effecting for these
actions the behavior of existing code will change.
- notFollowedBy p now behaves like notFollowedBy (try p) which
changes the behavior slightly when p consumes input, though the
behavior should be more natural now.
- the set of names exported from Text.Parsec.Prim has changed somewhat
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] type class constraints headache

2010-03-03 Thread muneson

When writing a command-line interface I ran into type class conflicts
I don't understand. Could anyone explain why ghc 6.10.4 compiles this

 methods :: (Eq a) = [(String, a)]
 methods = 
   [ (method1, undefined ) 
   , (method2, undefined)
   ]
  

but not the following?

 methods :: (Eq a) = [(String, a)]
 methods = 
   [ (method1, undefined ) 
   , (method2, undefined)
   ]

 enumerateMethodNames :: [String]
 enumerateMethodNames = map fst methods 


thanks,

Marcus

-- 
View this message in context: 
http://old.nabble.com/type-class-constraints-headache-tp27752745p27752745.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] type class constraints headache

2010-03-03 Thread Rahul Kapoor
 methods :: (Eq a) = [(String, a)]
 methods =
   [ (method1, undefined )
   , (method2, undefined)
   ]

 enumerateMethodNames :: [String]
 enumerateMethodNames = map fst methods

The above does not compile because the source does not have
enough information for GHC to determine what actual types to use
for methods since undefined can stand in as values for any
type. The program will compile if you use actual values instead
of undefined or supply an explicit type signature.

for example:

enumerateMethodNames = map fst (methods :: [(String, String)])
or
methods :: [(String, SomeEqType)]


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


Re: [Haskell-cafe] type class constraints headache

2010-03-03 Thread Miguel Mitrofanov

Which a should it use for methods?


On 4 Mar 2010, at 09:07, muneson wrote:



When writing a command-line interface I ran into type class conflicts
I don't understand. Could anyone explain why ghc 6.10.4 compiles this


methods :: (Eq a) = [(String, a)]
methods =
 [ (method1, undefined )
 , (method2, undefined)
 ]



but not the following?


methods :: (Eq a) = [(String, a)]
methods =
 [ (method1, undefined )
 , (method2, undefined)
 ]

enumerateMethodNames :: [String]
enumerateMethodNames = map fst methods



thanks,

Marcus

--  
View this message in context: http://old.nabble.com/type-class-constraints-headache-tp27752745p27752745.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


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


Re: [Haskell-cafe] type class constraints headache

2010-03-03 Thread Marcus Uneson
Thanks. I realize there are many ways to make it compile.
However, I am trying to understand the mechanism behind --
why does the first example compile and what constraints does
enumerateMethodNames add on a (which it does not inspect)?


cheers,

Marcus

2010/3/4 Rahul Kapoor r...@trie.org

  methods :: (Eq a) = [(String, a)]
  methods =
[ (method1, undefined )
, (method2, undefined)
]
 
  enumerateMethodNames :: [String]
  enumerateMethodNames = map fst methods

 The above does not compile because the source does not have
 enough information for GHC to determine what actual types to use
 for methods since undefined can stand in as values for any
 type. The program will compile if you use actual values instead
 of undefined or supply an explicit type signature.

 for example:

 enumerateMethodNames = map fst (methods :: [(String, String)])
 or
 methods :: [(String, SomeEqType)]


 Rahul

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


Re: [Haskell-cafe] type class constraints headache

2010-03-03 Thread Rahul Kapoor
I am trying to understand the mechanism behind --
 why does the first example compile and what constraints does
 enumerateMethodNames add on a (which it does not inspect)?

enumerateMethodNames does not add on any constraints. If you
don't actually use methods GHC does not care what it's type is
but the moment you use it some place the compiler needs to infer
it's type which it is unable to do in your case because
the undefineds can be of any type.

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


Re: [Haskell-cafe] type class constraints headache

2010-03-03 Thread Ryan Ingram
Perhaps this thought exercise will make things clear:

 class Show a = Foo a where
toFoo :: String - a

 foos :: (Foo a) = [(String, a)]
 foos = map (\f - (show f, f)) [toFoo a, toFoo b, toFoo c]

 data Foo1 = Foo1
 instance Show Foo1 where show _ = 1
 instance Foo Foo1 where toFoo _ = Foo1
 data Foo2 = Foo2
 instance Show Foo2 where show _ = 2
 instance Foo Foo2 where toFoo _ = Foo2

 exercise :: [String]
 exercise = map fst foos

Exercise for the reader: what should the contents of exercise be?

Keep in mind that your question is exactly the same as this one, from
the compiler's point of view.

  -- ryan

On Wed, Mar 3, 2010 at 10:48 PM, Marcus Uneson marcus.une...@gmail.com wrote:
 Thanks. I realize there are many ways to make it compile.
 However, I am trying to understand the mechanism behind --
 why does the first example compile and what constraints does
 enumerateMethodNames add on a (which it does not inspect)?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] type class constraints headache

2010-03-03 Thread Marcus Uneson
Thanks, it did!

(For the record, here is a paraphrase of what first
confused me -- undefined was not the problem).

 enumerateMethodNames :: [String]
 enumerateMethodNames = map fst methodsNoConstr
 --enumerateMethodNames = map fst methodsConstr

 methodsConstr :: (Ord a) = [(String, [a] - Int)]
 methodsConstr = [ (method, methodConstr )]
   where methodConstr :: (Ord a) = [a] - Int
 methodConstr xs = length . sort $ xs


 methodsNoConstr :: [(String, [a] - Int)]
 methodsNoConstr = [ (method, methodNoConstr )]
   where methodNoConstr :: [a] - Int
 methodNoConstr = length


 --First enumerateMethodNames works as expected, second does not compile.

2010/3/4 Ryan Ingram ryani.s...@gmail.com

 Perhaps this thought exercise will make things clear:

  class Show a = Foo a where
 toFoo :: String - a

  foos :: (Foo a) = [(String, a)]
  foos = map (\f - (show f, f)) [toFoo a, toFoo b, toFoo c]

  data Foo1 = Foo1
  instance Show Foo1 where show _ = 1
  instance Foo Foo1 where toFoo _ = Foo1
  data Foo2 = Foo2
  instance Show Foo2 where show _ = 2
  instance Foo Foo2 where toFoo _ = Foo2

  exercise :: [String]
  exercise = map fst foos

 Exercise for the reader: what should the contents of exercise be?

 Keep in mind that your question is exactly the same as this one, from
 the compiler's point of view.

  -- ryan

 On Wed, Mar 3, 2010 at 10:48 PM, Marcus Uneson marcus.une...@gmail.com
 wrote:
  Thanks. I realize there are many ways to make it compile.
  However, I am trying to understand the mechanism behind --
  why does the first example compile and what constraints does
  enumerateMethodNames add on a (which it does not inspect)?

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


Re: [Haskell-cafe] Real-time garbage collection for Haskell

2010-03-03 Thread Curt Sampson
On 2010-03-01 19:37 + (Mon), Thomas Schilling wrote:

 A possible workaround would be to sprinkle lots of 'rnf's around your
 code

As I learned rather to my chagrin on a large project, you generally
don't want to do that. I spent a couple of days writing instance
of NFData and loading up my application with rnfs and then watched
performance fall into a sinkhole.

I believe that the problem is that rnf traverses the entirety of a large
data structure even if it's already strict and doesn't need traversal.
My guess is that doing this frequently on data structures (such as Maps)
of less than tiny size was blowing out my cache.

I switched strategies to forcing a deep(ish) evaluation of only
newly constructed data instead. For example, after inserting a newly
constructed object into a Map, I would look it up and force evaluation
only of the result of that lookup. That solved my space leak problem and
made things chug along quite nicely.

Understanding the general techniques for this sort of thing and seeing
where you're likely to need to apply them isn't all that difficult, once
you understand the problem. (It's probably much easier if you don't have
to work it out all for yourself, as I did. Someone needs to write the
how to manage lazyness in Haskell guide.) The difficult part of it is
that you've really got to stay on top of it, because if you don't, the
space leaks come back and you have to go find them again. It feels a
little like dealing with buffers and their lengths in C.

On 2010-03-01 16:06 -0500 (Mon), Job Vranish wrote:

 All of our toplevel inputs will be strict, and if we keep our
 frame-to-frame state strick, our variances in runtimes, given the same
 inputs, should be quite low modulo the GC.

This is exactly the approach I need to take for the trading system. I
basically have various (concurrent) loops that process input, update
state, and possibly generate output. The system runs for about six
hours, processing five million or so input messages with other loops
running anywhere from hundreds of thousands to millions of times. The
trick is to make sure that I never, ever start a new loop with an
unevaluated thunk referring to data needed only by the previous loop,
because otherwise I just grow and grow and grow

Some tool to help with this would be wonderful. There's something for
y'all to think about.

On 2010-03-01 22:01 + (Mon), Thomas Schilling wrote:

 As Job and John have pointed out, though, laziness per se doesn't seem
 to be an issue, which is good to hear. Space leaks might, but there is
 no clear evidence that they are particularly harder to avoid than in
 strict languages.

As I mentioned above, overall I find them so. Any individual space
leak you're looking at is easy to fix, but the constant vigilance is
difficult.

cjs
-- 
Curt Sampson c...@cynic.net +81 90 7737 2974
 http://www.starling-software.com
The power of accurate observation is commonly called cynicism
by those who have not got it.--George Bernard Shaw
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: How do you set up windows enviroment

2010-03-03 Thread Jonas Almström Duregård
I suppose you are already using the Haskell Platform?

I had problems with darcs freezing, and it turned out that the ssh
client was actually prompting for something. Is the host you are
connected to in your list of trusted hosts? Also i had a similar
problem when using Pageant to manage SSH-keys, and the command prompt
was run in privileged mode.

/Jonas Duregård

On 4 March 2010 02:58, Maciej Piechotka uzytkown...@gmail.com wrote:
 On Wed, 2010-03-03 at 21:46 +, Stephen Tetley wrote:
 The terminal used to be below par for MSYS but its improved a lot
 recently, if I was starting from fresh I'd probably see how far I
 could go with just MinGW / MSYS. For darcs and SSH, Cygwin might be
 better though.

 I get the same behaviour - darcs hangs. In verbose output it seems that
 it has some I/O errors on FD 4 whatever it is (i.e. socket, file etc.).
 Any ideas?

 Combining with Console and/or (x)emacs+Cygwin/X+eshell it should be
 sufficient for my other needs.

 Regards

 ___
 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