Re: [Haskell-cafe] simple parsec question

2013-03-04 Thread Immanuel Normann
Andrey,
Thanks a lot for your effort! I have the same suspect that the lookahead in
the content parser is the problem, but I don't know how to solve it either.
At least the I learned from your code that noneOf is also a quite useful
parser in this context which I have overlooked.
Anyway, if you find a solution it would be great! In the end the task
itself doesn't look very specific, but rather general: an alternation
between strictly (the headline in my case) and loosely (the content in my
case) structured text. It shouldn't be difficult to build a parser for such
a setting.

(btw. I am aware the my test parser would (or rather should) parse only the
first section. For testing this would be sufficient.)



2013/3/4 Andrey Chudnov 

>  Immanuel,
> I tried but I couldn't figure it out. Here's a gist with my attempts and
> results so far: https://gist.github.com/achudnov/f3af65f11d5162c73064There, 
> 'test' uses my attempt at specifying the parser, 'test2' uses yours.
> Note that your attempt wouldn't parse multiple sections -- for that you
> need to use 'many section' instead of just 'section' in 'parse'
> ('parseFromFile' in the original).
> I think what's going on is the lookahead is wrong, but I'm not sure how
> exactly. I'll give it another go tomorrow if I have time.
>
> /Andrey
>
>
> On 03/03/2013 05:16 PM, Immanuel Normann wrote:
>
>Andrey,
>
>  Thanks for your attempt, but it doesn't seem to work. The easy part is
> the headline, but the content makes trouble.
>
> Let me write the code a bit more explicit, so you can copy and paste it:
>
> --
> {-# LANGUAGE FlexibleContexts #-}
>
> module Main where
>
> import Text.Parsec
>
> data Top = Top String deriving (Show)
> data Content = Content String deriving (Show)
> data Section = Section Top Content deriving (Show)
>
> headline :: Stream s m Char => ParsecT s u m Top
> headline = manyTill anyChar (char ':' >> newline) >>= return . Top
>
> content :: Stream s m Char => ParsecT s u m Content
> content = manyTill anyChar (try headline) >>= return . Content
>
> section :: Stream s m Char => ParsecT s u m Section
> section = do {h <- headline; c <- content; return (Section h c)}
> --
>
>
>  Assume the following example text is stored in  "/tmp/test.txt":
> ---
> top 1:
>
> some text ... bla
>
> top 2:
>
> more text ... bla bla
> ---
>
>  Now I run the section parser in ghci against the above mentioned example
> text stored in "/tmp/test.txt":
>
> *Main> parseFromFile section "/tmp/test.txt"
> Right (Section (Top "top 1") (Content ""))
>
>  I don't understand the behaviour of the content parser here. Why does it
> return ""? Or perhaps more generally, I don't understand the manyTill
> combinator (though I read the docs).
>
>  Side remark: of cause for this little task it is probably to much effort
> to use parsec. However, my content in fact has an internal structure which
> I would like to parse further, but I deliberately abstracted from these
> internals as they don't effect my above stated problem.
>
>  Immanuel
>
>
> 2013/3/3 Andrey Chudnov 
>
>> Immanuel,
>> Since a heading always starts with a new line (and ends with a colon
>> followed by a carriage return or just a colon?), I think it might be useful
>> to first separate the input into lines and then classify them depending on
>> whether it's a heading or not and reassemble them into the value you need.
>> You don't even need parsec for that.
>>
>> However, if you really want to use parsec, you can write something like
>> (warning, not tested):
>> many $ liftM2 Section headline content
>>where headline = anyChar `manyTill` (char ':' >> spaces >> newline)
>>content  = anyChar `manyTill` (try $ newline >> headline)
>>
>> /Andrey
>>
>>
>> On 3/3/2013 10:44 AM, Immanuel Normann wrote:
>>
>>> I am trying to parse a semi structured text with parsec that basically
>>> should identify sections. Each section starts with a headline and has an
>>> unstructured content - that's all. For instance, consider the following
>>> example text (inside the dashed lines):
>>>
>>> ---
>>>
>>> top 1:
>>>
>>> some text ... bla
>>>
>>> top 2:
>>>
>>> more text ... bla bla
>>>
>>>
>>> ---
>>>
>>> This should be parsed into a structure like this:
>>>
>>> [Section (Top 1) (Content "some text ... bla"), Section (Top 1) (Content
>>> "more text ... bla")]
>>>
>>> Say, I have a parser "headline", but the content after a headline could
>>> be anything that is different from what "headline" parses.
>>> How could the "section" parser making use of "headline" look like?
>>> My idea would be to use the "manyTill" combinator, but I don"t find an
>>> easy solution.
>>>
>>
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] GHC 7.6.2 introduces <> in UUAGC

2013-03-04 Thread Jeroen Bransen
Hi all,

The uuagc package [1] works fine with GHC versions 7.4.* and 7.6.1. However, 
with GHC 7.6.2 the binary still compiles but runs into an infinite loop at 
runtime. To reproduce, do:

cabal install uuagc && touch tmp.ag && uuagc tmp.ag

With GHC versions < 7.6.2 this succeeds and creates a (rather boring) file 
tmp.hs, while with GHC 7.6.2 this displays:

uuagc: <>

I suspect that this is related to strictness annotations, which exist in many 
places in the UUAGC source code (which itself is also preprocessed by the UUAGC 
system). In the release notes I cannot find anything related to strictness 
which could introduce this, so would anyone have a clue on where to look? Has 
there been a longstanding bug in the UUAGC source code which only now surfaces? 
Or is it a bug introduced in GHC 7.6.2 where something is a bit too strict?

Regards,
Jeroen Bransen

[1] http://hackage.haskell.org/package/uuagc
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Simple way to do something like ArrowChoice.right on a Conduit? (version 1.0.0)

2013-03-04 Thread Joey Adams
On Sun, Mar 3, 2013 at 10:24 PM, Joey Adams wrote:

> ...
> Here's a possible API for a resumable Conduit:
>
> newtype ResumableConduit i m o = -- hidden --
>
> newResumableConduit :: Monad m => Conduit i m o -> ResumableConduit i
> m o
>
> -- | Feed the 'Source' through the conduit, and send any output from
> the
> -- conduit to the 'Sink'.  When the 'Sink' returns, close the
> 'Source', but
> -- leave the 'ResumableConduit' open so more data can be passed
> through it.
> runResumableConduit
> :: Monad m
> => ResumableConduit i m o
> -> Source m i
> -> Sink o m r
> -> m (ResumableConduit i m o, r)
> ...
>

While trying to implement this, I found a more elegant interface for
resuming the ResumableConduit:

-- | Fuse a 'ResumableConduit' to a 'Sink'.  When the 'Sink' returns,
-- it returns the 'ResumableConduit' so the caller can reuse it.
(=$++) :: Monad m
   => ResumableConduit i m o
   -> Sink o m r
   -> Sink i m (ResumableConduit i m o, r)

This takes advantage of Sink's return value to forward the
ResumableConduit.  I don't think a ($=++) can be implemented.

Advantages:

 * (=$++) is easier to implement than 'runResumableConduit' since it only
has to fuse two pipes together instead of three.

 * Pretty syntax: (resumable', a) <- source $$ resumable =$++ sink
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell syntax/indentation for vim

2013-03-04 Thread Dan Doel
I hadn't seen this before, but I tried it out, and the parts I'm interested
in are nice. The indenting is less flaky than what I was using before
(comments had issues).

If you're rewriting things, though, it'd be nice to be able to customize
indentation a little more. For instance, I like laying out ifs like:

if foo
  then bar
  else baz

But I like to lay out wheres as:

foo = ...
 where
 bar = ...

But both the indents here are based on shiftwidth, so they're tied together.

Another 'nice to have' would be some intelligent outdenting. For instance,
if you type a let block right now:

let foo = zig
bar = zag
in ...

That's what you'll get. It'd be nice if typing the 'in' snapped back to the
let. I know it's possible to implement something like this, because the
scala indentation mode I use frequently outdents when I type '=>' (which
annoys the hell out of me, because it's almost never correct), but I don't
know if it can be done intelligently enough to be useful (which would be
important). Something to keep in mind, though.

-- Dan


On Sun, Mar 3, 2013 at 9:48 AM, dag.odenh...@gmail.com <
dag.odenh...@gmail.com> wrote:

> I see now in your README that you have seen vim2hs.  I'd love to hear what
> you disliked about it, especially given my plan to rewrite the whole thing
> [1]! :)
>
> [1] https://github.com/dag/vim2hs/issues/45
>
>
> On Sun, Mar 3, 2013 at 3:38 PM, dag.odenh...@gmail.com <
> dag.odenh...@gmail.com> wrote:
>
>> Hi
>>
>> Have you seen vim2hs?
>>
>> https://github.com/dag/vim2hs
>>
>>
>> On Sat, Mar 2, 2013 at 9:11 PM, Tristan Ravitch wrote:
>>
>>> Cafe,
>>>
>>> I've recently been playing with vim and wasn't quite satisfied with the
>>> existing syntax highlighting and indentation, so I thought I'd try my
>>> hand at a new Haskell mode:
>>>
>>> https://github.com/travitch/hasksyn
>>>
>>> It is minimal in that it doesn't provide support for running external
>>> commands over code or anything fancy.  It just does syntax highlighting
>>> and reasonably-smart indentation.  There is no support for literate
>>> Haskell since supporting both with one mode is very tricky.
>>>
>>> It might be useful to some people.  Comments, bug reports, and
>>> suggestions
>>> welcome.
>>>
>>> ___
>>> 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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell syntax/indentation for vim

2013-03-04 Thread Tristan Ravitch
I like automatic "outdenting" too, but I only came up with three cases
where I felt like I could do it reliably:

 * With let/in as you described
 * After a catchall case:

   case ... of
 C1 -> ...
 C2 -> ...
 _ -> ...
   -- dedent back to here

 * And similarly after a do block ending in a return

Even that last one is slightly questionable, I feel, but probably works
for almost all cases.  Are there any others?

On Mon, Mar 04, 2013 at 12:20:12PM -0500, Dan Doel wrote:
> I hadn't seen this before, but I tried it out, and the parts I'm interested
> in are nice. The indenting is less flaky than what I was using before
> (comments had issues).
> 
> If you're rewriting things, though, it'd be nice to be able to customize
> indentation a little more. For instance, I like laying out ifs like:
> 
> if foo
>   then bar
>   else baz
> 
> But I like to lay out wheres as:
> 
> foo = ...
>  where
>  bar = ...
> 
> But both the indents here are based on shiftwidth, so they're tied together.
> 
> Another 'nice to have' would be some intelligent outdenting. For instance,
> if you type a let block right now:
> 
> let foo = zig
> bar = zag
> in ...
> 
> That's what you'll get. It'd be nice if typing the 'in' snapped back to the
> let. I know it's possible to implement something like this, because the
> scala indentation mode I use frequently outdents when I type '=>' (which
> annoys the hell out of me, because it's almost never correct), but I don't
> know if it can be done intelligently enough to be useful (which would be
> important). Something to keep in mind, though.
> 
> -- Dan
> 
> 
> On Sun, Mar 3, 2013 at 9:48 AM, dag.odenh...@gmail.com <
> dag.odenh...@gmail.com> wrote:
> 
> > I see now in your README that you have seen vim2hs.  I'd love to hear what
> > you disliked about it, especially given my plan to rewrite the whole thing
> > [1]! :)
> >
> > [1] https://github.com/dag/vim2hs/issues/45
> >
> >
> > On Sun, Mar 3, 2013 at 3:38 PM, dag.odenh...@gmail.com <
> > dag.odenh...@gmail.com> wrote:
> >
> >> Hi
> >>
> >> Have you seen vim2hs?
> >>
> >> https://github.com/dag/vim2hs
> >>
> >>
> >> On Sat, Mar 2, 2013 at 9:11 PM, Tristan Ravitch 
> >> wrote:
> >>
> >>> Cafe,
> >>>
> >>> I've recently been playing with vim and wasn't quite satisfied with the
> >>> existing syntax highlighting and indentation, so I thought I'd try my
> >>> hand at a new Haskell mode:
> >>>
> >>> https://github.com/travitch/hasksyn
> >>>
> >>> It is minimal in that it doesn't provide support for running external
> >>> commands over code or anything fancy.  It just does syntax highlighting
> >>> and reasonably-smart indentation.  There is no support for literate
> >>> Haskell since supporting both with one mode is very tricky.
> >>>
> >>> It might be useful to some people.  Comments, bug reports, and
> >>> suggestions
> >>> welcome.
> >>>
> >>> ___
> >>> 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
> >
> >


pgpQSs5yXp9eD.pgp
Description: PGP signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Concurrency performance problem

2013-03-04 Thread Łukasz Dąbek
Hello Cafe!

I have a problem with following code: http://hpaste.org/83460. It is a
simple Monte Carlo integration. The problem is that when I run my
program with +RTS -N1 I get:
Multi
693204.039020917 8.620632s
Single
693204.039020917 8.574839s
End

And with +RTS -N4 (I have four CPU cores):
Multi
693204.0390209169 11.877143s
Single
693204.039020917 11.399888s
End

I have two questions:
 1) Why performance decreases when I add more cores for my program?
 2) Why performance of single threaded integration also changes with
number of cores?

Thanks for all answers,
Łukasz Dąbek.

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


Re: [Haskell-cafe] Concurrency performance problem

2013-03-04 Thread Don Stewart
Depends on your code...
On Mar 4, 2013 6:10 PM, "Łukasz Dąbek"  wrote:

> Hello Cafe!
>
> I have a problem with following code: http://hpaste.org/83460. It is a
> simple Monte Carlo integration. The problem is that when I run my
> program with +RTS -N1 I get:
> Multi
> 693204.039020917 8.620632s
> Single
> 693204.039020917 8.574839s
> End
>
> And with +RTS -N4 (I have four CPU cores):
> Multi
> 693204.0390209169 11.877143s
> Single
> 693204.039020917 11.399888s
> End
>
> I have two questions:
>  1) Why performance decreases when I add more cores for my program?
>  2) Why performance of single threaded integration also changes with
> number of cores?
>
> Thanks for all answers,
> Łukasz Dąbek.
>
> ___
> 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] Concurrency performance problem

2013-03-04 Thread Łukasz Dąbek
What do you exactly mean? I have included link to full source listing:
http://hpaste.org/83460.

--
Łukasz Dąbek

2013/3/4 Don Stewart :
> Depends on your code...
>
> On Mar 4, 2013 6:10 PM, "Łukasz Dąbek"  wrote:
>>
>> Hello Cafe!
>>
>> I have a problem with following code: http://hpaste.org/83460. It is a
>> simple Monte Carlo integration. The problem is that when I run my
>> program with +RTS -N1 I get:
>> Multi
>> 693204.039020917 8.620632s
>> Single
>> 693204.039020917 8.574839s
>> End
>>
>> And with +RTS -N4 (I have four CPU cores):
>> Multi
>> 693204.0390209169 11.877143s
>> Single
>> 693204.039020917 11.399888s
>> End
>>
>> I have two questions:
>>  1) Why performance decreases when I add more cores for my program?
>>  2) Why performance of single threaded integration also changes with
>> number of cores?
>>
>> Thanks for all answers,
>> Łukasz Dąbek.
>>
>> ___
>> 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] Concurrency performance problem

2013-03-04 Thread Don Stewart
Apologies, didn't see the link on my phone :)

As the comment on the link shows, youre accidentally migrating unevaluated
work to the main thread, hence no speedup.

Be very careful with evaluation strategies (esp. lazy expressions) around
MVar and TVar points. Its too easy to put a thunk in one.

The strict-concurrency package is one attempt to invert the conventional
lazy box, to better match thge most common case.
On Mar 4, 2013 7:25 PM, "Łukasz Dąbek"  wrote:

> What do you exactly mean? I have included link to full source listing:
> http://hpaste.org/83460.
>
> --
> Łukasz Dąbek
>
> 2013/3/4 Don Stewart :
> > Depends on your code...
> >
> > On Mar 4, 2013 6:10 PM, "Łukasz Dąbek"  wrote:
> >>
> >> Hello Cafe!
> >>
> >> I have a problem with following code: http://hpaste.org/83460. It is a
> >> simple Monte Carlo integration. The problem is that when I run my
> >> program with +RTS -N1 I get:
> >> Multi
> >> 693204.039020917 8.620632s
> >> Single
> >> 693204.039020917 8.574839s
> >> End
> >>
> >> And with +RTS -N4 (I have four CPU cores):
> >> Multi
> >> 693204.0390209169 11.877143s
> >> Single
> >> 693204.039020917 11.399888s
> >> End
> >>
> >> I have two questions:
> >>  1) Why performance decreases when I add more cores for my program?
> >>  2) Why performance of single threaded integration also changes with
> >> number of cores?
> >>
> >> Thanks for all answers,
> >> Łukasz Dąbek.
> >>
> >> ___
> >> 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] Concurrency performance problem

2013-03-04 Thread Łukasz Dąbek
Thank you for your help! This solved my performance problem :)

Anyway, the second question remains. Why performance of single
threaded calculation is affected by RTS -N parameter. Is GHC doing
some parallelization behind the scenes?

--
Łukasz Dąbek.

2013/3/4 Don Stewart :
> Apologies, didn't see the link on my phone :)
>
> As the comment on the link shows, youre accidentally migrating unevaluated
> work to the main thread, hence no speedup.
>
> Be very careful with evaluation strategies (esp. lazy expressions) around
> MVar and TVar points. Its too easy to put a thunk in one.
>
> The strict-concurrency package is one attempt to invert the conventional
> lazy box, to better match thge most common case.
>
> On Mar 4, 2013 7:25 PM, "Łukasz Dąbek"  wrote:
>>
>> What do you exactly mean? I have included link to full source listing:
>> http://hpaste.org/83460.
>>
>> --
>> Łukasz Dąbek
>>
>> 2013/3/4 Don Stewart :
>> > Depends on your code...
>> >
>> > On Mar 4, 2013 6:10 PM, "Łukasz Dąbek"  wrote:
>> >>
>> >> Hello Cafe!
>> >>
>> >> I have a problem with following code: http://hpaste.org/83460. It is a
>> >> simple Monte Carlo integration. The problem is that when I run my
>> >> program with +RTS -N1 I get:
>> >> Multi
>> >> 693204.039020917 8.620632s
>> >> Single
>> >> 693204.039020917 8.574839s
>> >> End
>> >>
>> >> And with +RTS -N4 (I have four CPU cores):
>> >> Multi
>> >> 693204.0390209169 11.877143s
>> >> Single
>> >> 693204.039020917 11.399888s
>> >> End
>> >>
>> >> I have two questions:
>> >>  1) Why performance decreases when I add more cores for my program?
>> >>  2) Why performance of single threaded integration also changes with
>> >> number of cores?
>> >>
>> >> Thanks for all answers,
>> >> Łukasz Dąbek.
>> >>
>> >> ___
>> >> 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] What pattern is this (Something.T -> IO a) in Sound.ALSA.Sequencer

2013-03-04 Thread Martin Drautzburg
On Sunday, 3. March 2013 21:11:21 Roman Cheplyaka wrote:

> Admittedly, programming with callbacks is not very pleasant. So we have
> an excellent alternative — the continuation monad transformer!
> 
> This nested code
> 
>   something1 $ \x -> do
>   something2 $ \y -> do
>   something3 $ \z -> do
> 
> can be equivalently rewritten as this linear code
> 
>   import Control.Monad.Cont
> 
>   flip runContT return $ do
> x <- ContT something1
> y <- ContT something2
> z <- ContT something3
> lift $ do
>   ...

Mind-blowing. Thanks a lot. Before I dig into the continuation monad 
transformer, one more question (demonstrating my ignorance):

The initialization actually starts with

main = (do
  SndSeq.withDefault SndSeq.Block $ \h -> do
  Client.setName (h :: SndSeq.T SndSeq.DuplexMode) "Haskell-Melody"
  Port.withSimple h "out"
 (Port.caps [Port.capRead, Port.capSubsRead, Port.capWrite])
 (Port.types [Port.typeMidiGeneric, Port.typeApplication]) $ \p -> do


So there are some plain actions like "Client.setName" and "Port.withSimple" 
before it gets to the next "do" block. How would I write this in ContT style?


-- 
Martin

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


Re: [Haskell-cafe] Trouble installing and using Chart/cairo on windows 7

2013-03-04 Thread Arnaud Bailly
Thanks for the pointer. While googling and stackoverflowing I came across
this as a potential issue but did not check.
It appears my ghc is 32 bits and I suspect the gtk+ lib are 64 bits.

I will check this and report on what I find.


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


Re: [Haskell-cafe] Concurrency performance problem

2013-03-04 Thread Johan Tibell
On Mon, Mar 4, 2013 at 11:39 AM, Łukasz Dąbek  wrote:

> Thank you for your help! This solved my performance problem :)
>
> Anyway, the second question remains. Why performance of single
> threaded calculation is affected by RTS -N parameter. Is GHC doing
> some parallelization behind the scenes?
>

I believe it's because -N makes GHC use the threaded RTS, which is
different from the non-threaded RTS and has some overheads therefore.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: pipes-network-0.1.0 - Stream your network sockets using the pipes and pipes-safe libraries

2013-03-04 Thread Alp Mestanogullari
I had the very same package idea a few weeks back but I have been busy with
other things, glad that you wrote it! I'll give your package a shot and
give you some feedback by then :-)


On Fri, Mar 1, 2013 at 5:07 AM, Renzo Carbonara  wrote:

> I'm happy to announce the release of pipes-network 0.1.0.
>
> The pipes-network package allows using network sockets together with the
> pipes and pipes-safe libraries, for streaming purposes. Currently, just
> TCP sockets are supported.
>
>http://hackage.haskell.org/package/pipes-network-0.1.0
>
> The package is split into two halves: one “Safe” half that can be used
> if proxies need to safely and timely acquire and release new sockets
> within a pipeline, using the facilities provided by the pipes-safe
> package; and another simpler and faster half that doesn't depend on
> pipes-safe, but it also doesn't provide any means for safely acquiring
> and releasing new sockets within a pipeline itself.
>
> There's plenty of documentation and some examples in the Haddocks.
>
> Many thanks to Gabriel Gonzalez, author of pipes, for discussing the
> design of the library with me; and to Paolo Capriotti, author of a
> previous pipes-network version, for his original work and for handing me
> the maintenance of this package.
>
> ¡Enjoy your TCP streams!
>
>
> Regards,
>
> Renzo Carbonara.
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



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


Re: [Haskell-cafe] Concurrency performance problem

2013-03-04 Thread Łukasz Dąbek
2013/3/4 Johan Tibell :
> I believe it's because -N makes GHC use the threaded RTS, which is different
> from the non-threaded RTS and has some overheads therefore.

That's interesting. Can you recommend some reading materials about
this? Besides GHC source, of course ;) Explanation of why decrease in
performance is proportional to number of cores would be great.

--
Łukasz Dąbek

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


Re: [Haskell-cafe] Concurrency performance problem

2013-03-04 Thread Edward Z. Yang
If you just pass -N, GHC automatically sets the number of threads
based on the number of cores on your machine. Do you mean -threaded?

Excerpts from Łukasz Dąbek's message of Mon Mar 04 11:39:43 -0800 2013:
> Thank you for your help! This solved my performance problem :)
> 
> Anyway, the second question remains. Why performance of single
> threaded calculation is affected by RTS -N parameter. Is GHC doing
> some parallelization behind the scenes?
> 
> --
> Łukasz Dąbek.
> 
> 2013/3/4 Don Stewart :
> > Apologies, didn't see the link on my phone :)
> >
> > As the comment on the link shows, youre accidentally migrating unevaluated
> > work to the main thread, hence no speedup.
> >
> > Be very careful with evaluation strategies (esp. lazy expressions) around
> > MVar and TVar points. Its too easy to put a thunk in one.
> >
> > The strict-concurrency package is one attempt to invert the conventional
> > lazy box, to better match thge most common case.
> >
> > On Mar 4, 2013 7:25 PM, "Łukasz Dąbek"  wrote:
> >>
> >> What do you exactly mean? I have included link to full source listing:
> >> http://hpaste.org/83460.
> >>
> >> --
> >> Łukasz Dąbek
> >>
> >> 2013/3/4 Don Stewart :
> >> > Depends on your code...
> >> >
> >> > On Mar 4, 2013 6:10 PM, "Łukasz Dąbek"  wrote:
> >> >>
> >> >> Hello Cafe!
> >> >>
> >> >> I have a problem with following code: http://hpaste.org/83460. It is a
> >> >> simple Monte Carlo integration. The problem is that when I run my
> >> >> program with +RTS -N1 I get:
> >> >> Multi
> >> >> 693204.039020917 8.620632s
> >> >> Single
> >> >> 693204.039020917 8.574839s
> >> >> End
> >> >>
> >> >> And with +RTS -N4 (I have four CPU cores):
> >> >> Multi
> >> >> 693204.0390209169 11.877143s
> >> >> Single
> >> >> 693204.039020917 11.399888s
> >> >> End
> >> >>
> >> >> I have two questions:
> >> >>  1) Why performance decreases when I add more cores for my program?
> >> >>  2) Why performance of single threaded integration also changes with
> >> >> number of cores?
> >> >>
> >> >> Thanks for all answers,
> >> >> Łukasz Dąbek.
> >> >>
> >> >> ___
> >> >> 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] Concurrency performance problem

2013-03-04 Thread briand
On Mon, 4 Mar 2013 20:39:43 +0100
Łukasz Dąbek  wrote:

> Thank you for your help! This solved my performance problem :)
> 

do you have a link to the new code ?

it should be very instructive to see the differences.

Brian


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


Re: [Haskell-cafe] Concurrency performance problem

2013-03-04 Thread Łukasz Dąbek
2013/3/4  :
> do you have a link to the new code ?

Diff is at the bottom of original code: http://hpaste.org/83460.

If you just pass -N, GHC automatically sets the number of threads
> based on the number of cores on your machine.


Yes, I know that. I am just wondering why seemingly single threaded
computation (look at singleThreadIntegrate in source code from first post)
runs slower with increasing number of cores available (set through -N
option).

--
Łukasz Dąbek
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Trouble installing and using Chart/cairo on windows 7

2013-03-04 Thread Brent Yorgey
On Sun, Mar 03, 2013 at 05:38:02PM -0800, bri...@aracnet.com wrote:
> On Sun, 3 Mar 2013 19:58:37 -0500
> Brent Yorgey  wrote:
> 
> > 
> > Good access to fonts and font metrics is the kicker.  Otherwise I'd
> > say to switch to using diagrams as a backend, hence getting a whole
> > bunch of actual backends for free.  I would love to see development of
> > some good Haskell font packages -- maybe it would even make a good
> > GSoC project?  Unfortunately I don't know enough about it to even know
> > what would be involved, or how much work it would be.
> > 
> 
> I assume that to use diagram the font package would have to be a vector font 
> system, or could bit-mapped fonts be used ?

A vector font system would be ideal, as then you could go crazy
turning glyphs into paths and doing whatever the heck you want with
them using the diagrams framework.  However, bit-mapped fonts could be
used too (as long as there is a backend to support them), it would
just be less useful.

-Brent

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


[Haskell-cafe] Library API design: functional objects VS type classes

2013-03-04 Thread Rob Stewart
Hi,

I have a question about API design for Haskell libraries. It is a simple one:
functional object data structures encapsulating mutable state VS type
classes encapsulating mutable state

Here is a simple example. I present an API: using a type class `FooC`,
and aso as a data structure `FooT`. Both are stateful, in the form of
an MVar holding an Integer, with an operation `incrFoo` to increment
this value by one, and another `readFoo` to read the Integer value.
-
import Control.Concurrent

-- API approach 1: Using type classes
class FooC a where
  mkFooC :: IO a
  readFooC :: a -> IO Int
  incrFooC :: a -> IO ()

newtype Bar = Bar (MVar Int)
instance FooC Bar where
  mkFooC = newMVar 0 >>= \i -> return $ Bar i
  readFooC (Bar mv) = readMVar mv
  incrFooC (Bar mv) =
modifyMVar_ mv $ \i -> return (i+1)

-- API approach 2: Using direct field records
data FooT a = FooT {
readFooT :: IO a
  , incrFooT :: IO ()
  }

mkBar :: IO (FooT Int)
mkBar = do
  mv <- newMVar 0
  return FooT {
  readFooT = readMVar mv
, incrFooT = modifyMVar_ mv $ \i -> return (i+1)
}

-- Tests the type class API
testTypeClass :: IO ()
testTypeClass = do
  bar <- mkBar
  incrFooT bar
  incrFooT bar
  i <- readFooT bar
  print i -- prints 2

-- Tests the direct data structure API
testDataStruct :: IO ()
testDataStruct = do
  bar <- (mkFooC :: IO Bar)
  incrFooC bar
  incrFooC bar
  i <- readFooC bar
  print i -- prints 2


With that, I now ask: which is more common? Which is the better API
design for a library? The APIs are almost identical. Under what
conditions is the type classes preferred over the "mutable object"
style data structure? There are two related resources that provides
additional context here, that favour the functional objects approach:
- Section 3.4 "Mutable Objects" in "Haskell's Overlooked Object
System" http://goo.gl/gnZXL
- A similar question (data structures vs type classes) in "Haskell
Antipattern: Existential Typeclass"
http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/

Thanks!

--
Rob

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


Re: [Haskell-cafe] Trouble installing and using Chart/cairo on windows 7

2013-03-04 Thread Brent Yorgey
On Mon, Mar 04, 2013 at 02:30:55PM -0800, bri...@aracnet.com wrote:
> On Mon, 4 Mar 2013 17:27:29 -0500
> Brent Yorgey  wrote:
> 
> > On Sun, Mar 03, 2013 at 05:38:02PM -0800, bri...@aracnet.com wrote:
> > > On Sun, 3 Mar 2013 19:58:37 -0500
> > > Brent Yorgey  wrote:
> > > 
> > > > 
> > > > Good access to fonts and font metrics is the kicker.  Otherwise I'd
> > > > say to switch to using diagrams as a backend, hence getting a whole
> > > > bunch of actual backends for free.  I would love to see development of
> > > > some good Haskell font packages -- maybe it would even make a good
> > > > GSoC project?  Unfortunately I don't know enough about it to even know
> > > > what would be involved, or how much work it would be.
> > > > 
> > > 
> > > I assume that to use diagram the font package would have to be a vector 
> > > font system, or could bit-mapped fonts be used ?
> > 
> > A vector font system would be ideal, as then you could go crazy
> > turning glyphs into paths and doing whatever the heck you want with
> > them using the diagrams framework.  However, bit-mapped fonts could be
> > used too (as long as there is a backend to support them), it would
> > just be less useful.
> > 
> 
> yes - seems to me that vector fonts are definitely the way to go.
> 
> it seems like this problem has to already have a solution.  maybe all that's 
> needed is a font importer which understands some, already established, vector 
> font  representation.
> 

Well, there is the SVGFonts package:

  http://hackage.haskell.org/package/SVGFonts

I don't have a good sense of how widely supported this representation
is, or how easy it is to convert between it and other font
representations.

-Brent

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


Re: [Haskell-cafe] Haskell syntax/indentation for vim

2013-03-04 Thread Dan Doel
They're hard to come by, but some other examples might be...

1) If you type something that is recognizably a guard, it could pop
back other guards:

foo x y z
  | guard1 = do ...
| guard2 = -- outdent now

Not sure how feasible that one is.

2) When you type 'else', outdent to the same indentation as the
associated 'then'.

There may be others, but those are what I could think of after a few
minutes of pondering.


On Mon, Mar 4, 2013 at 12:40 PM, Tristan Ravitch  wrote:
> I like automatic "outdenting" too, but I only came up with three cases
> where I felt like I could do it reliably:
>
>  * With let/in as you described
>  * After a catchall case:
>
>case ... of
>  C1 -> ...
>  C2 -> ...
>  _ -> ...
>-- dedent back to here
>
>  * And similarly after a do block ending in a return
>
> Even that last one is slightly questionable, I feel, but probably works
> for almost all cases.  Are there any others?
>
> On Mon, Mar 04, 2013 at 12:20:12PM -0500, Dan Doel wrote:
>> I hadn't seen this before, but I tried it out, and the parts I'm interested
>> in are nice. The indenting is less flaky than what I was using before
>> (comments had issues).
>>
>> If you're rewriting things, though, it'd be nice to be able to customize
>> indentation a little more. For instance, I like laying out ifs like:
>>
>> if foo
>>   then bar
>>   else baz
>>
>> But I like to lay out wheres as:
>>
>> foo = ...
>>  where
>>  bar = ...
>>
>> But both the indents here are based on shiftwidth, so they're tied together.
>>
>> Another 'nice to have' would be some intelligent outdenting. For instance,
>> if you type a let block right now:
>>
>> let foo = zig
>> bar = zag
>> in ...
>>
>> That's what you'll get. It'd be nice if typing the 'in' snapped back to the
>> let. I know it's possible to implement something like this, because the
>> scala indentation mode I use frequently outdents when I type '=>' (which
>> annoys the hell out of me, because it's almost never correct), but I don't
>> know if it can be done intelligently enough to be useful (which would be
>> important). Something to keep in mind, though.
>>
>> -- Dan
>>
>>
>> On Sun, Mar 3, 2013 at 9:48 AM, dag.odenh...@gmail.com <
>> dag.odenh...@gmail.com> wrote:
>>
>> > I see now in your README that you have seen vim2hs.  I'd love to hear what
>> > you disliked about it, especially given my plan to rewrite the whole thing
>> > [1]! :)
>> >
>> > [1] https://github.com/dag/vim2hs/issues/45
>> >
>> >
>> > On Sun, Mar 3, 2013 at 3:38 PM, dag.odenh...@gmail.com <
>> > dag.odenh...@gmail.com> wrote:
>> >
>> >> Hi
>> >>
>> >> Have you seen vim2hs?
>> >>
>> >> https://github.com/dag/vim2hs
>> >>
>> >>
>> >> On Sat, Mar 2, 2013 at 9:11 PM, Tristan Ravitch 
>> >> wrote:
>> >>
>> >>> Cafe,
>> >>>
>> >>> I've recently been playing with vim and wasn't quite satisfied with the
>> >>> existing syntax highlighting and indentation, so I thought I'd try my
>> >>> hand at a new Haskell mode:
>> >>>
>> >>> https://github.com/travitch/hasksyn
>> >>>
>> >>> It is minimal in that it doesn't provide support for running external
>> >>> commands over code or anything fancy.  It just does syntax highlighting
>> >>> and reasonably-smart indentation.  There is no support for literate
>> >>> Haskell since supporting both with one mode is very tricky.
>> >>>
>> >>> It might be useful to some people.  Comments, bug reports, and
>> >>> suggestions
>> >>> welcome.
>> >>>
>> >>> ___
>> >>> 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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] simple parsec question

2013-03-04 Thread Carlo Hamalainen
On Mon, Mar 4, 2013 at 1:44 AM, Immanuel Normann <
immanuel.norm...@googlemail.com> wrote:

> I am trying to parse a semi structured text with parsec that basically
> should identify sections. Each section starts with a headline and has an
> unstructured content - that's all.
>

Here's my attempt: https://gist.github.com/carlohamalainen/5087207

{-# LANGUAGE FlexibleContexts #-}

import Text.Parsec
import Control.Applicative hiding ((<|>),many)

-- Example input:

{-
top 1:

some text ... bla

top 2:

more text ... bla bla

-}

data Top = Top String deriving (Show)
data Content = Content [String] deriving (Show)
data Section = Section Top Content deriving (Show)

headline = do
t <- many1 (noneOf ":\n")
char ':'
newline

return $ Top t

contentLine = do
x <- many (noneOf ":\n")
newline
return x

content = do
line <- optionMaybe (try contentLine)

case line of Just x -> do xs <- content
  return (x:xs)
 _  -> return []

section = do
h <- headline
c <- Content <$> content
return $ Section h c

main = do
x <- readFile "simple.txt"
print $ parse (many section) "" x


Example run using your sample data:

$ runhaskell Simple.hs
Right [Section (Top "top 1") (Content ["","some text ... bla",""]),Section
(Top "top 2") (Content ["","more text ... bla bla",""])]

Notes:

* I had to assume that a content line does not contain a ':', because that
is the only way to distinguish a head-line (correct me if I'm wrong).

* The key was to use optionMaybe along with try; see the definition of
content.

* I haven't tested this code on very large inputs.

* I slightly changed the definition of Content to have a list of Strings,
one for each line. I'm sure this could be altered if you wanted to retain
all whitespace.

* I am still new to Parsec, so don't take this as the definitive answer ;-)

-- 
Carlo Hamalainen
http://carlo-hamalainen.net
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] LambdaJam 2013

2013-03-04 Thread Tony Morris
Hey haskell guys,
LambdaJam 2013 is a functional programming conference to be held in
Brisbane in early May.

Call for submissions ends this Friday 08 March. If you are planning to
make a submission, please make sure you do soon!

If you are stuck somehow, I'd love to be able to help you get to the
goal. So feel free to send me an email or I am on IRC (dibblego),
lurking around the #haskell channel or privmsg if you like. Personally,
I would love see more haskell submissions :)

LambdaJam2013 call for papers:
http://www.yowconference.com.au/lambdajam/Call.html

-- 
Tony Morris
http://tmorris.net/


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


Re: [Haskell-cafe] Haskell syntax/indentation for vim

2013-03-04 Thread Erlend Hamberg
Hi,

I wrote a Haskell indenter for Haskell for the Kate editor a few years ago,
which – if I remember correctly – worked quite well. It's quite simple and
doesn't try to bee *too* clever, but has some logic for when it should
dedent. Not sure if it's helpful, but you could have a look (it's
well-commented javascript):

https://projects.kde.org/projects/kde/kde-baseapps/kate/repository/revisions/master/entry/part/script/data/indentation/haskell.js

Erlend


On 4 March 2013 09:40, Tristan Ravitch  wrote:

> I like automatic "outdenting" too, but I only came up with three cases
> where I felt like I could do it reliably:
>
>  * With let/in as you described
>  * After a catchall case:
>
>case ... of
>  C1 -> ...
>  C2 -> ...
>  _ -> ...
>-- dedent back to here
>
>  * And similarly after a do block ending in a return
>
> Even that last one is slightly questionable, I feel, but probably works
> for almost all cases.  Are there any others?
>
> On Mon, Mar 04, 2013 at 12:20:12PM -0500, Dan Doel wrote:
> > I hadn't seen this before, but I tried it out, and the parts I'm
> interested
> > in are nice. The indenting is less flaky than what I was using before
> > (comments had issues).
> >
> > If you're rewriting things, though, it'd be nice to be able to customize
> > indentation a little more. For instance, I like laying out ifs like:
> >
> > if foo
> >   then bar
> >   else baz
> >
> > But I like to lay out wheres as:
> >
> > foo = ...
> >  where
> >  bar = ...
> >
> > But both the indents here are based on shiftwidth, so they're tied
> together.
> >
> > Another 'nice to have' would be some intelligent outdenting. For
> instance,
> > if you type a let block right now:
> >
> > let foo = zig
> > bar = zag
> > in ...
> >
> > That's what you'll get. It'd be nice if typing the 'in' snapped back to
> the
> > let. I know it's possible to implement something like this, because the
> > scala indentation mode I use frequently outdents when I type '=>' (which
> > annoys the hell out of me, because it's almost never correct), but I
> don't
> > know if it can be done intelligently enough to be useful (which would be
> > important). Something to keep in mind, though.
> >
> > -- Dan
> >
> >
> > On Sun, Mar 3, 2013 at 9:48 AM, dag.odenh...@gmail.com <
> > dag.odenh...@gmail.com> wrote:
> >
> > > I see now in your README that you have seen vim2hs.  I'd love to hear
> what
> > > you disliked about it, especially given my plan to rewrite the whole
> thing
> > > [1]! :)
> > >
> > > [1] https://github.com/dag/vim2hs/issues/45
> > >
> > >
> > > On Sun, Mar 3, 2013 at 3:38 PM, dag.odenh...@gmail.com <
> > > dag.odenh...@gmail.com> wrote:
> > >
> > >> Hi
> > >>
> > >> Have you seen vim2hs?
> > >>
> > >> https://github.com/dag/vim2hs
> > >>
> > >>
> > >> On Sat, Mar 2, 2013 at 9:11 PM, Tristan Ravitch  >wrote:
> > >>
> > >>> Cafe,
> > >>>
> > >>> I've recently been playing with vim and wasn't quite satisfied with
> the
> > >>> existing syntax highlighting and indentation, so I thought I'd try my
> > >>> hand at a new Haskell mode:
> > >>>
> > >>> https://github.com/travitch/hasksyn
> > >>>
> > >>> It is minimal in that it doesn't provide support for running external
> > >>> commands over code or anything fancy.  It just does syntax
> highlighting
> > >>> and reasonably-smart indentation.  There is no support for literate
> > >>> Haskell since supporting both with one mode is very tricky.
> > >>>
> > >>> It might be useful to some people.  Comments, bug reports, and
> > >>> suggestions
> > >>> welcome.
> > >>>
> > >>> ___
> > >>> 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 mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


-- 
Erlend Hamberg
ehamb...@gmail.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] "translating" recursively defined sequence

2013-03-04 Thread Christopher Howard
Hi. My Haskell is (sadly) getting a bit rusty. I was wondering what
would be the most straightforward and easily followed "procedure" for
translating a recursively defined sequence into a Haskell function. For
example, this one from a homework assignment.

quote:

a_1 = 10
a_(k+1) = (1/5) * (a_k)**2


(The underscore is meant to represent subscripting what follows it.)

-- 
frigidcode.com



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


Re: [Haskell-cafe] "translating" recursively defined sequence

2013-03-04 Thread Bob Ippolito
I suppose it depends on your definition of straightforward but you can use
the iterate function from Data.List to quickly define sequences like this.

a = iterate (\x -> (1/5) * (x**2)) 10


On Mon, Mar 4, 2013 at 9:19 PM, Christopher Howard <
christopher.how...@frigidcode.com> wrote:

> Hi. My Haskell is (sadly) getting a bit rusty. I was wondering what
> would be the most straightforward and easily followed "procedure" for
> translating a recursively defined sequence into a Haskell function. For
> example, this one from a homework assignment.
>
> quote:
> 
> a_1 = 10
> a_(k+1) = (1/5) * (a_k)**2
> 
>
> (The underscore is meant to represent subscripting what follows it.)
>
> --
> frigidcode.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] "translating" recursively defined sequence

2013-03-04 Thread Christopher Howard
On 03/04/2013 08:36 PM, Bob Ippolito wrote:
> I suppose it depends on your definition of straightforward but you can
> use the iterate function from Data.List to quickly define sequences like
> this.
> 
> a = iterate (\x -> (1/5) * (x**2)) 10
> 
> 
> On Mon, Mar 4, 2013 at 9:19 PM, Christopher Howard
>  > wrote:
> 
> Hi. My Haskell is (sadly) getting a bit rusty. I was wondering what
> would be the most straightforward and easily followed "procedure" for
> translating a recursively defined sequence into a Haskell function. For
> example, this one from a homework assignment.
> 
> quote:
> 
> a_1 = 10
> a_(k+1) = (1/5) * (a_k)**2
> 
> 
> (The underscore is meant to represent subscripting what follows it.)
> 
> --
> frigidcode.com 
> 
> 

Very cool! Thanks!

-- 
frigidcode.com



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